Jump to content

save stats


-stolka-

Recommended Posts

why doesnt it save my stats when i die/reconnect ???

addEventHandler("onPlayerSpawn", root, 
  function() 
    local playerAccount = getPlayerAccount( source ) 
    if playerAccount then 
     -- shotgun 
     local shotgunSkill = getAccountData(playerAccount, "shotgunskill") 
     if not shotgunSkill then 
     setPedStat(source, 72, 1) 
     else 
     setPedStat(source, 72, shotgunSkill) 
     end 
     -- m4 
     local m4Skill = getAccountData(playerAccount, "m4skill") 
     if not m4Skill then 
     setPedStat(source, 78, 1) 
     else 
     setPedStat(source, 78, m4Skill) 
     end 
     -- ak47 
     local ak47Skill = getAccountData(playerAccount, "ak47skill") 
     if not ak47Skill then 
     setPedStat(source, 77, 1) 
     else 
     setPedStat(source, 77, ak47Skill) 
     end    
     -- colt45 
     local colt45Skill = getAccountData(playerAccount, "colt45skill") 
     if not colt45Skill then 
     setPedStat(source, 69, 1) 
     else 
     setPedStat(source, 69, colt45Skill) 
     end 
     -- silenced 
     local silencedSkill = getAccountData(playerAccount, "silencedskill") 
     if not silencedSkill then 
     setPedStat(source, 70, 1) 
     else 
     setPedStat(source, 70, silencedSkill) 
     end     
     -- sawnoff shotgun 
     local sawnoffSkill = getAccountData(playerAccount, "sawnoffskill") 
     if not shotgunSkill then 
     setPedStat(source, 73, 1) 
     else 
     setPedStat(source, 73, sawnoffSkill) 
     end  
     -- sniper 
     local sniperSkill = getAccountData(playerAccount, "sniperskill") 
     if not sniperSkill then 
     setPedStat(source, 79, 1) 
     else 
     setPedStat(source, 79, sniperSkill) 
     end  
     -- spas12 
     local spas12Skill = getAccountData(playerAccount, "spas12skill") 
     if not spas12Skill then 
     setPedStat(source, 74, 1) 
     else 
     setPedStat(source, 74, spas12Skill) 
     end            
     -- deagle   
     local deagleSkill = getAccountData(playerAccount, "deagleskill") 
     if not deagleSkill then 
     setPedStat(source, 71, 1) 
     else 
     setPedStat(source, 71, deagleSkill) 
     end       
     -- mp5 
     local mp5Skill = getAccountData(playerAccount, "mp5skill") 
     if not mp5Skill then 
     setPedStat(source, 76, 1) 
     else 
     setPedStat(source, 76, mp5Skill) 
     end      
     -- uzi 
     local uziSkill = getAccountData(playerAccount, "uziskill") 
     if not uziSkill then 
     setPedStat(source, 75, 1) 
     else 
     setPedStat(source, 75, uziSkill) 
     end                    
    end 
  end 
) 
  
  
function savePlayerStats (  ) 
 local account = getPlayerAccount(source) 
  if account then 
   local colt45 = getPedStat(source, 69 ) 
   local sileced = getPedStat(source, 70 ) 
   local deagle = getPedStat(source, 71 ) 
   local shotgun = getPedStat(source, 72 ) 
   local swanoff = getPedStat(source, 73 ) 
   local spas12 = getPedStat(source, 74 ) 
   local uzi = getPedStat(source, 75 ) 
   local mp5 = getPedStat(source, 76 ) 
   local ak47 = getPedStat(source, 77 ) 
   local m4 = getPedStat(source, 78 ) 
   local sniper = getPedStat(source, 79 ) 
   -- setAccountData 
   setAccountData(account, "colt45skill", colt45) 
   setAccountData(account, "silencedskill", silenced) 
   setAccountData(account, "deagleskill", deagle) 
   setAccountData(account, "shotgunskill", shotgun) 
   setAccountData(account, "sawnoffskill", sawnoff) 
   setAccountData(account, "spas12skill", spas12) 
   setAccountData(account, "uziskill", uzi) 
   setAccountData(account, "mp5skill", mp5) 
   setAccountData(account, "ak47skill", ak47) 
   setAccountData(account, "m4skill", m4) 
   setAccountData(account, "sniperskill", sniper) 
  end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), savePlayerStats ) 
addEventHandler ( "onPlayerWasted", getRootElement(), savePlayerStats ) 

Link to comment
addEventHandler ("onPlayerLogin",root, 
function() 
loadPedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerQuit",root, 
function() 
savePedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerLogout",root, 
function(thePreviousAccount) 
savePedStats( thePreviousAccount ) 
end 
) 
function savePedStats( Acc) 
for i = 21 , 25 do 
setAccountData(Acc, "stat."..i , getPedStat(source,i)) 
end 
for i = 69 , 79 do 
setAccountData(Acc, "stat."..i , getPedStat(source,i)) 
end 
end 
function loadPedStats(Acc ) 
for i = 21 , 25 do 
setPedStat(source,i,getAccountData(Acc, "stat."..i)) 
end 
for i = 69 , 79 do 
setPedStat(source,i,getAccountData(Acc, "stat."..i)) 
end 
end 

Link to comment
addEventHandler ("onPlayerLogin",root, 
function() 
loadPedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerQuit",root, 
function() 
savePedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerLogout",root, 
function(thePreviousAccount) 
savePedStats( thePreviousAccount ) 
end 
) 
function savePedStats( Acc) 
for i = 21 , 25 do 
setAccountData(Acc, "stat."..i , getPedStat(source,i)) 
end 
for i = 69 , 79 do 
setAccountData(Acc, "stat."..i , getPedStat(source,i)) 
end 
end 
function loadPedStats(Acc ) 
for i = 21 , 25 do 
setPedStat(source,i,getAccountData(Acc, "stat."..i)) 
end 
for i = 69 , 79 do 
setPedStat(source,i,getAccountData(Acc, "stat."..i)) 
end 
end 

That wouldn't work, savePedStats and loadPedStats wern't defined at the time they were called. Therefore, savePedStats would return nil
function savePedStats( Acc) 
for i = 21 , 25 do 
setAccountData(Acc, "stat."..i , getPedStat(source,i)) 
end 
for i = 69 , 79 do 
setAccountData(Acc, "stat."..i , getPedStat(source,i)) 
end 
end 
function loadPedStats(Acc ) 
for i = 21 , 25 do 
setPedStat(source,i,getAccountData(Acc, "stat."..i)) 
end 
for i = 69 , 79 do 
setPedStat(source,i,getAccountData(Acc, "stat."..i)) 
end 
end 
addEventHandler ("onPlayerLogin",root, 
function() 
loadPedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerQuit",root, 
function() 
savePedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerWasted",root, 
function() 
loadPedStats(  getPlayerAccount(source)) 
end 
) 
addEventHandler ("onPlayerLogout",root, 
function(thePreviousAccount) 
savePedStats( thePreviousAccount ) 
end 
) 
  

Link to comment
That wouldn't work, savePedStats and loadPedStats wern't defined at the time they were called. Therefore, savePedStats would return nil

Wrong, they are defined by the time they are called. No matter where you put the function, it is called when it is called.

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...