Jump to content

Current Team - label dont update


Recommended Posts

local guiTextLabel = nil 
local guiTextLabelTeamName = nil 
local guiTextLabelText = nil 
  
function showPlayerTheirTeam(player, text, r, g, b) 
    if ( player == getLocalPlayer() ) then 
        if ( guiTextLabel ) then 
            guiSetText ( guiTextLabelTeamName, text ) 
            guiSetColor ( guiTextLabelTeamName, r, g, b ) 
        else 
            guiTextLabel = guiCreateLabel( 0.01, 0.20, 0.8203, 0.5, "Current Team: ", true ) 
            if ( guiTextLabel ) then 
                local guiLength = guiLabelGetTextExtent ( guiTextLabel ) 
                local screenX, screenY = guiGetScreenSize() 
                guiLength = tonumber(guiLength) / screenX 
                local guiTextLabelTeamName = guiCreateLabel( tonumber(guiLength) + 0.01, 0.20, 1, 0.5, text, true ) 
                if ( guiTextLabelTeamName ) then 
                    guiLabelSetColor ( guiTextLabelTeamName, tonumber(r), tonumber(g), tonumber(b) ) 
                end 
            end 
        end 
    end 
end 
  
function onClientPlayerSpawn() 
    --outputChatBox ( "Ive Loaded, contacting server!" ) 
    triggerServerEvent ( "Event_clientScriptLoaded", getRootElement(), getLocalPlayer() ) 
end 
  
addEvent ( "Event_showPlayerTheirTeam", true ) 
addEventHandler ( "Event_showPlayerTheirTeam", getRootElement(), showPlayerTheirTeam ) 
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), onClientPlayerSpawn ) 

Problem is, when player spawn then Label shows Current Team, but when map changes Label shows the old Team from previous map.

You can make a reconnect, for update Label (but it is inconvenient).

Need to finish script

Update Label

whit what functions?

add/remove function?

destroy element?

Link to comment

You can set a timer to check what is his current team or make custom events which would update that label when something happens (eg. player spawned, selected team, etc.)... You've got the event already (Event_showPlayerTheirTeam), just trigger that even when it's required to update the team name.

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