Jump to content

Player blips


Recommended Posts

function Blip ()

for id, PLAYERS in ipairs(getElementsByType("player")) do

local r, g, b = getTeamColor(getPlayerTeam(PLAYERS))

createBlipAttachedTo(PLAYERS, 0, 2, r, g, b)

end

end

setTimer(Blip, 5000, 0)

function quit ()

destroyBlipsAttachedTo(source)

end

addEventHandler("onPlayerQuit", getRootElement(), quit)

function dead (totalammo, killer, killerweapon)

destroyBlipsAttachedTo ( source )

end

addEventHandler("onPlayerWasted", getRootElement(), dead)

function destroyBlipsAttachedTo(player)

local attached = getAttachedElements(player)

if (attached) then

for k,element in ipairs(attached) do

if getElementType(element) == "blip" then

destroyElement(element)

end

end

end

end

----

Thank you CodyL

Link to comment
blips = {} 
  
function Blip () 
for id, player in ipairs(getElementsByType("player")) do 
local r, g, b = getTeamColor(getPlayerTeam(player)) 
if blips[player] then 
setBlipColor (blips[player],r, g, b,255) 
else 
blips[player] = createBlipAttachedTo(PLAYERS, 0, 2, r, g, b) 
end 
end 
end 
setTimer(Blip, 5000, 0) 
  
function quit () 
destroyElement(blips[source]) 
end 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
  
function dead (totalammo, killer, killerweapon) 
destroyElement(blips[source]) 
end 
addEventHandler("onPlayerWasted", getRootElement(), dead) 
  

You were creating a new blip every 5 secounds. Causing alot of lag.

Link to comment

sorry, that is my old script this is the new works but the problem in F11 (lag)

function Blip ()

for id, PLAYERS in ipairs(getElementsByType("player")) do

local r, g, b = getTeamColor(getPlayerTeam(PLAYERS))

createBlipAttachedTo(PLAYERS, 0, 2, r, g, b)

setTimer(Blip, 5000, 0)

end

end

Blip()

function quit ()

destroyBlipsAttachedTo(source)

end

addEventHandler("onPlayerQuit", getRootElement(), quit)

function dead (totalammo, killer, killerweapon)

destroyBlipsAttachedTo(source)

end

addEventHandler("onPlayerWasted", getRootElement(), dead)

function destroyBlipsAttachedTo(player)

local attached = getAttachedElements(player)

if (attached) then

for k,element in ipairs(attached) do

if getElementType(element) == "blip" then

destroyElement(element)

end

end

end

end

Link to comment
function Blip () 
for id, PLAYERS in ipairs(getElementsByType("player")) do 
local r, g, b = getTeamColor(getPlayerTeam(PLAYERS)) 
createBlipAttachedTo(PLAYERS, 0, 2, r, g, b) 
setTimer(Blip, 5000, 0) 
end 
end 
  
Blip() 
  
function quit () 
destroyBlipsAttachedTo(source) 
end 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
  
function dead (totalammo, killer, killerweapon) 
destroyBlipsAttachedTo(source) 
end 
addEventHandler("onPlayerWasted", getRootElement(), dead) 
  
function destroyBlipsAttachedTo(player) 
local attached = getAttachedElements(player) 
if (attached) then 
for k,element in ipairs(attached) do 
if getElementType(element) == "blip" then 
destroyElement(element) 
end 
end 
end 
end  

Done, anyone help?

the problem: when I open F11 it starts lag (FPS 5-10)

Link to comment
function blip () 
for id, thePlayer in ipairs(getElementsByType("player")) do 
local r, g, b = getTeamColor(getPlayerTeam(PLAYERS)) 
createBlipAttachedTo(thePlayer, 0, 2, r, g, b) 
end 
end 
  
addEventHandler("onPlayerJoin",root,blip) 
  
function quit () 
destroyBlipsAttachedTo(source) 
end 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
  
  
function destroyBlipsAttachedTo(player) 
local attached = getAttachedElements(player) 
if (attached) then 
for k,element in ipairs(attached) do 
if getElementType(element) == "blip" then 
destroyElement(element) 
end 
end 
end 
end 

Link to comment
function blip () 
for id, thePlayer in ipairs(getElementsByType("player")) do 
local r, g, b = getTeamColor(getPlayerTeam(PLAYERS)) 
createBlipAttachedTo(thePlayer, 0, 2, r, g, b) 
end 
end 
  
