GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 I had asked a question on the forums asking how many weapons a user could possibly have at one time and you said "a player could have 1 of every weapon" Unless you misunderstood my former question
Castillo Posted June 23, 2012 Posted June 23, 2012 https://wiki.multitheftauto.com/wiki/Weapons Are you sure that I didn't say: "A player can have a weapon of every slot." ?
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 Possibly, i have set the Account system to 12 slots now. Thank you for that bit, however, my original problem still stands. Any ideas?
Castillo Posted June 23, 2012 Posted June 23, 2012 Are you sure they aren't being saved? try adding debug outputs to the script.
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 The first time, it goes through and the weapons Bat and Pistol show up once. The next death on getPedWeapon it says the user has no weapons.
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 My question is, what is wrong with my code, that causes it not to save the users weapons on the second time dieing.
Castillo Posted June 23, 2012 Posted June 23, 2012 I don't see anything wrong with it. P.S: Why you declare your tables global? they should be local inside the function.
Jaysds1 Posted June 23, 2012 Posted June 23, 2012 try this: function storeWeps(player) for i=0,12 do local pedWep = getPedWeapon(player,i) if(pedWep)then playerTable[player]={pedWep} end end end function getMyWeps(player) local myWep = playerTable[player] if(myWep)then for i,v in ipairs(myWep)do giveWeapon(player,v) end end end addEventHandler("onPlayerWasted",root,function() storeWeps(source) end) addEventHandler("onPlayerSpawn",root,function() getMyWeps(source) end)
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 My problem is the getPedWeapon on the second death says the ped does not have any weapons. If the ped dies once, it says the ped has a pistol and bat, stores it, then restores it after spawning. However, if the ped dies again, it doesn't say the ped has any weapons, like the first time the ped died.
Castillo Posted June 23, 2012 Posted June 23, 2012 function RecyclePlayerStats ( source ) local PlayerSTATTable = { } PlayerSTATTable.PlayerWeapons = makeClientWeaponsTable ( source ) PlayerSTATTable.POSX, PlayerSTATTable.POSY, PlayerSTATTable.POSZ = getElementPosition ( source ) return PlayerSTATTable end function makeClientWeaponsTable ( source ) local temptable = { } for slot = 0, 11 do --12 possible weapons local weapon = getPedWeapon ( source, slot ) if ( weapon ~= 0 ) then temptable [ weapon ] = getPedTotalAmmo ( source, slot ) end end return temptable end
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 I'm not sure what it is you have changed other then the if block. Even so it doesn't work. The problem is, One first spawn, the player has a pistol and a bat. -Player dies, at the event the weapons are retrieved, saved, player spawns, then weapons are restored. -Player dies again, at the event, weapons are NOT retrieved as none are found?
Castillo Posted June 23, 2012 Posted June 23, 2012 Ok, I've added a 1 second timer and it's working now. function RecyclePlayerStats ( thePlayer ) local PlayerSTATTable = { } PlayerSTATTable.PlayerWeapons = makeClientWeaponsTable ( thePlayer ) PlayerSTATTable.POSX, PlayerSTATTable.POSY, PlayerSTATTable.POSZ = getElementPosition ( thePlayer ) return PlayerSTATTable end function makeClientWeaponsTable ( thePlayer ) local temptable = { } for slot = 0, 11 do --12 possible weapons local weapon = getPedWeapon ( thePlayer, slot ) if ( weapon ~= 0 ) then temptable [ weapon ] = getPedTotalAmmo ( thePlayer, slot ) end end return temptable end addEventHandler ( "onPlayerWasted", getRootElement(), function ( ) local PlayerTable = RecyclePlayerStats ( source ) --Tell death --Spawn the player setTimer ( function ( thePlayer, stats ) if spawnPlayer ( thePlayer, stats.POSX, stats.POSY, stats.POSZ ) then --Give the player his weapons for Weapon, Ammo in pairs ( stats.PlayerWeapons ) do outputChatBox ( tostring ( Weapon ) ) --DEBUG giveWeapon ( thePlayer, Weapon, Ammo ) end fadeCamera ( thePlayer, true ) setCameraTarget ( thePlayer, thePlayer ) end end ,1000, 1, source, PlayerTable ) end )
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 (edited) Can you please explain why you had to use a timer? Is it that the server asks for the information too fast? Just in case i run into this again. Edited June 23, 2012 by Guest
GhostXoP Posted June 23, 2012 Author Posted June 23, 2012 So the time may range even longer then once second? Either way, Thank you very much for solving this Extensive problem. When this server is done, i may consider putting you as a mod for bug watch.
Castillo Posted June 23, 2012 Posted June 23, 2012 You're welcome. And I doubt I would accept, I got enough with my own server .
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