Clipper_ Posted December 11, 2014 Share Posted December 11, 2014 (edited) Hello here! I need help in something function savePlayerData (thePlayer) if not (isGuestAccount (getPlayerAccount (source))) then local playeraccount = getPlayerAccount if ( playeraccount ) then local isPlayerInClass = getPlayerTeam( source ) if ( ( isPlayerInClass ) and not isGuestAccount( account ) ) then setAccountData(playeraccount, "save.Player.Class", getTeamName( isPlayerInClass )) end end end end addEventHandler("onPlayerQuit", root, savePlayerData); addEventHandler("onPlayerLogout", root, savePlayerData); function loadPlayerData () if not (isGuestAccount (getPlayerAccount (source))) then local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local isPedInClass = getAccountData (playeraccount, "save.Player.Class") if ( ( isPedInClass ) and getTeamFromName( isPedInClass ) ) then setPlayerTeam(source, getTeamFromName( isPedInClass )) end end end end addEventHandler("onPlayerLogin", root, loadPlayerData) addEventHandler ("onPlayerLogin",root, function() loadStats( getPlayerAccount(source)) end ) addEventHandler ("onPlayerQuit",root, function() saveStats( getPlayerAccount(source)) end ) addEventHandler ("onPlayerLogout",root, function() saveStats( getPlayerAccount(prev)) end ) addEventHandler ("onPlayerWasted",root, function() loadStats( getPlayerAccount(source)) end ) function saveStats( Acc) for i = 69 , 79 do setAccountData(Acc, "stat."..i , getPedStat(source,i)) end end function loadStats(Acc ) for i = 69 , 79 do setPedStat(source,i,getAccountData(Acc, "stat."..i)) end end Can you help me with some lines for saving the stats after dying? I mean, stats are to basic value after the ped is dead. And i can't figure out how to save them. I tried something in lines 43 - 49, but effect is same (basic stats after ped is dead) Sorry for my english! Leave here a messaje if you all have a solution. Thanks! Edited December 11, 2014 by Guest Link to comment
Clipper_ Posted December 11, 2014 Author Share Posted December 11, 2014 Or if I stop defaultstats and then i set the stats from admin panel, will it have the effect i want? Link to comment
Anubhav Posted December 12, 2014 Share Posted December 12, 2014 (edited) The thing I found was line 3. You forgot to make getPlayerAccount ( thePlayer ). source is not defined, it should be thePlayerIt's okay as it's. Just see my first line and done. I din't see the event. Edited December 12, 2014 by Guest Link to comment
John Smith Posted December 12, 2014 Share Posted December 12, 2014 The thing I found was line 3. You forgot to make getPlayerAccount ( thePlayer ).source is not defined, it should be thePlayer actually he has to put source or thePlayer instead of source, because (i'm guessing) that he wants to trigger that first function with source element and thePlayer as well when calling the function example local playeraccount = getPlayerAccount(source) or getPlayerAccount(thePlayer) Link to comment
Clipper_ Posted December 12, 2014 Author Share Posted December 12, 2014 (edited) thank you Edited December 12, 2014 by Guest Link to comment
Clipper_ Posted December 12, 2014 Author Share Posted December 12, 2014 The thing I found was line 3. You forgot to make getPlayerAccount ( thePlayer ).source is not defined, it should be thePlayer actually he has to put source or thePlayer instead of source, because (i'm guessing) that he wants to trigger that first function with source element and thePlayer as well when calling the function example local playeraccount = getPlayerAccount(source) or getPlayerAccount(thePlayer) well the replacement work. now i have problems with some lines function savePlayerData (thePlayer) local playeraccount = getPlayerAccount(thePlayer) if (playeraccount) then local isPlayerInClass = getPlayerTeam(thePlayer) if ( ( isPlayerInClass ) and not isGuestAccount( account ) ) then setAccountData(playeraccount, "save.Player.Class", getTeamName( isPlayerInClass )) end end end addEventHandler("onPlayerQuit", root, savePlayerData); addEventHandler("onPlayerLogout", root, savePlayerData); addEventHandler("onPlayerWasted", root, savePlayerData); function loadPlayerData (thePlayer) local playeraccount = getPlayerAccount(thePlayer) if (playeraccount) then local isPedInClass = getAccountData (playeraccount, "save.Player.Class") if ( ( isPedInClass ) and getTeamFromName( isPedInClass ) ) then setPlayerTeam(source, getTeamFromName( isPedInClass )) end end end addEventHandler("onPlayerQuit", root, loadPlayerData) addEventHandler("onPlayerLogout", root, loadPlayerData) addEventHandler("onPlayerWasted", root, loadPlayerData) addEventHandler ("onPlayerLogin",root, function() loadStats( getPlayerAccount(thePlayer)) end ) addEventHandler ("onPlayerQuit",root, function() saveStats( getPlayerAccount(thePlayer)) end ) addEventHandler ("onPlayerLogout",root, function() saveStats( getPlayerAccount(thePlayer)) end ) addEventHandler ("onPlayerWasted",root, function() loadStats( getPlayerAccount(thePlayer)) end ) function saveStats( Acc) for i = 69 , 79 do setAccountData(thePlayer, "stat."..i , getPedStat(thePlayer,i)) end end function loadStats(Acc ) for i = 69 , 79 do setPedStat(thePlayer, i, getAccountData(Acc, "stat."..i)) end end Console response: [2014-12-12 20:06:15] WARNING: stats\main_s.lua:2: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got number '22'] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:14: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got number '22'] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:43: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'setPedStat' [Expected element at argument 1, got nil] [2014-12-12 20:06:15] WARNING: stats\main_s.lua:55: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] Well i am at beggining of scripting. I was searching in community, in wiki to solve it. Same things. I did a progress by saving the stats after ped is dead. But the stats are 0 after exiting or reconnecting. You can check this. Thank you again Link to comment
John Smith Posted December 12, 2014 Share Posted December 12, 2014 There. I have also added comments in the script which mistakes you have done. function savePlayerData () -- those events use other arguments such as weapon and such in the function so you have used weapon as the player which doesnt make any sense, remember, source of events is a player, read through wiki local playeraccount = getPlayerAccount(source) if (playeraccount) then local isPlayerInClass = getPlayerTeam(source) if ( ( isPlayerInClass ) and not isGuestAccount( account ) ) then setAccountData(playeraccount, "save.Player.Class", getTeamName( isPlayerInClass )) end end end addEventHandler("onPlayerQuit", root, savePlayerData); addEventHandler("onPlayerLogout", root, savePlayerData); addEventHandler("onPlayerWasted", root, savePlayerData); function loadPlayerData ()-- same like line 2 in this function local playeraccount = getPlayerAccount(source) -- same thing here as line 2 if (playeraccount) then local isPedInClass = getAccountData (playeraccount, "save.Player.Class") if ( ( isPedInClass ) and getTeamFromName( isPedInClass ) ) then setPlayerTeam(source, getTeamFromName( isPedInClass )) end end end addEventHandler("onPlayerQuit", root, loadPlayerData) addEventHandler("onPlayerLogout", root, loadPlayerData) addEventHandler("onPlayerWasted", root, loadPlayerData) addEventHandler ("onPlayerLogin",root, function() loadStats( getPlayerAccount(source), source) -- you need to pass source(a player in this case) to function so that you can define the player in completely another function end ) addEventHandler ("onPlayerQuit",root, function() saveStats( getPlayerAccount(thePlayer), source) -- same like line 28 end ) addEventHandler ("onPlayerLogout",root, function() saveStats( getPlayerAccount(thePlayer), source)-- same like line 28 end ) addEventHandler ("onPlayerWasted",root, function() loadStats( getPlayerAccount(source), source) -- player who died is source, and not thePlayer. read wiki through end ) function saveStats( Acc, thePlayer ) for i = 69 , 79 do setAccountData(thePlayer, "stat."..i , getPedStat(thePlayer,i)) end end function loadStats(Acc, thePlayer ) for i = 69 , 79 do setPedStat(thePlayer, i, getAccountData(Acc, "stat."..i)) end end Link to comment
Clipper_ Posted December 12, 2014 Author Share Posted December 12, 2014 Ok thank you. Appreciate it . I will test it later. Link to comment
Clipper_ Posted December 15, 2014 Author Share Posted December 15, 2014 It's still not working. Link to comment
John Smith Posted December 15, 2014 Share Posted December 15, 2014 post debugscript 3 errors Link to comment
Anubhav Posted December 16, 2014 Share Posted December 16, 2014 John, the error's are clear. You also have not corrected everything. function savePlayerData( ) -- those events use other arguments such as weapon and such in the function so you have used weapon as the player which doesnt make any sense, remember, source of events is a player, read through wiki local playeraccount = getPlayerAccount( source ) if ( playeraccount ) then local isPlayerInClass = getPlayerTeam( source ) if ( ( isPlayerInClass ) and not isGuestAccount( playeraccount ) ) then -- Here was a nil value: It was playeraccount but you wrote it account! Be carefull! setAccountData( playeraccount, "save.Player.Class", getTeamName( isPlayerInClass ) ) end end end addEventHandler( "onPlayerQuit", root, savePlayerData ) addEventHandler( "onPlayerLogout", root, savePlayerData ) addEventHandler( "onPlayerWasted", root, savePlayerData ) function loadPlayerData( )-- same like line 2 in this function local playeraccount = getPlayerAccount( source ) -- same thing here as line 2 if (playeraccount) then local isPedInClass = getAccountData( playeraccount, "save.Player.Class" ) if ( ( isPedInClass ) and getTeamFromName( isPedInClass ) ) then setPlayerTeam( source, getTeamFromName( isPedInClass ) ) end end end addEventHandler( "onPlayerLogin", root, loadPlayerData ) -- Here was onPlayerQuit, so you have to load it when player logins. --addEventHandler("onPlayerLogout", root, loadPlayerData) I commented this line because you don't need to load the data while the player logouts, because when you login it'll be there! addEventHandler( "onPlayerWasted", root, loadPlayerData ) addEventHandler( "onPlayerLogin", root, function( ) loadStats( getPlayerAccount( source ), source ) -- you need to pass source(a player in this case) to function so that you can define the player in completely another function end ) addEventHandler( "onPlayerQuit", root, function( ) saveStats( getPlayerAccount( thePlayer ), source ) -- same like line 28 end ) addEventHandler( "onPlayerLogout", root, function( ) saveStats( getPlayerAccount( thePlayer ), source )-- same like line 28 end ) addEventHandler( "onPlayerWasted", root, function() loadStats( getPlayerAccount( source ), source ) -- player who died is source, and not thePlayer. read wiki through end ) function saveStats( Acc, thePlayer ) for i = 69 , 79 do setAccountData( thePlayer, "stat."..tostring( i ) , getPedStat( thePlayer, i ) ) end end function loadStats( Acc, thePlayer ) for i = 69 , 79 do setPedStat( thePlayer, i, getAccountData( Acc, "stat."..tostring( i ) ) ) -- Here and above, the i is a number and there's a string. And in account data values are in string only. end end EDIT-1: I indented it also! Re-read all the comments. Link to comment
Clipper_ Posted December 16, 2014 Author Share Posted December 16, 2014 The "debugscript" hadn't showed me some errors. By the way, thank you guys for your effort !!! 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