Hero192 Posted August 14, 2015 Share Posted August 14, 2015 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
Hero192 Posted August 14, 2015 Author Share Posted August 14, 2015 No matter if i put the full code or no, but my problem is in this part. Link to comment
Hero192 Posted August 14, 2015 Author Share Posted August 14, 2015 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 Link to comment
t3wz Posted August 14, 2015 Share Posted August 14, 2015 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. Link to comment
HUNGRY:3 Posted August 14, 2015 Share Posted August 14, 2015 i mean only if I restarted script You need some thing to refresh it or just use settimer Link to comment
Hero192 Posted August 14, 2015 Author Share Posted August 14, 2015 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? Link to comment
Hero192 Posted August 14, 2015 Author Share Posted August 14, 2015 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 Link to comment
Hero192 Posted August 14, 2015 Author Share Posted August 14, 2015 Please try to give me a hand i still need help Link to comment
t3wz Posted August 14, 2015 Share Posted August 14, 2015 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
Hero192 Posted August 14, 2015 Author Share Posted August 14, 2015 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 Link to comment
HUNGRY:3 Posted August 15, 2015 Share Posted August 15, 2015 (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 August 15, 2015 by Guest Link to comment
Moderators IIYAMA Posted August 15, 2015 Moderators Share Posted August 15, 2015 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
Hero192 Posted August 15, 2015 Author Share Posted August 15, 2015 Doesn't works , i think there's no event named onPlayerTeamChange, anyone?? Link to comment
Moderators IIYAMA Posted August 15, 2015 Moderators Share Posted August 15, 2015 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now