boro Posted August 3, 2014 Share Posted August 3, 2014 Hi i have this script for save Weapon When i wasted then it work good but when i reconect then my weapon dont are saved why? help pls.. function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then for weapon = 0, 12 do setAccountData ( playeraccount, "s.weap".. weapon, getPedWeapon ( source, weapon ) ) setAccountData ( playeraccount, "s.ammo".. weapon, getPedTotalAmmo ( source, weapon ) ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, function ( _, playeraccount ) for weapon = 0, 12 do local weap = getAccountData ( playeraccount, "s.weap".. weapon ) local ammo = getAccountData ( playeraccount, "s.ammo".. weapon ) giveWeapon ( source, weap, ammo ) end end ) 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 ) Link to comment
Castillo Posted August 3, 2014 Share Posted August 3, 2014 Any errors in debugscript? Link to comment
boro Posted August 3, 2014 Author Share Posted August 3, 2014 yes it show this WARNING: [gameplay]\weaponsaver\saveS.lua:17: Bad argument @ 'giveWeapon' [Expected weapon-type at argument 2, got boolean] Link to comment
RottenFlesh Posted August 3, 2014 Share Posted August 3, 2014 (edited) Maybe there is no weapon data in the account, that's why you get false (boolean) returned by the getAccountData function. Edited August 3, 2014 by Guest Link to comment
Addlibs Posted August 3, 2014 Share Posted August 3, 2014 Also attach onPlayerLogout event to onPlayerQuit function and test for any /debugscript 3 messages when using /logout (debugscript should stay open when logging out) There must be a reason why account data wasn't set. Link to comment
boro Posted August 3, 2014 Author Share Posted August 3, 2014 yes i test it and when i use logout then script work good but when i reconect and then open debug then see this warning and script dont work Link to comment
RottenFlesh Posted August 3, 2014 Share Posted August 3, 2014 do this after line 16: outputDebugString("s.weap data: "..tostring(weap), 3) outputDebugString("s.ammo data: "..tostring(ammo), 3) What does it output? And are you shure you are logged in when you test this script? Link to comment
boro Posted August 3, 2014 Author Share Posted August 3, 2014 i test it with this addEventHandler("onPlayerLogout",root,function(prev) onPlayerQuit(source, prev) end) and onPlayerLogout work fine but onPlayerQuit dont work Link to comment
boro Posted August 3, 2014 Author Share Posted August 3, 2014 Ok now show it this [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 1 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 30 [2014-08-03 20:54:21] INFO: s.ammo data: 270 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 [2014-08-03 20:54:21] INFO: s.weap data: 0 [2014-08-03 20:54:21] INFO: s.ammo data: 0 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