Jump to content

Blip visible for Criminal team only


Hero192

Recommended Posts

Posted

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 
  

Posted

It's a part of the script .. Already i did events..etc don't worry my problem is ,i want let blip be visible only for criminals even if i changed the team

Posted

There's no event which is triggered when the player change his team, then you need to edit the admin panel (or the script you use) to set the visibility of the blip when player change the team.

Posted

Yes i was changing the team just with the default admin panel not with a PED Jobs, i know there's no function for chaning the team but i thought i was wrong, anyway so im not wrong?

Posted

Doesn't works, please help me in a good way when player change the team the blip be invisible for no criminals and visible for criminals

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

Posted

Can you explain to me because i didn't get this way, i have to edit it? or put it directly to server side remplaced with what i wrote before?

and thank alot for your time

Posted (edited)
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
  • Moderators
Posted

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.

  • Moderators
Posted

are you kidding me? That code just creates a custom event.

You are the one that has to test and add everything. If you forget to add everything, it will be impossible to help you.

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