Jump to content

Saving system script


King12

Recommended Posts

Hello there,

I've downloaded this script from the community and my friend edited it.

we've tried everything but still somethings doesn't work.

firstly, when you login for the first time nothing happens, and when you logout and login again you will see punch of errors in debugscript 3

+

Nothing happen when you logout, no error messages or anything else.

My code :

  
  
 function savePlayerData (thePlayer) 
        if not (isGuestAccount (getPlayerAccount (source))) then 
        local playeraccount = getPlayerAccount (thePlayer) 
        if ( playeraccount ) then 
            local x,y,z = getElementPosition (source) 
            setAccountData (playeraccount, "save.MoneyInPocket", getPlayerMoney ( source ) ) 
            setAccountData (playeraccount, "save.skin", tostring (getPedSkin ( source))) 
            setAccountData (playeraccount, "save.x", x) 
            setAccountData (playeraccount, "save.y", y) 
            setAccountData (playeraccount, "save.z", z)  
            setAccountData (playeraccount, "save.int", getElementInterior ( source )) 
            setAccountData (playeraccount, "save.dim", getElementDimension ( source)) 
            setAccountData (playeraccount, "save.rot", getPedRotation ( source))             
            setAccountData (playeraccount, "save.weap0", getPedWeapon ( source, 0 )) 
            setAccountData (playeraccount, "save.weap1", getPedWeapon ( source, 1 )) 
            setAccountData (playeraccount, "save.weap2", getPedWeapon ( source, 2 )) 
            setAccountData (playeraccount, "save.ammo2", getPedTotalAmmo ( source, 2 )) 
            setAccountData (playeraccount, "save.weap3", getPedWeapon ( source, 3 )) 
            setAccountData (playeraccount, "save.ammo3", getPedTotalAmmo ( source, 3 )) 
            setAccountData (playeraccount, "save.weap4", getPedWeapon ( source, 4 )) 
            setAccountData (playeraccount, "save.ammo4", getPedTotalAmmo ( source, 4 )) 
            setAccountData (playeraccount, "save.weap5", getPedWeapon ( source, 5 )) 
            setAccountData (playeraccount, "save.ammo5", getPedTotalAmmo ( source, 5 )) 
            setAccountData (playeraccount, "save.weap6", getPedWeapon ( source, 6 )) 
            setAccountData (playeraccount, "save.ammo6", getPedTotalAmmo ( source, 6 )) 
            setAccountData (playeraccount, "save.weap7", getPedWeapon ( source, 7 )) 
            setAccountData (playeraccount, "save.ammo7", getPedTotalAmmo ( source, 7 )) 
            setAccountData (playeraccount, "save.weap8", getPedWeapon ( source, 8 )) 
            setAccountData (playeraccount, "save.ammo8", getPedTotalAmmo ( source, 8 )) 
            setAccountData (playeraccount, "save.weap9", getPedWeapon ( source, 9 )) 
            setAccountData (playeraccount, "save.ammo9", getPedTotalAmmo ( source, 9 )) 
            setAccountData (playeraccount, "save.weap10", getPedWeapon ( source, 10 )) 
            setAccountData (playeraccount, "save.weap11", getPedWeapon ( source, 11 )) 
            setAccountData (playeraccount, "save.weap12", getPedWeapon ( source, 12 )) 
            --# Skills 
            setAccountData (playeraccount, "save.Skill.Pistol", getPedStat( source, 69)) 
            setAccountData (playeraccount, "save.Skill.Silenced.Pistol", getPedStat( source, 70)) 
            setAccountData (playeraccount, "save.Skill.Desert.Eagle", getPedStat( source, 71)) 
            setAccountData (playeraccount, "save.Skill.Shotgun", getPedStat( source, 72)) 
            setAccountData (playeraccount, "save.Skill.Sawnoff.Shotgun", getPedStat( source, 73))        
            setAccountData (playeraccount, "save.Skill.SPAS12", getPedStat( source, 74))     
            setAccountData (playeraccount, "save.Skill.Uzi", getPedStat( source, 75))    
            setAccountData (playeraccount, "save.Skill.MP5", getPedStat( source, 76))    
            setAccountData (playeraccount, "save.Skill.AK47", getPedStat( source, 77)) 
            setAccountData (playeraccount, "save.Skill.M4", getPedStat( source, 78))     
            setAccountData (playeraccount, "save.Skill.Sniper.Rifle", getPedStat( source, 79)) 
            --# Classes 
            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 playerMoneyInPocket = getAccountData ( playeraccount, "save.MoneyInPocket" ) 
            if ( playerMoneyInPocket ) then 
                  setPlayerMoney ( source, playerMoneyInPocket ) 
            end 
            local playerInt = getAccountData(playeraccount, "save.int") 
            local playerDim = getAccountData(playeraccount, "save.dim")   
            local playerSkin = getAccountData(playeraccount, "save.skin") 
            local playerX = getAccountData(playeraccount, "save.x") 
            local playerY = getAccountData(playeraccount, "save.y") 
            local playerZ = getAccountData(playeraccount, "save.z") 
            local playerRot = getAccountData(playeraccount, "save.rot") 
                if playerX and playerY and playerZ and playerSkin then 
                    spawnPlayer(source, playerX, playerY, playerZ, playerRot, tonumber(playerSkin) ) 
                else  
                    spawnPlayer(source,1182.04358, -2223.13159, 43.62173,math.random(0,360)) 
                end      
                fadeCamera (source, true) 
                setCameraTarget (source, source)     
            local weap0 = getAccountData(playeraccount, "save.weap0") 
            local weap1 = getAccountData(playeraccount, "save.weap1") 
            local weap2 = getAccountData(playeraccount, "save.weap2") 
            local ammo2 = getAccountData(playeraccount, "save.ammo2") 
            local weap3 = getAccountData(playeraccount, "save.weap3") 
            local ammo3 = getAccountData(playeraccount, "save.ammo3") 
            local weap4 = getAccountData(playeraccount, "save.weap4") 
            local ammo4 = getAccountData(playeraccount, "save.ammo4") 
            local weap5 = getAccountData(playeraccount, "save.weap5") 
            local ammo5 = getAccountData(playeraccount, "save.ammo5") 
            local weap6 = getAccountData(playeraccount, "save.weap6") 
            local ammo6 = getAccountData(playeraccount, "save.ammo6") 
            local weap7 = getAccountData(playeraccount, "save.weap7") 
            local ammo7 = getAccountData(playeraccount, "save.ammo7") 
            local weap8 = getAccountData(playeraccount, "save.weap8") 
            local ammo8 = getAccountData(playeraccount, "save.ammo8") 
            local weap9 = getAccountData(playeraccount, "save.weap9") 
            local ammo9 = getAccountData(playeraccount, "save.ammo9") 
            local weap10 = getAccountData(playeraccount, "save.weap10") 
            local weap11 = getAccountData(playeraccount, "save.weap11") 
            local weap12 = getAccountData(playeraccount, "save.weap12") 
                giveWeapon ( source, weap0, 1 ) 
                giveWeapon ( source, weap1, 1 ) 
                giveWeapon ( source, weap2, ammo2 ) 
                giveWeapon ( source, weap3, ammo3 ) 
                giveWeapon ( source, weap4, ammo4 ) 
                giveWeapon ( source, weap5, ammo5 ) 
                giveWeapon ( source, weap6, ammo6 ) 
                giveWeapon ( source, weap7, ammo7 ) 
                giveWeapon ( source, weap8, ammo8 ) 
                giveWeapon ( source, weap9, ammo9 ) 
                giveWeapon ( source, weap10, 1 ) 
                giveWeapon ( source, weap11, 1 ) 
                giveWeapon ( source, weap12, 1 ) 
            --# Skills               
            local Skill_Pistol = getAccountData(playeraccount, "save.Skill.Pistol")  
            local Skill_Silenced_Pistol = getAccountData(playeraccount, "save.Skill.Silenced.Pistol")    
            local Skill_Desert_Eagle = getAccountData(playeraccount, "save.Skill.Desert.Eagle")      
            local Skill_Shotgun = getAccountData(playeraccount, "save.Skill.Shotgun") 
            local Skill_Sawnoff_Shotgun = getAccountData(playeraccount, "save.Skill.Sawnoff.Shotgun") 
            local Skill_SPAS12 = getAccountData(playeraccount, "save.Skill.SPAS12")      
            local Skill_Uzi = getAccountData(playeraccount, "save.Skill.Uzi") 
            local Skill_MP5 = getAccountData(playeraccount, "save.Skill.MP5") 
            local Skill_AK47 = getAccountData(playeraccount, "save.Skill.AK47") 
            local Skill_M4 = getAccountData(playeraccount, "save.Skill.M4")  
            local Skill_Sniper_Rifle = getAccountData(playeraccount, "save.Skill.Sniper.Rifle")              
                setPedStat( source, 69, Skill_Pistol ) 
                setPedStat( source, 70, Skill_Silenced_Pistol ) 
                setPedStat( source, 71, Skill_Desert_Eagle ) 
                setPedStat( source, 72, Skill_Shotgun ) 
                setPedStat( source, 73, Skill_Sawnoff_Shotgun ) 
                setPedStat( source, 74, Skill_SPAS12 ) 
                setPedStat( source, 75, Skill_Uzi ) 
                setPedStat( source, 76, Skill_MP5 ) 
                setPedStat( source, 77, Skill_AK47 ) 
                setPedStat( source, 78, Skill_M4 ) 
                setPedStat( source, 79, Skill_Sniper_Rifle )     
            --# Classes 
            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) 
             
  

