MatXpl Posted January 5, 2014 Posted January 5, 2014 hi. i'm not good in tables. but can i please for code ? 1. get all player weapons to table 2. load them from table and give it just for learning
TAPL Posted January 5, 2014 Posted January 5, 2014 -- By Solidsnake14 local playerWeapons = { } addEventHandler ( "onPlayerWasted", root, function ( ) if ( not playerWeapons [ source ] ) then playerWeapons [ source ] = { } end for slot = 0, 12 do local weapon = getPedWeapon ( source, slot ) if ( weapon > 0 ) then local ammo = getPedTotalAmmo ( source, slot ) if ( ammo > 0 ) then playerWeapons [ source ] [ weapon ] = ammo end end end end ) addEventHandler ( "onPlayerSpawn", root, function ( ) if ( playerWeapons [ source ] ) then for weapon, ammo in pairs ( playerWeapons [ source ] ) do giveWeapon ( source, tonumber ( weapon ), tonumber ( ammo ) ) end end playerWeapons [ source ] = nil end )
MatXpl Posted January 9, 2014 Author Posted January 9, 2014 -- By Solidsnake14 local playerWeapons = { } addEventHandler ( "onPlayerWasted", root, function ( ) if ( not playerWeapons [ source ] ) then playerWeapons [ source ] = { } end for slot = 0, 12 do local weapon = getPedWeapon ( source, slot ) if ( weapon > 0 ) then local ammo = getPedTotalAmmo ( source, slot ) if ( ammo > 0 ) then playerWeapons [ source ] [ weapon ] = ammo end end end end ) addEventHandler ( "onPlayerSpawn", root, function ( ) if ( playerWeapons [ source ] ) then for weapon, ammo in pairs ( playerWeapons [ source ] ) do giveWeapon ( source, tonumber ( weapon ), tonumber ( ammo ) ) end end playerWeapons [ source ] = nil end ) now i have this code, all works okay, but today i saw when i have 4 ammo of flamethrover after death it's giving me 49 ammo of flamethrover, but all other weapons work good. what's wrong?
MatXpl Posted January 9, 2014 Author Posted January 9, 2014 nope local playerWeapons = { } function respawn() local p = source if ( not playerWeapons [ p ] ) then playerWeapons [ p ] = { } end for slot = 0, 12 do local weapon = getPedWeapon ( p, slot ) if ( weapon > 0 ) then local ammo = getPedTotalAmmo ( p, slot ) if ( ammo > 0 ) then playerWeapons [ p ] [ weapon ] = ammo end end end setTimer(function(p) local skin = getElementModel(p) spawnPlayer(p,1607.3,1816.5,11,0,skin) local accName = getAccountName ( getPlayerAccount ( p) ) if ( playerWeapons [ p ] ) then for weapon, ammo in pairs ( playerWeapons [ p ] ) do giveWeapon ( p, tonumber ( weapon ), tonumber ( ammo ) ) end end playerWeapons [ p ] = nil end,4000,1,source) end addEventHandler("onPlayerWasted",getRootElement(),respawn)
MatXpl Posted January 9, 2014 Author Posted January 9, 2014 but i see only this bug with flamethrover
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