Jump to content

getElementsByType


TorNix~|nR

Recommended Posts

Posted (edited)

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

76561198387870432.png

ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003

560x95_FFFFFF_FF9900_000000_000000.png

  • Moderators
Posted

@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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • 3 months later...
Posted
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)?
 

Говорю на русском. Sorry for bad english.
 

Posted (edited)
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

Chillin' with some demons, satans and vamps

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...