Some of the errors :

  
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:128: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:129: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:130: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:131: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:132: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:133: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:134: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:135: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:136: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 
[17:01:03] WARNING: save-system-1\server.lua:137: Bad argument @ 'setPedStat' [E 
xpected number at argument 3, got boolean] 

Link to comment
function savePlayerData (thePlayer) 
        if not (isGuestAccount (getPlayerAccount (source))) then 
        local playeraccount = getPlayerAccount (thePlayer) 
        if ( playeraccount ) then 
            local x,y,z = getElementPosition (source) 
            setAccountData (playeraccount, "save.MoneyInPocket", getPlayerMoney ( source ) ) 
            setAccountData (playeraccount, "save.skin", tostring (getPedSkin ( source))) 
            setAccountData (playeraccount, "save.x", x) 
            setAccountData (playeraccount, "save.y", y) 
            setAccountData (playeraccount, "save.z", z)  
            setAccountData (playeraccount, "save.int", getElementInterior ( source )) 
            setAccountData (playeraccount, "save.dim", getElementDimension ( source)) 
            setAccountData (playeraccount, "save.rot", getPedRotation ( source))            
            setAccountData (playeraccount, "save.weap0", getPedWeapon ( source, 0 )) 
            setAccountData (playeraccount, "save.weap1", getPedWeapon ( source, 1 )) 
            setAccountData (playeraccount, "save.weap2", getPedWeapon ( source, 2 )) 
            setAccountData (playeraccount, "save.ammo2", getPedTotalAmmo ( source, 2 )) 
            setAccountData (playeraccount, "save.weap3", getPedWeapon ( source, 3 )) 
            setAccountData (playeraccount, "save.ammo3", getPedTotalAmmo ( source, 3 )) 
            setAccountData (playeraccount, "save.weap4", getPedWeapon ( source, 4 )) 
            setAccountData (playeraccount, "save.ammo4", getPedTotalAmmo ( source, 4 )) 
            setAccountData (playeraccount, "save.weap5", getPedWeapon ( source, 5 )) 
            setAccountData (playeraccount, "save.ammo5", getPedTotalAmmo ( source, 5 )) 
            setAccountData (playeraccount, "save.weap6", getPedWeapon ( source, 6 )) 
            setAccountData (playeraccount, "save.ammo6", getPedTotalAmmo ( source, 6 )) 
            setAccountData (playeraccount, "save.weap7", getPedWeapon ( source, 7 )) 
            setAccountData (playeraccount, "save.ammo7", getPedTotalAmmo ( source, 7 )) 
            setAccountData (playeraccount, "save.weap8", getPedWeapon ( source, 8 )) 
            setAccountData (playeraccount, "save.ammo8", getPedTotalAmmo ( source, 8 )) 
            setAccountData (playeraccount, "save.weap9", getPedWeapon ( source, 9 )) 
            setAccountData (playeraccount, "save.ammo9", getPedTotalAmmo ( source, 9 )) 
            setAccountData (playeraccount, "save.weap10", getPedWeapon ( source, 10 )) 
            setAccountData (playeraccount, "save.weap11", getPedWeapon ( source, 11 )) 
            setAccountData (playeraccount, "save.weap12", getPedWeapon ( source, 12 )) 
            --# Classes 
            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 playerMoneyInPocket = getAccountData ( playeraccount, "save.MoneyInPocket" ) 
            if ( playerMoneyInPocket ) then 
                  setPlayerMoney ( source, playerMoneyInPocket ) 
            end 
            local playerInt = getAccountData(playeraccount, "save.int") 
            local playerDim = getAccountData(playeraccount, "save.dim")   
            local playerSkin = getAccountData(playeraccount, "save.skin") 
            local playerX = getAccountData(playeraccount, "save.x") 
            local playerY = getAccountData(playeraccount, "save.y") 
            local playerZ = getAccountData(playeraccount, "save.z") 
            local playerRot = getAccountData(playeraccount, "save.rot") 
                if playerX and playerY and playerZ and playerSkin then 
                    spawnPlayer(source, playerX, playerY, playerZ, playerRot, tonumber(playerSkin) ) 
                else 
                    spawnPlayer(source,1182.04358, -2223.13159, 43.62173,math.random(0,360)) 
                end     
                fadeCamera (source, true) 
                setCameraTarget (source, source)    
            local weap0 = getAccountData(playeraccount, "save.weap0") 
            local weap1 = getAccountData(playeraccount, "save.weap1") 
            local weap2 = getAccountData(playeraccount, "save.weap2") 
            local ammo2 = getAccountData(playeraccount, "save.ammo2") 
            local weap3 = getAccountData(playeraccount, "save.weap3") 
            local ammo3 = getAccountData(playeraccount, "save.ammo3") 
            local weap4 = getAccountData(playeraccount, "save.weap4") 
            local ammo4 = getAccountData(playeraccount, "save.ammo4") 
            local weap5 = getAccountData(playeraccount, "save.weap5") 
            local ammo5 = getAccountData(playeraccount, "save.ammo5") 
            local weap6 = getAccountData(playeraccount, "save.weap6") 
            local ammo6 = getAccountData(playeraccount, "save.ammo6") 
            local weap7 = getAccountData(playeraccount, "save.weap7") 
            local ammo7 = getAccountData(playeraccount, "save.ammo7") 
            local weap8 = getAccountData(playeraccount, "save.weap8") 
            local ammo8 = getAccountData(playeraccount, "save.ammo8") 
            local weap9 = getAccountData(playeraccount, "save.weap9") 
            local ammo9 = getAccountData(playeraccount, "save.ammo9") 
            local weap10 = getAccountData(playeraccount, "save.weap10") 
            local weap11 = getAccountData(playeraccount, "save.weap11") 
            local weap12 = getAccountData(playeraccount, "save.weap12") 
                giveWeapon ( source, weap0, 1 ) 
                giveWeapon ( source, weap1, 1 ) 
                giveWeapon ( source, weap2, ammo2 ) 
                giveWeapon ( source, weap3, ammo3 ) 
                giveWeapon ( source, weap4, ammo4 ) 
                giveWeapon ( source, weap5, ammo5 ) 
                giveWeapon ( source, weap6, ammo6 ) 
                giveWeapon ( source, weap7, ammo7 ) 
                giveWeapon ( source, weap8, ammo8 ) 
                giveWeapon ( source, weap9, ammo9 ) 
                giveWeapon ( source, weap10, 1 ) 
                giveWeapon ( source, weap11, 1 ) 
                giveWeapon ( source, weap12, 1 )   
            --# Classes 
            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 
) 
  
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 

