Jump to content

Player Blips with teams


Hutchpe

Recommended Posts

Ok so I am trying to configure player blips for my server. I was initially running the 'playerblips' resource which was creating blips for the players but when a player was killed the killer could no longer see the victim on the radar when they respawned. I then attempted to write my own script with no success.

The overall aim is for a blip of a certain colour to be created for a player when the join a team or respawn. Here is what I have written.

function onPlayerSpawn ( spawnpoint ) --creates blip for player on team join 
    local team = getPlayerTeam (source) 
    if (team == teamMexicans) then 
        createBlipAttachedTo ( source, 0) 
    end 
end 
  
function onPlayerSpawn ( spawnpoint ) --creates blip for player on team join 
    local team = getPlayerTeam (source) 
    if (team == teamBorderControl) then 
        createBlipAttachedTo ( source, 0) 
    end 
end 
  
blips = getElementsByType ( "blip" ) --sets blip colour 
for blipKey, blipValue in blips do 
    red, green, blue, alpha = getBlipColor (  blipValue ) 
    local team = getPlayerTeam (source) 
    if (team == teamBorderControl) then 
        setBlipColor ( blipValue, 0, 0, 255, 255 ) 
    end 
end 
  
blips = getElementsByType ( "blip" ) --sets blip colour 
for blipKey, blipValue in blips do 
    red, green, blue, alpha = getBlipColor (  blipValue ) 
    local team = getPlayerTeam (source) 
    if (team == teamMexicans) then 
        setBlipColor ( blipValue, 255, 0, 0, 255 ) 
    end 
end 
  
function onPlayerQuit () 
    destroyBlipsAttachedTo ( source ) 
end 
  
function onPlayerWasted ( totalammo, killer, killerweapon ) 
    destroyBlipsAttachedTo ( source ) 
end 

Using the following code I also get get this error in console when starting the server.

ERROR: Mexihunt\script.lua:134: attempt to call a table value

Any help is greatly appreciated.

Link to comment

Ok thanks for the help guys. I added in events and now blips are being created properly with no issues!

There are only two remaining problems and one of them is with the blip colours. I have rewritten the script for it but it is changing all blip colours to red instead of red for one team and blue for the other. I get a message in console saying "WARNING: Bad argument @ 'setBlipColor' [C]" Here is what I have written.

function onPlayerSpawn ( spawnpoint ) 
    local team = getPlayerTeam (source) 
    local blips = getElementsByType ( "blip" ) 
    if (team == teamMexicans) then 
        setBlipColor ( blips, 255, 0, 0, 255 ) 
    else 
        setBlipColor ( blips, 0, 0, 255, 255 ) 
    end 
end 
addEventHandler ( "onPlayerSpawn", root, setBlipColor ) 

The last problem is that when a player disconnects, their blip is not destroyed. This is all I currently have that destroys players blips on quit.

function onPlayerQuit () 
    destroyBlipsAttachedTo ( source ) 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 

If I add this on the end of my script it destroys the blips properly when a player quits but when you kill another player you can no longer see them on radar which puts me back at step 1 again.

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 

Any help is greatly appreciated.

EDIT: I've changed the code significantly since this and the code here is no longer relevant.

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