Jump to content

need help with getAccountData


Saml1er

Recommended Posts

Hello, I want to learn more about getElementData and so on after spending 5 hours on wiki I made some code but it's not working the way I want it to work. I want it save the player's serial,account info whenever he leaves and joins ( for everyone ) and when I execute this command "/srl" and I want to get the serial and previous account, sadly I can't get the previous account + it's giving me the account details of player who logged in. :|

function onPlayerQuit ( previous_Account, Current_Account ) 
      local playerAccount = getAccountData (source) 
      if (playerAccount) then 
      local playerserial = getPlayerSerial ( source ) 
            local playername = getPlayerName ( source ) 
            local previous = getAccountName ( previous_Account ) 
            local current = getAccountName ( Current_Account ) 
            setAccountData ( playerAccount, "piraterpg.current", current ) 
            setAccountData ( playerAccount, "piraterpg.previous", previous ) 
            setAccountData ( playerAccount, "piraterpg.serial", playerserial ) 
      end 
end 
  
function onPlayerLogin ( ) 
 local playerAccount = getAccountData (source) 
 if (playerAccount) then 
 getAccountData ( playerAccount, "piraterpg.serial" ) 
 getAccountData ( playerAccount, "piraterpg.current" ) 
 getAccountData ( playerAccount, "piraterpg.previous" ) 
end 
end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 
  
addCommandHandler ("srl", 
function ( ) 
local playerAccount = getAccountData(source) 
if ( playerAccount ) then 
  local serialss = getAccountData ( playerAccount, "piraterpg.serial" ) 
  local currents = getAccountData ( playerAccount, "piraterpg.current" ) 
  local previous = getAccountData ( playerAccount, "piraterpg.previous" ) 
  outputChatBox ( "* "..playeraccount.." found on serial: "..serialss..": "..currents..", "..previous, source, 255, 255, 0, true ) 
end 
end 
) 

Edited by Guest
Link to comment

The code is a total disaster.

addEventHandler("onPlayerQuit", root, 
 function() 
  local account = getPlayerAccount(source) 
  if (not account) then return end 
  setAccountData(account, "player.lastSerial", getPlayerSerial(source)) 
  setAccountData(account, "player.lastNick", getPlayerName(source)) 
 end 
) 

Whenever you want the last serial or nick, use getAccountData() to fetch it.

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