Jump to content

Save team help again -.-


Xeno

Recommended Posts

function setTeam() 
local account = getPlayerAccount(source) 
local team = getAccountData (account, "team") 
if (team) and getTeamFromName(team) then 
      setPlayerTeam(source, getTeamFromName(team)) 
     end 
end 
addEventHandler("onPlayerLogin",root,setTeam) 
  
function save(player) 
 local team = getPlayerTeam(player) 
local account = getPlayerAccount(player) 
if (team) and not isGuestAccount(account) then 
setAccountData(account, "team", getTeamName(team)) 
 end 
    end 
addEventHandler("onPlayerQuit", getRootElement(), save) 

I used this script to save teams, and I have no idea why its not working, can someone help me please? I get no errors.

Link to comment
function setTeam() 
local account = getPlayerAccount(source) 
local team = getAccountData (account, "team") 
if (team) and getTeamFromName(team) then 
      setPlayerTeam(source, getTeamFromName(team)) 
     end 
end 
addEventHandler("onPlayerLogin",root,setTeam) 
  
function save() 
 local team = getPlayerTeam(source) 
local account = getPlayerAccount(source) 
if (team) and not isGuestAccount(account) then 
setAccountData(account, "team", getTeamName(team)) 
 end 
    end 
addEventHandler("onPlayerQuit", getRootElement(), save) 

Make sure you read the arguments of events, onPlayerQuit does not have a player argument, the player is source.

Link to comment
function setTeam() 
local account = getPlayerAccount(source) 
local team = getAccountData (account, "team") 
if (team) and getTeamFromName(team) then 
      setPlayerTeam(source, getTeamFromName(team)) 
     end 
end 
addEventHandler("onPlayerLogin",root,setTeam) 
  
function save() 
 local team = getPlayerTeam(source) 
local account = getPlayerAccount(source) 
if (team) and not isGuestAccount(account) then 
setAccountData(account, "team", getTeamName(team)) 
 end 
    end 
addEventHandler("onPlayerQuit", getRootElement(), save) 

Make sure you read the arguments of events, onPlayerQuit does not have a player argument, the player is source.

Ill test that nao :)

Link to comment
And how would I save skin? the same but change around the functions

See this example. This is one way of saving the skin, for the next time the player connects.

  
function onMapLoad () 
    -- create our table, if it doesn't already exist 
    executeSQLCreateTable ( "players", "clothes_head_texture TEXT, clothes_head_model TEXT, player TEXT" ) 
end 
addEventHandler ( "onGamemodeMapStart", getRootElement(), onMapLoad ) 
  
function addInfoToSQL( theSpawnpoint, theTeam )  
    sourcename = getPlayerName ( source )   -- get the player's name 
  
    -- try to retrieve the player data from the db 
    result = executeSQLSelect ( "players", "player", "player = '" .. sourcename .. "'" ) 
    if ( result == false ) then -- see if any data was found at all 
        outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) 
        executeSQLInsert ( "players", "'none', 'none', '" .. sourcename .. "'" ) 
    else 
        outputChatBox ( "Welcome back " .. sourcename .. "!", source ) 
        executeSQLUpdate ( "players", "clothes_head_texture = 'hairgreen', clothes_head_model = 'somehead'", 
        "player = '" .. sourcename .. "'" ) 
    end  
  
    -- get the clothes data for the player 
    result = executeSQLSelect ( "players", "clothes_head_texture, clothes_head_model", "player = '" .. sourcename .. "'" ) 
    outputChatBox ( "Your head texture is " .. result[1][1] ) 
    outputChatBox ( "Your head model is " .. result[1][2] )  
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), addInfoToSQL ) 
  

https://wiki.multitheftauto.com/wiki/ExecuteSQLUpdate

And for getting the players current skin use.

https://wiki.multitheftauto.com/wiki/GetElementModel

Link to comment
And how would I save skin? the same but change around the functions

See this example. This is one way of saving the skin, for the next time the player connects.

  
function onMapLoad () 
    -- create our table, if it doesn't already exist 
    executeSQLCreateTable ( "players", "clothes_head_texture TEXT, clothes_head_model TEXT, player TEXT" ) 
end 
addEventHandler ( "onGamemodeMapStart", getRootElement(), onMapLoad ) 
  
function addInfoToSQL( theSpawnpoint, theTeam )  
    sourcename = getPlayerName ( source )   -- get the player's name 
  
    -- try to retrieve the player data from the db 
    result = executeSQLSelect ( "players", "player", "player = '" .. sourcename .. "'" ) 
    if ( result == false ) then -- see if any data was found at all 
        outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) 
        executeSQLInsert ( "players", "'none', 'none', '" .. sourcename .. "'" ) 
    else 
        outputChatBox ( "Welcome back " .. sourcename .. "!", source ) 
        executeSQLUpdate ( "players", "clothes_head_texture = 'hairgreen', clothes_head_model = 'somehead'", 
        "player = '" .. sourcename .. "'" ) 
    end  
  
    -- get the clothes data for the player 
    result = executeSQLSelect ( "players", "clothes_head_texture, clothes_head_model", "player = '" .. sourcename .. "'" ) 
    outputChatBox ( "Your head texture is " .. result[1][1] ) 
    outputChatBox ( "Your head model is " .. result[1][2] )  
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), addInfoToSQL ) 
  

https://wiki.multitheftauto.com/wiki/ExecuteSQLUpdate

And for getting the players current skin use.

https://wiki.multitheftauto.com/wiki/GetElementModel

I swear you need a special server to use SQL? :S

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