Jump to content

problem with onPlayerTeamChanged


Recommended Posts

Hello community

Im here to ask a help regarding playerblips.

Okay here, I tell you what's the point. I want to make blips that will change after player changes team, ex from criminal to civillian but this code doesnt work at all, I have to restart it then the color will change

local blip = { } 
addEventHandler ( "onPlayerSpawn", root, function ( ) 
    if ( not isElement ( blip [ source ] ) ) then 
        blip [ source ] = createBlipAttachedTo ( source ) 
    end 
    local theTeam = getPlayerTeam ( source ) 
    if ( not theTeam ) then 
        return 
    end 
    if ( getTeamName ( theTeam ) == "Police" ) then 
        return 
    end 
    local r, g, b = getTeamColor ( theTeam ) 
    setPlayerNametagColor ( source, r, g, b ) 
    setBlipColor ( blip [ source ], r, g, b, 255 ) 
end ) 
    
addEventHandler ( "onResourceStart", resourceRoot, function () 
    for k, v in ipairs ( getElementsByType("player") ) do 
        if ( not isElement ( blip [ v ] ) ) then 
            blip [ v ] = createBlipAttachedTo ( v ) 
        end 
        local theTeam = getPlayerTeam ( v ) 
        if (not theTeam) then 
            return 
        end   
        if ( getTeamName ( theTeam ) == "Police" ) then 
            return 
        end 
        local r, g, b = getTeamColor ( theTeam ) 
        setPlayerNametagColor ( v, r, g, b ) 
        setBlipColor ( blip [ v ], r, g, b, 255 ) 
    end 
end )   
local blip = { } 
  
addEvent ( "onPlayerTeamChanged", true ) 
addEventHandler ( "onPlayerTeamChanged", root, 
    function ( theTeam ) 
        if ( not theTeam ) then 
            return 
        end 
  
        if ( not isElement ( blip [ source ] ) ) then 
            blip [ source ] = createBlipAttachedTo ( source ) 
        end 
        local theTeam = getTeamName(source) 
        local r, g, b = getTeamColor ( theTeam ) 
        setPlayerNametagColor ( source, r, g, b ) 
        setBlipColor ( blip [ source ], r, g, b, 255 ) 
    end 
) 
function destroyPlayerBlip( ) 
    if isElement ( blip [ source ] ) then 
        destroyElement ( blip [ source ] ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, destroyPlayerBlip ) 
addEventHandler ( "onPlayerWasted", root, destroyPlayerBlip ) 
  
setTimer ( function ( ) 
    for i,v in ipairs ( getElementsByType ( "player" ) ) do 
    if isElement ( blip [ sourc ] ) then 
            destroyElement ( blip [ v ] ) 
        end 
        local theTeam = getPlayerTeam ( v ) 
        if (not theTeam) then 
            return 
        end   
        if ( getTeamName ( theTeam ) == "Police" ) then 
            return 
        end 
        local r, g, b = getTeamColor ( theTeam ) 
        setPlayerNametagColor ( source, r, g, b ) 
        setBlipColor ( blip [ source ], r, g, b, 255 ) 
    end 
    end, 6000, 0 ) 
  

and there is no errors but It got warning

v3us.png

here guys Thank you

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