Tycka Posted October 13, 2014 Posted October 13, 2014 function weaponSwitch(weapon) local wpn = getElementData(getLocalPlayer(), "currentweapon_1") if source == getLocalPlayer() then if wpn == "Sawn-Off Shotgun" then if getElementData(getLocalPlayer(), "2Rnd. Slug") > 0 then setElementData(getLocalPlayer(), "2Rnd. Slug", getElementData(getLocalPlayer(), "2Rnd. Slug") - 1) end elseif wpn == "AS50" then if getElementData(getLocalPlayer(), "AS50 Mag") > 0 then setElementData(getLocalPlayer(), "AS50 Mag", getElementData(getLocalPlayer(), "AS50 Mag") - 1) end else local ammoName, _ = getWeaponAmmoType2(weapon) if getElementData(getLocalPlayer(), ammoName) > 0 then setElementData(getLocalPlayer(), ammoName, getElementData(getLocalPlayer(), ammoName) - 1) end end end end
Mr_Moose Posted October 13, 2014 Posted October 13, 2014 Have you tried /debugscript 3, if not do that and post the output.
tosfera Posted October 13, 2014 Posted October 13, 2014 There are a few deathtraps in your code, first off: Always add this under the function() line, so you are avoiding unnecessary steps your server is doing. if source == getLocalPlayer() then Second, if you fail to set the data as a number you'll get a nice little error that you're trying to compare strings to ints, use tonumber ( getElement... if getElementData(getLocalPlayer(), "2Rnd. Slug") > 0 then Third, almost the same as second, it can create a lot of unwanted errors setElementData(getLocalPlayer(), "2Rnd. Slug", getElementData(getLocalPlayer(), "2Rnd. Slug") - 1) Last off, are you calling this function with triggerClientEvent / triggerEvent? If not, check what your source is.
Tycka Posted October 14, 2014 Author Posted October 14, 2014 function weaponSwitch(weapon) local wpn = getElementData(getLocalPlayer(), "currentweapon_1") if source == getLocalPlayer() then if wpn == "Sawn-Off Shotgun" then if getElementData(getLocalPlayer(), "2Rnd. Slug") > 0 then setElementData(getLocalPlayer(), "2Rnd. Slug", getElementData(getLocalPlayer(), "2Rnd. Slug") - 1) end else local ammoName, _ = getWeaponAmmoType2(weapon) if getElementData(getLocalPlayer(), ammoName) > 0 then setElementData(getLocalPlayer(), ammoName, getElementData(getLocalPlayer(), ammoName) - 1) end end end end When I use this its work great, when I add elseif wpn == "AS50" then if getElementData(getLocalPlayer(), "AS50 Mag") > 0 then setElementData(getLocalPlayer(), "AS50 Mag", getElementData(getLocalPlayer(), "AS50 Mag") - 1) end Them code didint work
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now