local pBlips = { }
addEventHandler("onResourceStart", resourceRoot,
function()
for index, player in ipairs(getElementsByType("player")) do
addTeamBlip(player)
end
end
)
function addTeamBlip(player)
if ( pBlips[player] ) then return false end -- Adding a prevention of duplicate blips
local theGang = getElementData ( player, "gang" )
if ( theGang and theGang ~= "None" ) then
local r, g, b = getPlayerNametagColor( player )
local theBlip = createBlipAttachedTo( player, 0, 2, r, g, b )
-- Change visibility to only the team members
setElementVisibleTo( theBlip, root, false )
for index, value in ipairs ( getPlayersByGang ( theGang ) ) do -- THIS
setElementVisibleTo( theBlip, value, true )
end
pBlips[player] = theBlip
end
end
function destroyBlip(element)
local theElement = source or element
if ( theElement ) then
destroyElement(pBlips[theElement])
pBlips[theElement] = nil -- Just in-case...
end
end
-- Events
addEventHandler ( "onPlayerSpawn", root, addTeamBlip ) -- onPlayerSpawn will now add a teamBlip
addEventHandler ( "onPlayerQuit", root, destroyBlip )
addEventHandler ( "onPlayerWasted", root, destroyBlip )
function getPlayersByGang ( gang )
local players = { }
for _, player in ipairs ( getElementsByType ( "player" ) ) do
if ( getElementData ( player, "gang" ) == gang ) then
table.insert ( players, player )
end
end
return players
end