Jump to content

[Question] Account data and teams


kieran

Recommended Posts

Okay, straight to the point, I am trying to edit the "save_system" script on the MTA resources hoping it will allow me to get a better understanding of setting account data etc, but I am unsure if I'm doing it right, code is below...  Not posting whole script, that is a lot to read :P changed nothing but adding lines below.

function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin)
  if  not (isGuestAccount (getPlayerAccount (source))) then
    local accountData = getAccountData (theCurrentAccount, "funmodev2-money")
    if (accountData) then
    local playerTeam = getAccountData (theCurrentAccount, "funmodev2-Team")
      	  setPlayerTeam ( source, playerTeam )
          end   
  end
end
addEventHandler ("onPlayerLogin", getRootElement(), playerLogin)


function onQuit (quitType, reason, responsibleElement)
  if not (isGuestAccount (getPlayerAccount (source))) then
    account = getPlayerAccount (source)
    if (account) then
      	  setAccountData (account, "funmodev2-playerTeam", getPlayerTeam (source))
          end
  end
end
addEventHandler ("onPlayerQuit", getRootElement(), onQuit)

--full thing is around 150 lines, rest is just weapons, armor, money etc which works perfectly.

No errors, debug 3 shows nothing, team is called Admin, could there be an ACL group conflict?

 

P.S. Very sorry for spam, submit was not loading :/ 

Edited by kieran
Link to comment
35 minutes ago, MIKI785 said:

It really doesn't show any errors/warnings? Because you can't possibly store elements (ie. teams) in account data. However, you could store the team name and then use getTeamFromName to set the team.

(facepalm) I forgot only certain things can be stored as data xD thanks.

Link to comment

@MIKI785 Attempted to make it again, I don't think it's quite right, won't work... :/ 

--Team save
function onPlayQuit ( )
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
	      local playerTeam = getPlayerTeam(source)
			if (playerTeam) then
			
            local currentTeam = getTeamFromName ( "playerTeam" ) 
            setAccountData ( playeraccount, "TeamLog", currentTeam )
      end
end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayQuit )


--Team load
function onPlayLogin (_, playeraccount )
      if ( playeraccount ) then
            local LoadTeam = getAccountData ( playeraccount, "TeamLog" )

            if ( LoadTeam ) then
                  setPlayerTeam ( source, LoadTeam )
            end
      end
end
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayLogin )

 

Link to comment
1 hour ago, pa3ck said:

getTeamFromName check the wiki, that will explain your problem also take a look at getTeamName

I got as far as saving the string, but I just have an issue with actually giving the team now, the error is: WARNING: Teams\team.lua:22: Bad argument @ 'setPlayerTeam' [Expected team at argument 2, got string 'TestTeam']

 

server script

--Team save
function onPlayQuit ( )
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in
	      local myTeam = getPlayerTeam ( source )
			if (myTeam) then
			
            local currentTeam = getTeamName ( myTeam ) 
            setAccountData ( playeraccount, "TeamLog", currentTeam ) -- save it in his account
      end
end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayQuit )


--Team load
function onPlayLogin (_, playeraccount )
      if ( playeraccount ) then
            local LoadTeam = getAccountData ( playeraccount, "TeamLog" )

            if ( LoadTeam ) then
                  setPlayerTeam ( source, LoadTeam )
            end
      end
end
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayLogin )

I've tried using getTeamFromName but it doesn't work. -_- 

 

EDIT

Okay, I have got it working! :D I feel so dumb, it got the string, so it got the team name, so I just changed this(For anyone that needs this script):

                  teamLoad = getTeamFromName ( LoadTeam ) 

                  setPlayerTeam ( source, LoadTeam )

 

Thank you so much for all your help :) I can finally work on the job scripts now! haha

Edited by kieran
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...