Jump to content

getPlayerTeam


Klesh

Recommended Posts

Hello Community, i've try to do a script, this script it saves the team, when you quit and login, you are in the same team you left when you quit the game, so here is the code:

function onPlayerQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
            local playerteam = getPlayerTeam ( source ) 
            setAccountData ( playeraccount, "xsrpg.team", playerteam ) 
    end 
end 
  
function onPlayerLogin (_, playeraccount ) 
    if ( playeraccount ) then 
            local playerteam = getAccountData ( playeraccount, "xsrpg.team" ) 
            if ( playerteam ) then  
                    setPlayerTeam ( source, playermoney ) 
            end 
    end 
end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHander ( "onPlayerLogin" getRootElement ( ), onPlayerLogin ) 
     

The team not saved.

Note: The team is created by admin with the panel!

Link to comment
function onPlayerQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
        local playerTeam = getPlayerTeam ( source ) 
        if playerTeam then 
            local playerTeam = getTeamName(playerTeam) 
            setAccountData ( playeraccount, "xsrpg.team", playerTeam ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
  
function onPlayerLogin (_, playeraccount ) 
    if ( playeraccount ) then 
        local playerTeam = getAccountData ( playeraccount, "xsrpg.team" ) 
            if ( playerTeam ) then 
            setPlayerTeam ( source, getTeamFromName(playerTeam) ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin" getRootElement ( ), onPlayerLogin ) 

Edited by Guest
Link to comment
addEventHandler ( "onPlayerLogin" getRootElement ( ), onPlayerLogin ) 

correct

addEventHandler ( "onPlayerLogin", getRootElement(), onPlayerLogin ) 

also you have two local playerTeam idk if this make problem or not but change it better -_-

function onPlayerQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
        local playerTeam = getPlayerTeam ( source ) 
        if playerTeam then 
            local playerTeamName = getTeamName(playerTeam) 
            setAccountData ( playeraccount, "xsrpg.team", playerTeamName ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit",getRootElement (), onPlayerQuit ) 
  
function onPlayerLogin (_, playeraccount ) 
    if ( playeraccount ) then 
        local playerTeam = getAccountData ( playeraccount, "xsrpg.team" ) 
            if ( playerTeam ) then 
            setPlayerTeam ( source, getTeamFromName(playerTeam) ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), onPlayerLogin ) 

Link to comment

No it doesn't.

Btw you can improve scripts using some less lines for the variable settings, or making their names smaller:

function onPlayerQuit ( ) 
    local acc = getPlayerAccount ( source ) 
    if ( acc ) and not isGuestAccount ( acc ) then 
        if getPlayerTeam ( source ) then 
            setAccountData ( acc, "xsrpg.team", getTeamName ( playerTeam ) ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit",getRootElement (), onPlayerQuit ) 
  
function onPlayerLogin (_, cc ) 
    if ( acc ) then 
        local pTeam = getAccountData ( acc, "xsrpg.team" ) 
            if ( pTeam ) then 
              setPlayerTeam ( source, getTeamFromName ( pTeam ) ) 
            end 
    end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), onPlayerLogin ) 

Link to comment

you forgot thing

function onPlayerLogin (_, cc ) 

function onPlayerLogin (_, acc ) 

also this will be less

function onPlayerQuit ( ) 
    local acc = getPlayerAccount ( source ) 
    if ( acc ) and not isGuestAccount ( acc ) then 
        if getPlayerTeam ( source ) then 
            setAccountData ( acc, "xsrpg.team", getTeamName ( playerTeam ) ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit",root, onPlayerQuit ) 
  
function onPlayerLogin (_, acc ) 
    if ( acc ) then 
        local pTeam = getAccountData ( acc, "xsrpg.team" ) 
            if ( pTeam ) then 
              setPlayerTeam ( source, getTeamFromName ( pTeam ) ) 
            end 
    end 
end 
addEventHandler ( "onPlayerLogin",root, onPlayerLogin ) 

Link to comment

There's something with the code I gave LOL

Also, why to use parenthesis?

function onPlayerQuit ( ) 
    local acc = getPlayerAccount ( source ) 
    if acc and not isGuestAccount ( acc ) then 
        if getPlayerTeam ( source ) then 
            setAccountData ( acc, "xsrpg.team", getTeamName ( getPlayerTeam ( source ) ) ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 
  
function onPlayerLogin ( _, acc ) 
    if acc then --Is this necessary in fact? 
        local pTeam = getAccountData ( acc, "xsrpg.team" ) 
        if pTeam then 
           setPlayerTeam ( source, getTeamFromName ( pTeam ) ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin",root, onPlayerLogin ) 

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