roaddog Posted May 10, 2014 Share Posted May 10, 2014 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 ) and there is no errors but It got warning here guys Thank you Link to comment
justn Posted May 10, 2014 Share Posted May 10, 2014 I already have a code for this, so I will just give it to you. local blipTable = {} local blipFixTimer addEventHandler("onResourceStart",resourceRoot, function() local players = getElementsByType("player") for i=1,#players do local player = players[i] local playerTeam = getPlayerTeam( player ) if playerTeam and not isPedDead(player) then local r, g, b = getTeamColor ( playerTeam ) blipTable[player] = createBlipAttachedTo ( player, 0, 2, r, g, b ) end end blipFixTimer = setTimer(function() local players = getElementsByType("player") for i=1,#players do local player = players[i] local playerTeam = getPlayerTeam( player ) local oldBlip = blipTable[player] if playerTeam and not isPedDead(player) then local r, g, b = getTeamColor ( playerTeam ) if not isElement(oldBlip) then blipTable[player] = createBlipAttachedTo ( player, 0, 2, r, g, b ) else local r2,g2,b2 = getBlipColor ( oldBlip ) if r ~= r2 or g ~= g2 or b ~= b2 then destroyElement(oldBlip) blipTable[player]= createBlipAttachedTo ( player, 0, 2, r, g, b ) end end elseif oldBlip and isElement(oldBlip) then destroyElement(oldBlip) blipTable[player]= nil end end end,1000,0) end) addEventHandler("onPlayerSpawn",root, function() local oldBlip = blipTable[source] if isElement(oldBlip) then destroyElement(oldBlip) blipTable[source] = nil end local playerTeam = getPlayerTeam(source ) if playerTeam then local r, g, b = getTeamColor ( playerTeam ) blipTable[source] = createBlipAttachedTo ( source, 0, 2, r, g, b ) end end) addEventHandler("onPlayerWasted",root, function() local oldBlip = blipTable[source] if isElement(oldBlip) then destroyElement(oldBlip) blipTable[source] = nil end end) addEventHandler ( "onPlayerQuit", root, function() local oldBlip = blipTable[source] if isElement(oldBlip) then destroyElement(oldBlip) blipTable[source] = nil end end) Link to comment
cheez3d Posted May 10, 2014 Share Posted May 10, 2014 addEvent("onPlayerTeamChange"); local _setPlayerTeam = setPlayerTeam; setPlayerTeam = function(player,team) triggerEvent("onPlayerTeamChange",player,getPlayerTeam(player),team); return _setPlayerTeam(player,team); end; local PlayerBlips = {}; local AssigningHandler = function(player) local Team = getPlayerTeam(player); local Colors = not Team and {255,255,255} or {getTeamColor(Team)}; setPlayerNametagColor(player,Colors[1],Colors[2],Colors[3]); if PlayerBlips[player] then setBlipColor(PlayerBlips[player],Colors[1],Colors[2],Colors[3],255); elseif not PlayerBlips[player] then PlayerBlips[player] = createBlipAttachedTo(player,_,_,Colors[1],Colors[2],Colors[3]); end; end; local DestroyingHandler = function(player) if PlayerBlips[player] then destroyElement(PlayerBlips[player]); PlayerBlips[player] = nil; end; end; addEventHandler("onResourceStart",resourceRoot,function() for _,v in ipairs(getElementsByType("player") do AssigningHandler(v); end; end); addEventHandler("onPlayerSpawn",root,function() AssigningHandler(source); end); addEventHandler("onPlayerTeamChange",root,function(old_team,new_team) outputChatBox(("%s changed his team from %s to %s."):format(getPlayerName(source),getTeamName(old_team),getTeamName(new_team)),root); AssigningHandler(source); end; addEventHandler("onPlayerWasted",root,function() DestroyingHandler(source); end); addEventHandler("onPlayerQuit",root,function() DestroyingHandler(source); end); Your new event: onPlayerTeamChange (Serverside event) This event is triggered when a player team changes. This can be done using setPlayerTeam. Parameters element oldTeam, element newTeam The source of this event is the player whose team changed. Link to comment
roaddog Posted May 10, 2014 Author Share Posted May 10, 2014 Well Thank you guys that helped me alot Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now