Jump to content

Get Players On Team


PoliceSA

Recommended Posts

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

Link to comment

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 

Link to comment
  
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
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...