Jump to content

[Solved]Problem save team


abu5lf

Recommended Posts

This script is to save the police team but does not work

I tried a lot but my attempts failed is

function onLogin () 
    local uAccount = getPlayerAccount ( source ) 
    local sTeamName = getAccountData ( uAccount, 'POLICE' ) 
    if uAccount and not isGuestAccount ( uAccount ) and sTeamName then 
    setPlayerTeam ( source, getTeamFromName( sTeamName ) ) 
    setElementModel (source, 280) 
    spawnPlayer ( source, 2292.0925292969, 2451.7045898438, 10.8203125, 0, 280, 0, 0 ) 
    else 
    setPlayerTeam ( source, nil ) 
    end 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function saveData () 
    local theAccount = getPlayerAccount(source) 
    local team = getPlayerTeam(source) 
    local uTeam = getTeamName ( team ) 
    if theAccount and not isGuestAccount(theAccount) and team == getTeamFromName("Police") then 
    if uTeam then  
    setAccountData (theAccount, "POLICE", uTeam ) 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", root, saveData) 
addEventHandler ("onPlayerLogout", root, saveData) 

Edited by Guest
Link to comment

Try this:

function onLogin ( _, account ) 
    local sTeamName = getAccountData ( account, 'POLICE' ) 
    if ( account and not isGuestAccount ( account ) and sTeamName ) then 
        setPlayerTeam ( source, getTeamFromName ( sTeamName ) ) 
        setElementModel ( source, 280 ) 
        spawnPlayer ( source, 2292.0925292969, 2451.7045898438, 10.8203125, 0, 280, 0, 0 ) 
    else 
        setPlayerTeam ( source, nil ) 
    end 
end 
addEventHandler ( "onPlayerLogin", root, onLogin ) 
  
function saveData ( account ) 
    local account = type ( account ) == "userdata" and account or getPlayerAccount ( source ) 
    local team = getPlayerTeam ( source ) 
    local teamName = team and getTeamName ( team ) or "" 
    if ( account and not isGuestAccount ( account ) and teamName == "Police" ) then 
        setAccountData ( account, "POLICE", teamName ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, saveData ) 
addEventHandler ( "onPlayerLogout", root, saveData ) 

Link to comment
Try this:
function onLogin ( _, account ) 
    local sTeamName = getAccountData ( account, 'POLICE' ) 
    if ( account and not isGuestAccount ( account ) and sTeamName ) then 
        setPlayerTeam ( source, getTeamFromName ( sTeamName ) ) 
        setElementModel ( source, 280 ) 
        spawnPlayer ( source, 2292.0925292969, 2451.7045898438, 10.8203125, 0, 280, 0, 0 ) 
    else 
        setPlayerTeam ( source, nil ) 
    end 
end 
addEventHandler ( "onPlayerLogin", root, onLogin ) 
  
function saveData ( account ) 
    local account = type ( account ) == "userdata" and account or getPlayerAccount ( source ) 
    local team = getPlayerTeam ( source ) 
    local teamName = team and getTeamName ( team ) or "" 
    if ( account and not isGuestAccount ( account ) and teamName == "Police" ) then 
        setAccountData ( account, "POLICE", teamName ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, saveData ) 
addEventHandler ( "onPlayerLogout", root, saveData ) 

Thank you

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