Jump to content

Get Players On Team


PoliceSA

Recommended Posts

Posted

Yes, first of all you need to get all player elements and then check their team. After that, add them to a table. For example;

-- Define the table. 
local mtaTeamPlayers = {}; 
  
-- First of all, fetch all current player elements 
local allPlayers = getElementsByType("player"); 
-- Then loop through all players and check their team name 
for k, v in ipairs(allPlayers) do 
    if(getTeamName(getPlayerTeam(v)) == "MTA") then 
        -- If their team name matches the one you want, get their player name and store it in a local variable 
        local playerName = getPlayerName(v); 
        -- Insert their name into our previously defined table 
        table.insert(mtaTeamPlayers, #mtaTeamPlayers, playerName); 
    end 
end 

Of course that's just an example. You'll have to make code which updates the table whenever a player join and quits. You'll also have to loop through the table to draw their names using dxDrawText.

Edit:

Or use the function manawydan suggested :P

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.

Posted

Aahah thx :D but what should I put in the client? Cuz i'm not good to script

i should use on server like that?

for k, v in ipairs(allPlayers) do 
    if(getTeamName(getPlayerTeam(v)) == "team[1]") then 
        local playerName = getPlayerName(v) 
        table.insert(mtaTeamPlayers, #mtaTeamPlayers, playerName); 
        triggerClientEvent (source, "TriggerToClient", g_Root, mtaTeamPlayers) 
              end 
           end 

Posted

one example,

addEventHandler("onClientRender",root, 
function() 
local team = getPlayerTeam(localPlayer) 
if not(team)then return end 
local players = getPlayersInTeam(team) 
for k,v in ipairs(players)do 
-- you dxdraw here 
end 
end) 
  

560x95_FFFFFF_09FF00_050505_000000.png

"Querer não é poder, mas tentar é avançar"!

Posted
  
.... 
local team = getPlayerTeam(localPlayer) 
if not(team)then return end 
local players = getPlayersInTeam(team) 
for k,v in ipairs(players)do 
dxDrawText (whatishouldputhere?, x + 60, 420, x, y, tocolor( 255, 255, 255 ), 1, "default-bold" ) 
end 

Posted (edited)
  
addEventHandler("onClientRender",root, 
function () 
local team = getPlayerTeam(localPlayer) 
if not(team)then return end 
local players = getPlayersInTeam(team) 
for _,v in ipairs(players)do 
dxDrawText (getPlayerName(v), x + 60, 420, x, y, tocolor( 255, 255, 255 ), 1, "default-bold" ) 
end 

Edited by Guest

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

Like That?

  
.... 
for id,v in ipairs(players)do 
         dxDrawText(getPlayerName(v), x + 60,420*id, x, screenHeight, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "top", false, false, true, true, false) 

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