Hi! i get this code from this forum, but i need some help..
the problem is when i start the resource and a player is in a team the script doesnt get the player team and set the blip color according to the team color and when the player is moved to another team it doesnt get the color of the newer team only when he die, and he reconnects it doesnt get the color of the team and set the blip color
addEventHandler ( "onClientResourceStart", getRootElement(getThisResource()),
function( resource, source )
for id, source in ipairs( getElementsByType ( "source" ) ) do
if getPlayerTeam(source) ~= nil then
local r, g, b = getTeamColor(getPlayerTeam(source))
createBlipAttachedTo ( source, 0, 2, r,g,b )
else
if ( players[source] ) then
createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] )
else
createBlipAttachedTo ( source, 0, 2, color[1], color[2], color[3] )
end
end
end
end)
addEventHandler ( "onPlayerSpawn",getRootElement(),
function( spawnpoint )
if getPlayerTeam(source) ~= nil then
local r, g, b = getTeamColor(getPlayerTeam(source))
createBlipAttachedTo ( source, 0, 2, r,g,b )
else
if ( players[source] ) then
createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] )
else
createBlipAttachedTo ( source, 0, 2, color[1], color[2], color[3] )
end
end
end)
playerTimer = {}
addEventHandler('onResourceStart', resourceRoot,
function()
for i, v in ipairs(getElementsByType('player')) do
playerTimer[v] = setTimer(updatePlayerBlip, 50, 0)
end
end
)
addEventHandler('onPlayerSpawn', root,
function()
playerTimer[source] = setTimer(updatePlayerBlip, 50, 0, source)
end
)
function getPlayerBlip(src)
if src then
local attached = getAttachedElements ( src )
if ( attached ) then
for k,element in ipairs(attached) do
if getElementType ( element ) == "blip" then
return element
end
end
end
end
end
function updatePlayerBlip(src)
if src then
if not isPedDead(src) then
if getPlayerBlip(src) then
local r, g, b = getPlayerNametagColor(src)
setBlipColor(getPlayerBlip(src), r, g, b, 255)
end
end
end
end
addEventHandler('onPlayerQuit', root,
function()
if isTimer(playerTimer[source]) then
killTimer(playerTimer[source])
end
end
)
addEventHandler('onPlayerWasted', root,
function()
if isTimer(playerTimer[source]) then
killTimer(playerTimer[source])
end
end
)