Ride1234 Posted July 12, 2010 Share Posted July 12, 2010 Hi, I'm making tdm mode, and try to create blips on the radar which will be visible only to player's team (so, player can see on the radar only his team-mates), but when I try to make blip visible to player's team, the blip don't wants to create. There are no errors or warnings in server's log. My code (it's it onPlayerSpawn event): if(getTeamName(getPlayerTeam(source)) == "Terrorists") then icons[source] = createBlipAttachedTo(source,59,0,255,0,0,255,0,99999.0,getPlayerTeam(source)) elseif (getTeamName(getPlayerTeam()) == "Cops") then icons[source] = createBlipAttachedTo(value,61,1,0,0,255,255,0,99999.0,getPlayerTeam(source)) end if I create blip without last argument, it creates, but visible to all players. Can anyone help me? Link to comment
dzek (varez) Posted July 12, 2010 Share Posted July 12, 2010 you are passing TEAM as last value.. it needs to be player element.. Link to comment
Callum Posted July 12, 2010 Share Posted July 12, 2010 You could create it as normal, but then setElementVisibleTo to make it a team-only visible blip. Link to comment
Ride1234 Posted July 12, 2010 Author Share Posted July 12, 2010 I create a blip, it's visible by all players: icons[source] = createBlipAttachedTo(source,58) then in other functuion (it invokes be typing command) i try to set blip visible to selected players: for idx,value in ipairs(getElementsByType("player")) do if(getTeamName(getPlayerTeam(value)) == "Terrorists") then setElementVisibleTo ( icons[value], getRootElement ( ), false ) setElementVisibleTo( icons[value], getPlayerTeam(value),true) elseif (getTeamName(getPlayerTeam()) == "Cops") then setElementVisibleTo ( icons[value], getRootElement ( ), false ) setElementVisibleTo( icons[value], getPlayerTeam(value),true) end end And... it doesn't work. Where is my fail? Link to comment
50p Posted July 12, 2010 Share Posted July 12, 2010 You have to understand what is Element Tree. Once you know what element tree is, you can fix your problem easily. you are passing TEAM as last value.. it needs to be player element.. It doesn't need to be player, it has to be an element. It shouldn't matter if it's player or team but it matters how they are located in the element tree. If you setPlayerTeam then player is assigned to that team but in element tree, team is not player's parent. Understanding element tree is very important because MTA is built on it and every element has its location on the tree. There are functions which let you do same thing for children of specific element, like outputChatBox, lets you print message to 1 player, whole server or team (if the element tree is laid out properly). What you can do Ride1234 is use setElementParent so that player is team's child. For instance: local team = getTeamFromName( "Terrorists" ); setPlayerTeam( player, team ); setElementParent( player, team ); --[[ Element tree would look like this: +Terrorists +Player1 +Player2 +Cops +Player3 +Player4 ]] This way, if you outputChatBox to Terrorists team, it will print the message to Player1 and Player2 only. At least it should because that's how MTA is meant to work. Link to comment
Ride1234 Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks everyone for help. So here is small manual for beginners like me. Create an array: playerBlips = { } and put this code in the function you need (or maybe create timer) for index,value in ipairs(getElementsByType("player")) do if( playerBlips [ value ] ) then destroyElement( playerBlips[ value ] ) playerBlips [ value ] = nil end playerBlips[ value ] = createBlipAttachedTo ( value, 59 ) setElementVisibleTo(playerBlips[value],getRootElement( ),false) if(getTeamName(getPlayerTeam(value)) == "Terrorists") then for index1,value1 in ipairs(getElementsByType("player")) do if(getTeamName(getPlayerTeam(value1)) == "Terrorists") then setElementVisibleTo(playerBlips[value],value1,true) end end elseif(getTeamName(getPlayerTeam(value)) == "Cops") then for index1,value1 in ipairs(getElementsByType("player")) do if(getTeamName(getPlayerTeam(value1)) == "Cops") then setElementVisibleTo(playerBlips[value],value1,true) end end end end and of course you need to delete blip when player exit or die, using this code: if (playerBlips[source]) then destroyElement(playerBlips[source]) playerBlips[source] = nil end It works fine with me. P.S. And sorry for my bad english 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