Link to comment

Me and My friend have made a new code, the script outputs the money value when you logout but it doesn't load when you login.

same with the other functions like getPedStat.

  
dataTable = { 
"MoneyInPocket", 
} 
  
function savePlayerData () 
        local playeraccount = getPlayerAccount(source) 
        if ( playeraccount ) then 
            for i,data in ipairs(dataTable) do 
            if data == "MoneyInPocket" then 
                setAccountData(playeraccount,"save."..data,getPlayerMoney(source)) 
                outputChatBox(getAccountData (playeraccount, "save."..data)) 
            end 
        end 
    end 
end      
addEventHandler("onPlayerQuit", root, savePlayerData); 
addEventHandler("onPlayerLogout", root, savePlayerData);         
  
function loadPlayerData () 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) then 
        for i,data in ipairs(dataTable) do 
        if data == "MoneyInPocket" then 
                setPlayerMoney(source,tonumber(getAccountData (playeraccount, "save."..data)) or 0) 
                outputChatBox(getAccountData (playeraccount, "save."..data)) 
                         end                         
        end 
    end 
end 
addEventHandler("onPlayerLogin", root, loadPlayerData) 
  

NightFury, your codes output'ing alot of errors.

دون : none of your scripts working.

prestige @ ixjf : I want to get the value, I've tried tonumber and still not working.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...