Jump to content

Getting all players in a team


Xeno

Recommended Posts

I have a problem with getting all the players in a team... Here is my code:

local team = getTeamFromName("Aliens")            
     local players = getPlayersInTeam (team)  
    dxDrawText ( "Team:",    175, screenHeight - 98, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
    dxDrawText ( "Team:"..players.."", 175, screenHeight - 100, screenWidth, screenHeight, tocolor ( 255, 0, 0, 255 ), 1, "pricedown" )  

The debug says:

Attempt to concentrate local "players" (a table value) 

I would appreciate if you helped me.

Link to comment

I guess you want to count the players, if so, use this:

     local team = getTeamFromName("Aliens")           
     local players = countPlayersInTeam(team) 
     dxDrawText ( "Team:",    175, screenHeight - 98, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
     dxDrawText ( "Team:".. tostring(players) .."", 175, screenHeight - 100, screenWidth, screenHeight, tocolor ( 255, 0, 0, 255 ), 1, "pricedown" ) 

Link to comment
local text="" 
local team = getTeamFromName("Aliens")           
     local players = getPlayersInTeam (team) 
    dxDrawText ( "Team:",    175, screenHeight - 98, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
for i,v in pairs (players) do  
text=text.." , "..getPlayerName(v) 
end 
  
    dxDrawText ( "Team:"..text, 175, screenHeight - 100, screenWidth, screenHeight, tocolor ( 255, 0, 0, 255 ), 1, "pricedown" ) 

Link to comment

Congradulations! Guru! :D

And ill test it again...

local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
  
  
function createText ( ) 
  local text="" 
local team = getTeamFromName("Aliens")           
     local players = getPlayersInTeam (team) 
    dxDrawText ( "Team:",    175, screenHeight - 98, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
for i,v in pairs (players) do 
text=text.." , "..getPlayerName(v) 
end 
  
     
  
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 
end 
  
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering) 

That is my full script

Link to comment

you forgot an "end"

local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
  
  
function createText ( ) 
  local text="" 
local team = getTeamFromName("Aliens")           
     local players = getPlayersInTeam (team) 
    dxDrawText ( "Team:",    175, screenHeight - 98, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
for i,v in pairs (players) do 
text=text.." , "..getPlayerName(v) 
end 
 end 
    
  
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 
end 
  
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering) 

Link to comment

More better and it should working:

local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
  
function createText ( ) 
    local team = getTeamFromName( "Aliens" )      
    if team then     
        dxDrawText ( "Team:\n"..table.concat( getPlayersInTeam ( team ),"\n" ), 175, screenHeight - 98, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" ) 
    end  
end 
addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 

Example draw:

Team:

Player1

Player2

...

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