Jump to content

Player blips


Xwad

Recommended Posts

hi i have a script that makes possible when i shoot with a gun then the players will see my blip on the map but its not working:/

  
function applyBlips() 
    for k, player in pairs( getElementsByType( "player" ) ) do 
        local r, g, b = getPlayerNametagColor( player ) 
        if isPedDead( player ) then return end 
        if not blip[player] then 
            blip[player] = createBlipAttachedTo( player, 0, 2, r, g, b, 255, 0, blipViewDistance ) 
        else 
            setBlipColor( blip[player], r, g, b, 255 ) 
        end 
    end 
end 
addEventHandler( "onWeaponFire", resourceRoot, applyBlips ) 
setTimer( applyBlips, 500, 0 ) -- This is to account for name tag colour changes, especially in RPG servers. 
  
  
  
function createBlips() 
    if ( source ) then player = source end 
    local r, g, b = getPlayerNametagColor( player ) 
    if not blip[player] then 
        blip[player] = createBlipAttachedTo( player, 0, 2, r, g, b, 255, 0, blipViewDistance ) 
    else 
        setBlipColor( blip[player], r, g, b, 255 ) 
    end 
end 
addEventHandler( "onWeaponFire", root, createBlips ) 
  

Link to comment

The code is illogical. You're creating a blip for each player instead of only creating one for the player that used his weapon. The timer is also not needed.

local blip = {} 
  
addEventHandler('onWeaponFire', root, function() 
 if (not isElement(source) or isPedDead(source)) then return end 
 local r, g, b = getPlayerNametagColor(source) 
 if (isElement(blip[source])) then 
  setBlipColor(blip[source], r, g, b) 
 else 
  blip[source] = createBlipAttachedTo(source, 0, 2, r, g, b) 
 end 
end) 

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