Jump to content

Blip visible for Criminal team only


Hero192

Recommended Posts

Hey guys, i tried this way to let the blip visible only for criminal team but it works only one time i mean only if i restarted the script, so when i change the team it doesn't works, about errors there's no error.

I hope someone can give me a hand thanks in advance~

setElementVisibleTo(criminalBlip, root, false) 
    for i, player in ipairs ( getPlayersInTeam ( getTeamFromName ( "Criminal" ) ) ) do 
     setElementVisibleTo(criminalBlip, player, true) 
     end 
  

Link to comment
addEvent ( "onPlayerTeamChange" ) 
  
addDebugHook( "postFunction", function ( _, _, _, _, _, player, team ) triggerEvent ( "onPlayerTeamChange", player, team ) end, { "setPlayerTeam" } ) 

then you use this (↑) custom event:

addEventHandler ( "onPlayerTeamChange", root, 
function ( team ) 
    setElementVisibleTo( criminalBlip, source, team == getTeamFromName ( "Criminal" ) ) 
end ) 

but as cited in the wiki "it may degrade script performance", there's other ways (timers, editing the admin panel² etc).

Link to comment
function refs(player) 
if getTeamName(getPlayerTeam(player)) == "Criminal" then 
     setElementVisibleTo(criminalBlip, player, true) 
     else 
     setElementVisibleTo(criminalBlip, player,false) 
     end 
end 
setTimer(refs,1000,0) -- checks every second 

Edited by Guest
Link to comment
  • Moderators

that laggs, will use too much bandwidth and it is incorrect.

This example should enable the event "onPlayerTeamChange".

local lastPlayerTeam = {} 
setTimer(function () 
    local players = getElementsByType("player") 
    for i=1,#players do 
        local player = players[i] 
        local playerTeam = getPlayerTeam(player) or false -- make sure it always returns false, if it returns nil. 
        if playerTeam then 
            local lastTeam = lastPlayerTeam[player] or false -- make sure it always returns false, if it returns nil. 
            if playerTeam ~= lastTeam then 
                triggerEvent("onPlayerTeamChange",player,isElement(lastTeam) and lastTeam or false,playerTeam) 
                lastPlayerTeam[player] = playerTeam 
            end 
        else 
            local lastTeam = lastPlayerTeam[player] 
            if lastTeam then 
                triggerEvent("onPlayerTeamChange",player,isElement(lastTeam) and lastTeam or false,nil) 
                lastPlayerTeam[player] = nil 
            end 
        end 
    end 
end,1000,0) 
  
addEventHandler("onPlayerQuit",root, 
function () 
    if lastPlayerTeam[source] then 
        lastPlayerTeam[source] = nil 
    end 
end) 

Which you can use here:

addEventHandler ( "onPlayerTeamChange", root, 
function ( oldTeam,newTeam ) 
    local team = getTeamFromName ( "Criminal" ) 
    if oldTeam == team then 
        setElementVisibleTo( criminalBlip, source, nil ) 
    elseif newTeam == team then 
        setElementVisibleTo( criminalBlip, source, true ) 
    end 
end) 

And this is maybe handy too.

addEventHandler("onPlayerJoin",root, 
function () 
    setElementVisibleTo(criminalBlip, source, false) 
end) 

Nothing is tested, I will leave that to 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...