Atouk Posted December 26, 2013 Posted December 26, 2013 Muy buenas gente de la comunidad!, hace mucho que no los veo, espero que hayan tenido una feliz navidad!. También eh vuelto al scripting haciendo mi mejor servidor de DayZ y tengo un problema que el arma no se equipa y me da los siguientes errores! Bad argument @ 'getElementData' [Expected string at argument 2, got nil] attempt to compare boolean with number Los dos los dice en la misma linea y la remarcare. Script: weaponAmmoTable = { ["Makarov Mag"] = {{"Makarov PM", 22}}, ["M9SD Mag"] = {{"M9 SD", 23}}, [".45 ACP"] = {{"Revolver", 24}}, ["PDW Mag"] = {{"PDW", 28}}, ["MP5 Mag"] = {{"MP5A5", 29}}, ["30Rnd. AK"] = {{"AKS-74 Kobra", 30}}, ["30Rnd. STANAG"] = {{"M4A1 CCO", 31}}, ["8Rnd. Slugs"] = {{"Remington 870", 25}}, ["2Rnd. Slug"] = {{"Sawn-Off Shotgun", 26}}, ["SPAZ-12 Pellet"] = {{"SPAZ-12 Combat Shotgun", 27}}, ["DMR Mag"] = {{"DMR", 34}}, ["5Rnd. M24"] = {{"M14 AIM", 33}}, ["M136 Rocket"] = {{"Heat-Seeking RPG", 36},{"M136 Rocket Launcher", 35}}, ["others"] = {{"Parachute", 46},{"Satchel", 39},{"Tear Gas", 17},{"M67 Frag Grenade", 16},{"Hunting Knife", 4},{"Machete", 8},{"Binoculars", 43},{"Baseball Bat", 5},{"Hatchet", 3},{"Shovel", 6},{"Crowbar", 2}} } function getWeaponAmmoType(weaponName) for i, weaponData in ipairs(weaponAmmoTable.others) do if weaponName == weaponData[2] then return weaponData[1], weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["Makarov Mag"]) do if weaponName == weaponData[2] then return "Makarov Mag", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["M9SD Mag"]) do if weaponName == weaponData[2] then return "M9SD Mag", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable[".45 ACP"]) do if weaponName == weaponData[2] then return ".45 ACP", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["PDW Mag"]) do if weaponName == weaponData[2] then return "PDW Mag", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["MP5 Mag"]) do if weaponName == weaponData[2] then return "MP5 Mag", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["30Rnd. AK"]) do if weaponName == weaponData[2] then return "30Rnd. AK", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["30Rnd. STANAG"]) do if weaponName == weaponData[2] then return "30Rnd. STANAG", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["8Rnd. Slugs"]) do if weaponName == weaponData[2] then return "8Rnd. Slugs", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["SPAZ-12 Pellet"]) do if weaponName == weaponData[2] then return "SPAZ-12 Pellet", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["2Rnd. Slug"]) do if weaponName == weaponData[1] then return "2Rnd. Slug", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["DMR Mag"]) do if weaponName == weaponData[2] then return "DMR Mag", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["5Rnd. M24"]) do if weaponName == weaponData[2] then return "5Rnd. M24", weaponData[2] end end for i, weaponData in ipairs(weaponAmmoTable["M136 Rocket"]) do if weaponName == weaponData[2] then return "M136 Rocket", weaponData[2] end end end function rearmPlayerWeapon(weaponName, slot) takeAllWeapons(source) local ammoData, weapID = getWeaponAmmoType(weaponName) if getElementData(source, ammoData) <= 0 then -- Aca salta el error triggerClientEvent(source, "displayClientInfo", source, "Rearm", shownInfos.nomag, 255, 22, 0) return end setElementData(source, "currentweapon_" .. slot, weaponName) local weapon = getElementData(source, "currentweapon_1") if weapon then local ammoData, weapID = getWeaponAmmoType(weapon) giveWeapon(source, weapID, getElementData(source, ammoData), true) end local weapon = getElementData(source, "currentweapon_2") if weapon then local ammoData, weapID = getWeaponAmmoType(weapon) giveWeapon(source, weapID, getElementData(source, ammoData), false) end local weapon = getElementData(source, "currentweapon_3") if weapon then local ammoData, weapID = getWeaponAmmoType(weapon) giveWeapon(source, weapID, getElementData(source, ammoData), false) end if elementWeaponBack[source] then detachElementFromBone(elementWeaponBack[source]) destroyElement(elementWeaponBack[source]) elementWeaponBack[source] = false end setElementModel(source, getElementData(source, "skin")) end addEvent("onPlayerRearmWeapon", true) addEventHandler("onPlayerRearmWeapon", getRootElement(), rearmPlayerWeapon) Espero recibir alguna respuesta y que la pasen bomba! Gracias a todos los que me ayudaron y me soportaron en todo este tiempo!
Castillo Posted December 26, 2013 Posted December 26, 2013 Debe ser que "getWeaponAmmoType" esta devolviendo 'nil' o 'false'.
Castillo Posted December 26, 2013 Posted December 26, 2013 local ammoData, weapID = getWeaponAmmoType(weaponName) if getElementData(source, ammoData) <= 0 then -- Aca salta el error Despues de getWeaponAmmoType ponele esto: outputChatBox ( tostring ( weaponName ) .."; ".. tostring ( ammoData ) )
Atouk Posted December 26, 2013 Author Posted December 26, 2013 Dice nil cuando me equipo el arma, nose si te dice algo jaja
Atouk Posted December 26, 2013 Author Posted December 26, 2013 No, me equipe la M4A1 CCO y el 2do argumento me dice nil, osea dice: M4A1; nil
Atouk Posted December 26, 2013 Author Posted December 26, 2013 El nil debe ser el ammo, y por eso no te la equipa.
Sasu Posted December 26, 2013 Posted December 26, 2013 Eso es porque las tablas tiene subtablas. Saca las subtablas, me refiero a esto: {{"Makarov PM", 22}} -> {"Makarov PM", 22} Y asi con todas.
Atouk Posted December 26, 2013 Author Posted December 26, 2013 La cagaste ahora dice esto: attempt to index local 'weaponData' ( a number value )
Castillo Posted December 26, 2013 Posted December 26, 2013 function getWeaponAmmoType ( weaponName ) for i, weaponData in ipairs ( weaponAmmoTable.others ) do if ( weaponName == weaponData [ 2 ] ) then return weaponData [ 1 ], weaponData [ 2 ] end end local ammoName, id = false, false for ammo, data in pairs ( weaponAmmoTable ) do if ( data [ 1 ] [ 1 ] == weaponName ) then ammoName, id = ammo, data [ 1 ] [ 2 ] break end end return ammoName, id end
Atouk Posted December 27, 2013 Author Posted December 27, 2013 Naaa que proo, anduvo. Yo te juro que cuando la equipe y anduvo sonreí y dije, ' Que pedazo de Grozo ', Muchisimas gracias a todos y en especial avos castillo
Recommended Posts