GrinningTrout Posted June 15, 2016 Share Posted June 15, 2016 function getPedWeapons(ped) ammoPlayer={} playerWeapons = {} for i=2,9 do local amo=getPedAmmoInClip ( source,i) if amo and amo ~= 0 then table.insert(ammoPlayer,amo) setAccountData( getPlayerAccount ( source ),"ammo",amo) end end for i=2,9 do local wep = getPedWeapon(source,i) if wep and wep ~= 0 then table.insert(playerWeapons,wep) setAccountData( getPlayerAccount ( source ),"weapons",wep) end else return false end return playerWeapons end addEventHandler("onPlayerQuit",root,getPedWeapons) addEventHandler("onPlayerWasted",root,getPedWeapons) function poi() wapon=getAccountData( getPlayerAccount ( source ),"weapons") aimo=getAccountData( getPlayerAccount ( source ),"ammo") for i,wapon in ipairs(playerWeapons) do giveWeapon ( source, wapon,aimo) end end addEventHandler("onPlayerLogin",root,poi) addEventHandler("onPlayerSpawn",root,poi) i just give up, can anyone help me in this code, the problem is with the ammo Link to comment
GrinningTrout Posted June 15, 2016 Author Share Posted June 15, 2016 Bad argument @ 'giveWeapon' [Expected number at argument 3, got boolean] Link to comment
GrinningTrout Posted June 16, 2016 Author Share Posted June 16, 2016 Is it that hard ? Link to comment
KariiiM Posted June 16, 2016 Share Posted June 16, 2016 It's not a propper way to ask for help, you didn't explain anything about your problem, what's the role of this code? Is it a saving weapons on the account data ? Link to comment
GrinningTrout Posted June 16, 2016 Author Share Posted June 16, 2016 It's not a propper way to ask for help, you didn't explain anything about your problem, what's the role of this code? Is it a saving weapons on the account data ? Yes it's for saving all weapons and ammo for player on account data and give the player on spawn the exact same weapons and ammo that he had before he dies/quit (all weapons not the weapon that was in the player hands before he dies) Link to comment
KariiiM Posted June 16, 2016 Share Posted June 16, 2016 Your code is totally messy I won't edit the whole code for you, I will just guide you to do that then post what you have done with so far. Use those two functions: getPedWeapon -- To get player weapon. getPedTotalAmmo -- To get the total ammo of a specified weapon. Change the index loop to 0, 12: for example: for i= 0, 12 do -- your code end I recommand you to use an empty table using the weapon as an index and insert into it the ammo. and use: toJSON -- store the data fromJSON -- load the data Link to comment
DeVo Posted June 17, 2016 Share Posted June 17, 2016 function savePlayerWeapons() ammoPlayer = {} playerWeapons = {} for i=1,12 do local amo=getPedAmmoInClip (source, i) if amo and amo ~= 0 then ammoPlayer[i] = amo end end for i=1,12 do local wep = getPedWeapon(source,i) if wep and wep ~= 0 then playerWeapons[i] = wep end end setAccountData(getPlayerAccount ( source ), "ammo", ammoPlayer) setAccountData(getPlayerAccount ( source ), "weapons", playerWeapons) end addEventHandler("onPlayerQuit", root, savePlayerWeapons) addEventHandler("onPlayerWasted", root, savePlayerWeapons) function poi() if not isGuestAccount(getPlayerAccount(source)) then wapon = getAccountData(getPlayerAccount(source), "weapons") aimo = getAccountData(getPlayerAccount(source), "ammo") for i,wapon in ipairs(playerWeapons) do giveWeapon (source, wapon, aimo[i]) end end end addEventHandler("onPlayerSpawn", root, poi) Much cleaner code. The changes I made are a lot and I advise you to read this and this. And after those two, read this. Link to comment
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