Jump to content

getElementData ipairs


Dolinho

Recommended Posts

Posted

if I use that goes for all of the specific team

for _,v in ipairs (getPlayersInTeam (getTeamFromName("Novo Jogador do BMV"))) do 
outputChatBox ( "Ola novo jogador", v ,0,255,0,true) 

how will I do for getElementData ?

for _,v in ipairs (getElementData("Red")) do  
outputChatBox ( "Ola novo jogador", v ,0,255,0,true) 

??????????????

If a player has Element Red so he would receive a msg

Posted
function theCheck() 
    for _,v in ipairs (getElementsByType("player")) do 
        if getElementData(v,"Red") then 
            outputChatBox ( "Ola novo jogador", v ,0,255,0,true) 
        end 
    end 
end  

Posted

?

local players = getElementsByType('player') 
      for index, p in ipairs(players) do 
            if getElementData(p, 'Red') ~= nil then 
                  --Your message here 
            end 
      end 

Posted (edited)

My bad, I was connected from my mobile, Try this

    for i, v in ipairs((getElementData(getElementsByType('player'), 'Red')) ~= nil) do 
            --Your message here 
    end 

Edited by Guest
  • Moderators
Posted

lol, your previously code was better.

Yet, mihayy5 his code is still the best solution, since getElementData only returns nil when the code fails, otherwise false.

@Dolinho

Make sure you only send the message to the correct player. Which you can set up in the outputChatBox function.

Posted
  
function getPlayersByElementData(theData) 
local tableResult = {} 
for i, v in ipairs(getElementsByType("player")) do 
if getElementData(v, theData) then 
table.insert(tableResult, v) 
end 
end 
return tableResult 
end 

Example

  
for i, v in ipairs(getPlayersByElementData("Red")) do 
outputChatBox("lol msg", v, 0, 255, 0) 
end 
  

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