Jump to content

How to prevent outputChatBox Spam in a for?


Tony Brand

Recommended Posts

hi
this is my code that prints player that have a elementdata

 

for index,player in ipairs(getElementsByType("player") ) do
      if getElementData(player,"Money") == 10000 then
	local name = getPlayerName(player)
      outputChatBox(" "..name.." ",player)
    end
  end

but as you it will use a single outputChatBox for each one,
For Example result can be:
Player1
Player2
Player3
...
PlayerN

how to show all of them in one or few lines?
like this ==> Player1, Player2, Player3, ..., PlayerN

Edited by Tony Brand
Link to comment
function func()
	local text = ""
	for index, player in ipairs(getElementsByType("player")) do
		if getElementData(player,"Money") == 10000 then
			local len = string.len(text)
			local name = getPlayerName(player)
			if len == 0 then
				text = name
			elseif len > 0 and len <= 256 then
				if (len + string.len(tostring(", "..name))) > 256 then
					outputChatBox(text, player)
					text = name
				else
					text = text..", "..name
				end
			end
		end
	end
	if string.len(text) > 0 then
		outputChatBox(text, player)		
	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...