addEventHandler("onPlayerJoin",root,blip) 
  
function quit () 
destroyBlipsAttachedTo(source) 
end 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
  
function destroyBlipsAttachedTo(player) 
local attached = getAttachedElements(player) 
if (attached) then 
for k,element in ipairs(attached) do 
if getElementType(element) == "blip" then 
destroyElement(element) 
end 
end 
end 
end 

 PLAYERS = ?

Link to comment
  
function blip1 () 
for id, thePlayer in ipairs(getElementsByType("player")) do 
local r, g, b = getTeamColor(getPlayerTeam(thePlayer)) 
createBlipAttachedTo(thePlayer,20,1,r,g,b) 
end 
end 
  
  
  
 blip1() 
  
  
 function destroyBlipsAttachedTo(player) 
local attached = getAttachedElements(player) 
if (attached) then 
for k,element in ipairs(attached) do 
if getElementType(element) == "blip" then 
destroyElement(element) 
end 
end 
end 
end 
  
function quit () 
destroyBlipsAttachedTo(source) 
end 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
  

Link to comment
function blip () 
for id, thePlayer in ipairs(getElementsByType("player")) do 
local r, g, b = getTeamColor(getPlayerTeam(PLAYERS)) 
createBlipAttachedTo(thePlayer, 0, 2, r, g, b) 
end 
end 
  
addEventHandler("onPlayerJoin",root,blip) 
  
function quit () 
destroyBlipsAttachedTo(source) 
end 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
  
function destroyBlipsAttachedTo(player) 
local attached = getAttachedElements(player) 
if (attached) then 
for k,element in ipairs(attached) do 
if getElementType(element) == "blip" then 
destroyElement(element) 
end 
end 
end 
end 

 PLAYERS = ?

Are you blind? there is thePlayer

Link to comment
function Blip() 
   for _, v in ipairs(getElementsByType("player")) do 
       local r, g, b = getTeamColor(getPlayerTeam(v)) 
       createBlipAttachedTo(v, 0, 2, r, g, b) 
    end 
end 
setTimer(Blip, 5000, 0) 
  
function quit() 
    destoryBlipsAttachedTo(souce) 
end 
addEventHandler("onPlayerQuit", root, quit) 
  
function destoryBlipsAttachedTo(thePlayer) 
    local attached = getAttachedElements(thePlayer) 
    if (attached) then 
        for k, element in ipairs(attached) do 
            if getElementType(element)== "blip" then 
               destroyElement(element) 
            end 
        end 
    end 
end 

Link to comment

or or or or --

    blips = {} 
      
    function Blip () 
    for id, player in ipairs(getElementsByType("player")) do 
    local r, g, b = getTeamColor(getPlayerTeam(player)) 
    if blips[player] then 
    setBlipColor (blips[player],r, g, b,255) 
    else 
    blips[player] = createBlipAttachedTo(player, 0, 2, r, g, b) 
    end 
    end 
    end 
    setTimer(Blip, 5000, 0) 
      
    function quit () 
    destroyElement(blips[source]) 
    end 
    addEventHandler("onPlayerQuit", getRootElement(), quit) 
      
    function dead (totalammo, killer, killerweapon) 
    destroyElement(blips[source]) 
    end 
    addEventHandler("onPlayerWasted", getRootElement(), dead) 
      

Updates the color every 5.

I forgot to change PLAYERS to player. Small mistake, rest of the code should work perfectly from what I know.

Link to comment

Try this

local blips = {} -- blips table 
      
function Blip () 
    local players = getElementsByType("player") 
    for id, player in ipairs(players) do 
        local team = getPlayerTeam(player) 
        if team then  
            local r, g, b = getTeamColor(team) 
            if blips[player] then 
                setBlipColor (blips[player],r, g, b,255) 
            else 
                blips[player] = createBlipAttachedTo(player, 0, 2, r, g, b) 
            end  
        end 
    end 
end 
setTimer(Blip, 5000, 0) 
      
-- destroy the blip (onPlayerQuit,onPlayerLogout,onPlayerWasted) 
function quit () 
    if blips[source] then -- if the blip exist then 
        destroyElement(blips[source]) -- destroy it 
        blips[source] = nil 
    end  
end 
addEventHandler("onPlayerLogout", getRootElement(), quit) 
addEventHandler("onPlayerQuit", getRootElement(), quit) 
addEventHandler("onPlayerWasted", getRootElement(), quit)  

  • Like 1
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...