Jump to content

Saving Teams?


FWCentral

Recommended Posts

Posted

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 :(

Posted
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 )) 

Posted (edited)
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
Posted

bandi, his problem isn't that, he already did this, and the code he posted is just the functions he used.

As he said.

I faced problems before with saving the team, but when I used names, it got solved.

Posted

yes i think your problem was on saving team onPlayerQuit for my autoteam i use onPlayerQuit getTeam to check the player's in that team to delet team or not and it returns BadArgument getPlayerTeam

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

Posted

Hey sorry i did send a reply before saying thanks JR10, I didn't notice i wasn't logged in :P anyways it works now it was the name in the saving of the team that was the error.

Posted

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 
  

Posted

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 

Posted

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 :(

Posted

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 ) 
  
  

Posted

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 ) 

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