Jump to content

Saving Teams?


FWCentral

Recommended Posts

Hey im trying to save player teams so when a player disconnects and reconnect they will be in the team.

Here is the functions i used:

  
local team = getAccountData (theCurrentAccount, "team") 
if (team) then 
setPlayerTeam(source, team) 
  
--and  
  
local team = getPlayerTeam(source) 
if (team) then 
setAccountData(account, "team", team) 
  

and it doesn't work, All the other things save using the same sort of way as above e.g position and sking esc but this wont :(

Link to comment
local team = getAccountData (theCurrentAccount, "team") 
if (team) then 
setPlayerTeam(source, getTeamFromName ( team )) 
  
--and 
  
local team = getPlayerTeam(source) 
if (team) then 
setAccountData(account, "team", getTeamName ( team )) 

Link to comment
funtion setTeam(player) 
local account = getPlayerAccount(player) 
local team = getAccountData (account, "team") 
if (team) then 
setPlayerTeam(player, team) 
 end 
    end 
addEventHandler("onPlayerJoin",root,setTeam) 
function save(player) 
 local team = getPlayerTeam(player) 
if (team) then 
setAccountData(account, "team", team) 
 end 
    end 
 addCommandHandler("saveteam",save) 

Edited by Guest
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(player) 
 local team = getPlayerTeam(player) 
local account = getPlayerAccount(player) 
if (team) and not isGuestAccount(account) then 
setAccountData(account, "team", getTeamName(team)) 
 end 
    end 
 addCommandHandler("saveteam",save) 

Try that, should work.

Link to comment

Didn't want to start a new topic so i decided to post here.

I got another problem, I want to set the players blip to the color of the players team so i tried editing the playerblips resource to do that but the problem is it just sets the players blip to red and i dno why here's the code:

  
-- needs configurable blip colors, and team support 
root = getRootElement () 
r, g, b = getTeamColor( getTeamFromName(getPlayerTeam( root )) ) -- i added this 
color = { r, g, b } -- changed this 
players = {} 
resourceRoot = getResourceRootElement ( getThisResource () ) 
  
function onResourceStart ( resource ) 
    for id, player in ipairs( getElementsByType ( "player" ) ) do 
        if ( players[player] ) then 
            createBlipAttachedTo ( player, 0, 2, color[r], color[g], color[b] ) 
        else 
            createBlipAttachedTo ( player, 0, 2, color[r], color[g], color[b] ) 
        end 
    end 
end 
  
function onPlayerSpawn ( spawnpoint ) 
    if ( players[source] ) then 
        createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] ) 
    else 
        createBlipAttachedTo ( source, 0, 2, color[r], color[g], color[b] ) --and this 
    end 
end 
  
function onPlayerQuit () 
    destroyBlipsAttachedTo ( source ) 
end 
  
function onPlayerWasted ( totalammo, killer, killerweapon ) 
    destroyBlipsAttachedTo ( source ) 
end 
  
function setBlipsColor ( source, commandName, r, g, b ) 
    if ( tonumber ( b ) ) then 
        color = { tonumber ( r ), tonumber ( g ), tonumber ( b ) } 
        for id, player in ipairs( getElementsByType ( "player" ) ) do 
            destroyBlipsAttachedTo ( player ) 
            if ( players[player] ) then 
                createBlipAttachedTo ( player, 0, 2, players[source][1], players[source][2], players[source][3] ) 
            else 
                createBlipAttachedTo ( player, 0, 2, color[r], color[g], color[b] ) -- and this 
            end 
        end 
    end 
end 
  
function setBlipColor ( source, commandName, r, g, b ) 
    if ( tonumber ( b ) ) then 
        destroyBlipsAttachedTo ( source ) 
        players[source] = { tonumber ( r ), tonumber ( g ), tonumber ( b ) } 
        createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] ) 
    end 
end 
  
addCommandHandler ( "setblipscolor", setBlipsColor ) 
addCommandHandler ( "setblipcolor", setBlipColor ) 
addEventHandler ( "onResourceStart", resourceRoot, onResourceStart ) 
addEventHandler ( "onPlayerSpawn", root, onPlayerSpawn ) 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 
addEventHandler ( "onPlayerWasted", root, onPlayerWasted ) 
  
function destroyBlipsAttachedTo(player) 
    local attached = getAttachedElements ( player ) 
    if ( attached ) then 
        for k,element in ipairs(attached) do 
            if getElementType ( element ) == "blip" then 
                destroyElement ( element ) 
            end 
        end 
    end 
end 
  

Link to comment

You're getting the team from root (which is not a player) and only once when the resource starts ..

Use it at resourcestart for every player and when a player spawns (revert your other changes)

function onResourceStart ( resource ) 
    for id, player in ipairs( getElementsByType ( "player" ) ) do 
        if ( players[player] ) then 
            createBlipAttachedTo ( player, 0, 2, players[source][1], players[source][2], players[source][3] ) 
        elseif getPlayerTeam(player) then 
            local r, g, b = getTeamColor(getPlayerTeam(player)) 
            createBlipAttachedTo ( player, 0, 2, r, g, b ) 
        else 
            createBlipAttachedTo ( player, 0, 2, color[1], color[2], color[3] ) 
        end 
    end 
end 
  
function onPlayerSpawn ( spawnpoint ) 
    if ( players[source] ) then 
        createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] ) 
    elseif getPlayerTeam(player) then 
        local r, g, b = getTeamColor(getPlayerTeam(player)) 
        createBlipAttachedTo ( player, 0, 2, r, g, b ) 
    else 
        createBlipAttachedTo ( source, 0, 2, color[1], color[2], color[3] ) 
    end 
end 

Link to comment

Hey thanks for the reply SDK i did post back earlier but wasnt logged in again :P the script you posted kinda works, when resource starts the blip is set the right color but when the player respawns his color goes black the color[1] [2] [3] is 0 0 0 so this is why it went black but yet i was still in a team so it should be the team color :(

Link to comment

One more quick question please, Im creating mechanic job and i want to create a blip attached to vehicles after 20 seconds of them leaving it but i dont know how i can get the players vehicle.

  
function abandonveh() 
        local veh = ?? 
        createBlipAttachedTo(veh, 55, getTeamFromName("Mechanic")) 
end 
     
function startvehtime() 
setTimer(abandonveh, 20000, 1) 
end 
addEventHandler ( "onVehicleExit", getRootElement(), startvehtime ) 
  
  

Link to comment

Simple, 'source' is the element of the vehicle the player just exit.

function abandonveh(veh) 
        createBlipAttachedTo(veh, 55, getTeamFromName("Mechanic")) 
end 
    
function startvehtime() 
setTimer(abandonveh, 20000, 1, source) 
end 
addEventHandler ( "onVehicleExit", getRootElement(), startvehtime ) 

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