Jump to content

Too long outputChatBox


kevenvz

Recommended Posts

I got a too long outputChatBox string(I think)

local commandsXML = xmlLoadFile("commands.xml") 
  for index,node in pairs(xmlNodeGetChildren(commandsXML)) do 
    if xmlNodeGetName(node) == "command" then 
      checkSound(xmlNodeGetAttribute(node,"sound")) 
      commands = commands..colorCode.." /"..xmlNodeGetAttribute(node,"commandName")..textColor 
    end 
  end 
  
addCommandHandler("chatcommands", 
  function(player) 
    outputChatBox(colorCode.."# "..textColor.."Available chatcommands:"..commands,player,255,255,255,true) 
  end) 

Does anybody know how to fix it or something? Something like \r\n?

Link to comment

Read the commands into a table, and then output them from here, only one command for one outputChatBox.

local commandsTable = {} 
local commandsXML = xmlLoadFile("commands.xml") 
  for index,node in pairs(xmlNodeGetChildren(commandsXML)) do 
    if xmlNodeGetName(node) == "command" then 
      checkSound(xmlNodeGetAttribute(node,"sound")) 
      commandsTable[ #commandsTable + 1 ] = colorCode.." /"..xmlNodeGetAttribute(node,"commandName")..textColor 
    end 
  end 
  
addCommandHandler("chatcommands", 
  function(player) 
    outputChatBox(colorCode.."# "..textColor.."Available chatcommands:",player,255,255,255,true) 
    for i, v in ipairs ( commandsTable ) do 
        outputChatBox ( v, player, 255, 255, 255, true ) 
    end 
  end) 

Link to comment
Read the commands into a table, and then output them from here, only one command for one outputChatBox.
local commandsTable = {} 
local commandsXML = xmlLoadFile("commands.xml") 
  for index,node in pairs(xmlNodeGetChildren(commandsXML)) do 
    if xmlNodeGetName(node) == "command" then 
      checkSound(xmlNodeGetAttribute(node,"sound")) 
      commandsTable[ #commandsTable + 1 ] = colorCode.." /"..xmlNodeGetAttribute(node,"commandName")..textColor 
    end 
  end 
  
addCommandHandler("chatcommands", 
  function(player) 
    outputChatBox(colorCode.."# "..textColor.."Available chatcommands:",player,255,255,255,true) 
    for i, v in ipairs ( commandsTable ) do 
        outputChatBox ( v, player, 255, 255, 255, true ) 
    end 
  end) 

But I want them to be in a straight line, like when the first line is full it goes to the next line etc..

Link to comment

Then you have to brake it into lines by yourself. My solution:

function linebreak ( t ) 
    local line = "" 
    local newTable = {} 
     
    local i = 1 
    while i <= #t do 
    while line:len () <= 120 and i <= #t do -- I'm not sure what is the character limit. You can try changing the value 120. 
            line = line .. t[ i ] 
            i = i + 1 
        end 
        newTable[ #newTable + 1 ] = line 
        line = "" 
    end     
    return newTable 
end 
  
local commandsTable = {} 
local commandsXML = xmlLoadFile("commands.xml") 
  for index,node in pairs(xmlNodeGetChildren(commandsXML)) do 
    if xmlNodeGetName(node) == "command" then 
      checkSound(xmlNodeGetAttribute(node,"sound")) 
      commandsTable[ #commandsTable + 1 ] = colorCode.." /"..xmlNodeGetAttribute(node,"commandName")..textColor 
       
    end 
  end 
  commandsTable = linebreak ( commandsTable ) 
   
addCommandHandler("chatcommands", 
  function(player) 
    outputChatBox(colorCode.."# "..textColor.."Available chatcommands:",player,255,255,255,true) 
    for i, v in ipairs ( commandsTable ) do 
        outputChatBox ( v, player, 255, 255, 255, true ) 
    end 
  end) 

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