TorNix~|nR

getElementsByType

Recommended Posts

hello guys, please I'm wondering why isn't this working

for index,thisPlayer in pairs(getElementsByType("player") or getElementsByType("ped")) do

nothing found on debug, but only ped works but player not

help please?

Edited by TorNix~|nR

Share this post


Link to post

@TorNix~|nR

That is not how this works. A table is a thing, it is something even if it is empty.

if {} then
	outputChatBox("Always true")
end

 

local players = getElementsByType("player") 


for index,thisPlayer in pairs(#players > 0 and players or getElementsByType("ped")) do

 

Note, this does not merge the tables. Just uses peds when there are no players.

  • Thanks 1

Share this post


Link to post
On 22/03/2019 at 01:39, IIYAMA said:

@TorNix~|nR

That is not how this works. A table is a thing, it is something even if it is empty.


if {} then
	outputChatBox("Always true")
end

 


local players = getElementsByType("player") 


for index,thisPlayer in pairs(#players > 0 and players or getElementsByType("ped")) do

 

Note, this does not merge the tables. Just uses peds when there are no players.

I have "edixBox" from which I get the result (variable - result), how to check if there is such a player on the server (with the same name)?
 

Share this post


Link to post
37 minutes ago, Hugos said:

I have "edixBox" from which I get the result (variable - result), how to check if there is such a player on the server (with the same name)?
  

addEventHandler ( "onClientGUIChanged" , guiRoot , function ( )
    if source == yourEditBox then
        local Name = guiGetText ( source )
        if Name and Name ~= "" then
            for _ , Player in pairs( getElementsByType ( "player" ) ) do
                if getPlayerName ( Player ):lower ( ):find ( Name:lower ( ) , 1 , true) then
                    outputChatBox ( "Player Exists" , 255 , 255 , 255 , true )
                    break
                end
            end
        end
    end
end )

Edit : forget ( break )

Edited by #x1AhMeD-09
  • Like 1

Share this post


Link to post

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.