Jump to content

createBlip on Player for a specific Team or Group


Zuher Laith

Recommended Posts

Hi everyone,

So I'm trying to make a button that create a blip on player, the blip is visible to him & for a specific Group, well I just did it for team, I want it for group ..
At first a blip attached to player, and visible to client & each player in that group (acl group), and setting the blip color to green using SetBlipColor ,
and another button that remove the blip on client & in the other players map,

This is only server sided, the client triggers the event from gui for sure ..

local playerBlipRoot = createElement("playerBlipRoot", "playerBlipRoot")
local blipvisible, myBlip
blipvisible = false

-- The Calling Function:
-- function
	local theTeam = getTeamFromName(get("Police"))
	for index, polices in ipairs(getPlayersInTeam(theTeam)) do
		if blipvisible == false then
			-- chat msg to "polices", "help requisted, check your gps."
			-- chat msg to "client", "you called police."
			myBlip = createBlipAttachedTo(Player, 20)
			setElementParent(myBlip, playerBlipRoot)
			setElementVisibleTo ( myBlip, polices, true )
			blipvisible = true
		else 
			-- chat msg to "client", "you already called the police."
			return
		end
-- end

-- THE REMOVING BLIP ELEMENT:
-- function
		destroyElement(myBlip)
		blipvisible = false
        -- enough.. right ?
-- end

Instead of blip 20, I want to change it to 0 and make it colored to green, since I'm willing to remove blip 0 from every single player,
I hope its clear enough ..

Thanks in advance.

Link to comment
  • Moderators

There is also a for ... do in that code which is looping through the exact same element type. Not much of a difference..

 

Here you got a stripped version: (18+ only)

local players = getElementsByType ( "player" )

local aclGroup = aclGetGroup ( "Police" )

for k, player in pairs(players) do
	local account = getPlayerAccount(player)
	if not isGuestAccount(account) then
		local accountName = getAccountName (account)
		if isObjectInACLGroup ( "user." .. accountName,  aclGroup) then
			-- put your stuff.
			
		end
	end
end

 

Edited by IIYAMA
  • Like 2
Link to comment
16 hours ago, IIYAMA said:

Here you got a stripped version: (18+ only)

I love your humor with coding xD
 

16 hours ago, IIYAMA said:

There is also a for ... do in that code which is looping through the exact same element type. Not much of a difference..

I see.. now I get it,
but when I make the blip visible for the "player" or "v" in "for...do", I'm trying to make it visible for the player itself:

Spoiler

function LlamaServicio(Player, Team)
  if Team == "Police" then
    local players = getElementsByType ( "player" )
    local aclGroup = aclGetGroup ( "Police" )
    for k, polices in pairs(players) do
      local account = getPlayerAccount(polices)
      if not isGuestAccount(account) then
        local accountName = getAccountName (account)
        if isObjectInACLGroup ( "user." .. accountName,  aclGroup) then
          -- chat msg here (polices, "Backup requested, location on GPS")
          outputDebugString("Blip Attached!", 3)
          myBlip = createBlipAttachedTo(polices, 20)
          setElementParent(myBlip, playerBlipRoot)
          setElementVisibleTo ( myBlip, polices, true ) -- HERE --
          blipvisible = true
        end
      end
    end
    -- chat msg here (player, "You called police.")
  end if
end

 

I'm running this on a server but I'm the only one suppose to test it,
So If the player was not in the aclGroup, it just shows the msg "You called Police", and no Debug String message shown in the Debug script, and no blip visible in client .

What I want you to confirm, is this working if a player is not in aclGroup ?

Link to comment
  • Moderators

That depends on a lot of things. The only way to figure it out is by testing and testing with multiple players.

I also do not know if the function setElementVisible works for the team element. If not, then you also have to re-loop and collecting all players.

 

What you need to do is testing it with multiple players. There are just no other options

function LlamaServicio(Player, Team)
	if Team == "Police" then
		local players = getElementsByType ( "player" )
		local aclGroup = aclGetGroup ( "Police" )
		for k, polices in pairs(players) do
			local blipvisible = false
			local account = getPlayerAccount(polices)
			if not isGuestAccount(account) then
				local accountName = getAccountName (account)
				if isObjectInACLGroup ( "user." .. accountName,  aclGroup) then
					-- chat msg here (polices, "Backup requested, location on GPS")
					outputDebugString("Blip Attached! For player: "  .. tostring(getPlayerName(polices)), 3)
					local myBlip = createBlipAttachedTo(polices, 20)
					setElementParent(myBlip, playerBlipRoot)
					setElementVisibleTo ( myBlip, root, false ) -- make it invisible for all players. (this does not have influence on new joined players.)
					setElementVisibleTo ( myBlip, polices, true ) -- I am not sure if it works for team players. You should test it with multiple players.
					blipvisible = true
				end
			end
			if not blipvisible then
				outputDebugString("I am not the police. For player: " .. tostring(getPlayerName(polices)))
				-- I am not the police
			end
		end
		-- chat msg here (player, "You called police.")
	end
end

 

  • Thanks 1
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...