Jump to content

pls Help me getPlayerTeam


XeRo

Recommended Posts

Posted
        PlayerClan = guiCreateLabel(6, 96, 170, 24, "Clan:", false, UserPanel) 
        guiSetFont(PlayerClan, "default-bold-small") 

     addEventHandler("onClientResourceStart",getRootElement(), 
 function() 
  if getElementsByType("team") then 
                  guiSetText(PlayerClan,"Clan:",getTeamName ( team )) 
                  end 
              end 
                  ) 

Destruction Derby UserPanel%15

Posted

getElementsByType returns a table, therefore you need to loop through them. You'll want to read about for loops.

Here's 2 examples on how you can do it;

local allTeams = getElementsByType("team") 
if(allTeams) then -- If allTeams is not false or nil, then continue 
    for key, value in ipairs(allTeams) do 
        outputChatBox("Team #"..tostring(key)..": "..tostring(value)) -- Will output like this; "Team #1: BlueTeam", "Team #2: RedTeam" 
    end 
else 
    outputChatBox("Failed to retrieve teams!") -- If allTeams returned false or nil, this will be output. 
end 
  
-- Alternatively you can write it like this, but it's generally better to use if statements to catch errors and let the user know what went wrong. 
for key, value in ipairs(getElementsByType("team")) do 
    local teamName = getTeamName(value) -- This will get the team name for each team in the table. 
    outputChatBox(tostring(teamName)) -- You can use tostring in case it would return false or nil. 
end 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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