roaddog Posted July 5, 2014 Share Posted July 5, 2014 I need help with this save system, It doesn't want to work. I get headache because of this, I have tried alot things to fix but you know my capability is not good enough. thus this save system doesnt save em. I need help function loginHandler(thePlayer, username, password) if (username ~= "" and username ~= nil and password ~= "" and password ~= nil) then local account = getAccount(username) if (account) then local daRealAccount = getAccount(username, password) if (daRealAccount) then local x = getAccountData(daRealAccount, "x.position12") local y = getAccountData(daRealAccount, "y.position12") local z = getAccountData(daRealAccount, "z.position12") local playerWanted = getAccountData (daRealAccount, "wantedlevel") local armor = getAccountData(daRealAccount, "armor") local model = getAccountData(daRealAccount, "model") local interior = getAccountData(daRealAccount, "interior") local dimension = getAccountData(daRealAccount, "dimension") local rx = getAccountData(daRealAccount, "rotx") local ry = getAccountData(daRealAccount, "roty") local rz = getAccountData(daRealAccount, "rotz") local team = getTeamFromName("Unemployed") local money = getAccountData(daRealAccount, "Money") local health = getAccountData(daRealAccount, "health") local playerWeapons = getAccountData(daRealAccount, "weapons") if (x) and (y) and (z) then triggerClientEvent(thePlayer,"savexml",thePlayer,username,password) logIn(thePlayer, daRealAccount, password) triggerClientEvent(thePlayer,"hideWindow",thePlayer) fadeCamera(thePlayer, false, 2.0) setElementData(thePlayer, "basicrp.slider", 1) setElementData(thePlayer, "player.loggedin", 1) setTimer(function() if (playerWeapons and playerWeapons ~= "") then giveWeaponsFromJSON(thePlayer, playerWeapons) end spawnPlayer(thePlayer, tonumber(x), tonumber(y), tonumber(z)) setElementHealth ( thePlayer, tonumber(health)) --------------------------------- line 184 setPedArmor(thePlayer, tonumber(armor)) setPlayerWantedLevel(thePlayer, playerWanted) setElementInterior(thePlayer, tonumber(interior)) setElementDimension(thePlayer,tonumber(dimension)) setElementRotation(thePlayer, tonumber(rx), tonumber(ry), tonumber(rz)) setCameraTarget(thePlayer, thePlayer) showChat(thePlayer, true) setPedHeadless(thePlayer, false) setPlayerMoney(thePlayer, tonumber(money)) setElementModel(thePlayer, tonumber(model)) for i = 0,17 do local accd = getAccountData( daRealAccount, 'player.clothes.'..i ) if not accd:find 'false' then addPedClothes( thePlayer,accd:sub( 1,accd:find( ',' ) - 1 ),accd:sub( accd:find( ',' ) + 1,accd:len( ) ),i ) end end end, 2000, 1) setTimer(fadeCamera, 3000,1, thePlayer, true, 2.0) end end end end end function saveAccount(player) local account = getPlayerAccount(player) if isGuestAccount(account) then return end local money = getPlayerMoney(player) local health = tonumber(getElementHealth(player)) local armor = tonumber(getPedArmor(player)) local x, y, z = getElementPosition(player) local interior = tonumber(getElementInterior(player)) local dimension = tonumber(getElementDimension(player)) local model = tonumber(getElementModel(player)) local rx, ry, rz = getElementRotation(player) for i = 0,17 do local arg1,arg2 = getPedClothes( player, i ) setAccountData( account, "player.clothes."..tostring( i ),tostring( arg1 )..","..tostring( arg2 ) ) end setAccountData(account, "Money", money) setAccountData (account, "wantedlevel", getPlayerWantedLevel (player)) local weapons = convertWeaponsToJSON(player) setAccountData(account, "weapons", weapons) setAccountData(account, "health", health) setAccountData(account, "armor", armor) setAccountData(account, "model", model) setAccountData(account, "interior", interior) setAccountData(account, "dimension", dimension) setAccountData(account, "x.position12", tonumber(x)) setAccountData(account, "y.position12", tonumber(y)) setAccountData(account, "z.position12", tonumber(z)) setAccountData(account, "rotx", tonumber(rx)) setAccountData(account, "roty", tonumber(ry)) setAccountData(account, "rotz", tonumber(rz)) end ----------------saving them--------------------- addEventHandler("onPlayerQuit", cRoot, function() saveAccount(getPlayerAccount ( source )) end ) addEventHandler("onResourceStop", cThisRoot, function() for i,v in ipairs(getElementsByType("player")) do saveAccount(getPlayerAccount (v)) end end ) -----------------save weapons ------------------------------- function convertWeaponsToJSON(player) local weaponSlots = 12 local weaponsTable = {} for slot=1, weaponSlots do local weapon = getPedWeapon(player, slot ) local ammo = getPedTotalAmmo(player, slot ) if (weapon > 0 and ammo > 0) then weaponsTable[weapon] = ammo end end return toJSON(weaponsTable) end function giveWeaponsFromJSON(player, weapons) if (weapons and weapons ~= "") then for weapon, ammo in pairs(fromJSON(weapons)) do if (weapon and ammo) then giveWeapon(player, tonumber(weapon), tonumber(ammo)) end end end end -----------------saving wantedlevel on die------------------- addEventHandler ( "onPlayerWasted", root, function ( ) local account = getPlayerAccount(source) setAccountData ( account,"save-wanted",getPlayerWantedLevel ( source ) ) end ) addEventHandler ( "onPlayerSpawn", root, function () local account = getPlayerAccount ( source ) local playerWanted = getAccountData (account, "save-wanted") setPlayerWantedLevel ( source,playerWanted ) end ) Warnings [2014-07-06 05:45:46] WARNING: login\server.lua:184: Bad argument @ 'setElementHealth' [Expected number at argument 2, got nil] [2014-07-06 05:45:46] WARNING: login\server.lua:185: Bad argument @ 'setPedArmor' [2014-07-06 05:45:46] WARNING: login\server.lua:187: Bad argument @ 'setElementInterior' [Expected number at argument 2, got nil] [2014-07-06 05:45:46] WARNING: login\server.lua:188: Bad argument @ 'setElementDimension' [Expected number at argument 2, got nil] [2014-07-06 05:45:46] WARNING: login\server.lua:189: Bad argument @ 'setElementRotation' [Expected number at argument 2, got nil] [2014-07-06 05:45:46] WARNING: login\server.lua:194: Bad argument @ 'setElementModel' [Expected number at argument 2, got nil] I marked the folowing line in the code, Thank you very much Link to comment
Castillo Posted July 5, 2014 Share Posted July 5, 2014 Well, these error mean that the function ( e.g: setElementHealth ) expected a number, but instead, it got "nil", basically, the data is not there. You should make it so if the data is not available, use a default value. Link to comment
MTA Team botder Posted July 5, 2014 MTA Team Share Posted July 5, 2014 You are calling saveAccount always with an account element, but you should have passed the player element. That's why the "nil" values are being saved and also loaded, when the player logs in. for i,v in ipairs(getElementsByType("player")) do saveAccount(getPlayerAccount (v)) end addEventHandler("onPlayerQuit", cRoot, function() saveAccount(getPlayerAccount ( source )) end ) function saveAccount(player) local account = getPlayerAccount(player) Link to comment
roaddog Posted July 5, 2014 Author Share Posted July 5, 2014 Okay, I understand now, Thanks for helping. I have fixed that. 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