Jump to content

Remove the source player in "players" table


Cronoss

Recommended Posts

I want to show a specific message to players near to the "source player", but when I get "elements by type ("player"), it takes all the players, including the one it's executing the command, but i don't want to show the message like that, just for the players around... I've been trying to remove the sourceplayer from the table but nothing seems to work

-----
local playersAround = getElementsByType ("player") 
local x, y, z = getElementPosition (thePlayer))
    for i,v in ipairs (jugadores) do
     table.remove(jugadores, ?) -----don't know what to add here, I tried with "source, sourcePlayer, thePlayer, player" but it don't work as i want
	local x2, y2, z2 = getElementPosition (v)
			
	if getDistanceBetweenPoints3D (x, y, z, x2, y2, z2) <= distanceofmsj then
			if getElementDimension (thePlayer) == getElementDimension (v) then
					outputChatBox ("testeo", v,  21, 208, 24)
											
			end
	end

 

Link to comment

I tried to translate the code to english and I missed that part, the table "jugadores" (now called playersAround) contains all the players, and yes, I know the "table.remove" need two parameters, but I don't know how to make the table ignores the source player (player who started the function)

(fixed)

local playersAround = getElementsByType ("player") 
local x, y, z = getElementPosition (thePlayer))
    for i,v in ipairs (playersAround) do
     table.remove(playersAround, ?) -----don't know what to add here, I tried with "source, sourcePlayer, thePlayer, player" but it don't work as i want
	local x2, y2, z2 = getElementPosition (v)
			
	if getDistanceBetweenPoints3D (x, y, z, x2, y2, z2) <= distanceofmsj then
			if getElementDimension (thePlayer) == getElementDimension (v) then
					outputChatBox ("testeo", v,  21, 208, 24)
											
			end
	end

I tried with table.remove(playersAround, ........ source,sourceplayer,theplayer,player,i), nothing seems to work... well, it works but it removes the other players and not the source player, so I get the "inverse" result that I want

Link to comment
  • Moderators
26 minutes ago, Cronoss said:

her players and not the source player, so I get the "inverse" result that I want

Just compare each player with the player you do not want. Filtering is only beneficial when you keep that table for a longer period of time/repeat usage.

-- loop start
if player ~= otherPlayer then
  
end
-- loop end

 

 

 

  • Like 3
Link to comment

That loop should be before or after "for i,v in ipairs (playersAround) do"? Because I'm trying everything I can think and still can see the message

Quote

is only beneficial when you keep that table for a longer period of time/repeat usage.

I want to keep the table for a long period of time, because it will be a frequently command used in the server, so yes, this kind of solution would help. 

local jugadores = getElementsByType ("player")
	if (player~=thePlayer) then ----also tried with "(jugadores ~=thePlayer, source, sourcePlayer...)

 

Link to comment
  • Moderators

 

13 minutes ago, Cronoss said:

I want to keep the table for a long period of time, because it will be a frequently command

The player-list is dynamic, it does not seems to be a worth option for your user-case. It is only an option when the list is static, so no new players.

 

-- function ( playerSource, commandName )
  local playerList = getElementsByType ("player")
  for index, player in pairs(playerList) do
      if player ~= playerSource then

      end
  end
-- end

 

 

 

  • Like 1
  • Thanks 1
Link to comment

Just tested it with another person and it works, thank you so much! But then, this table solution it's dynamic? I'm not too good for some english concepts, I just want to know if this add "new players" in the list, because I don't think that this command should keep static information... I'm sorry if you already explained it, I don't get some words:thumbup:

Edited by Cronoss
  • Like 2
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...