Jump to content

help


Recommended Posts

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
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

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
  
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...