local strnum = 0 //string num, for checking if it's the first string local elength = 0 //Make sure emote's lengths count! surface.SetFont("ChatFont") for k,v in ipairs(args) do //ipairs, we need order! if (type(v)=="string") then //We have a string! Let's test it! strnum = strnum+1 if (surface.GetTextSize( fullmsg..v )+elength > maxlen) then //Is it too long? NeedNewLine = true //Mark us as needing a new line! //Gonna have to keep colour consistancy between lines //_______ local ocol = Color(125,175,255) //Fallback for i=1,k do //k is where we are now, no point checking after it if ( ( type(args[i]) == "table") and (args[i].r and args[i].g and args[i].b)) then ocol=args[i] //It's a colour, set our current colour to it! end end NewArgs = { ocol } //New Arguments table //Split where neccessary for maximum sensible line-usage //_______ local fullstr = "" local words = string.Explode(" ", v) local newstring = "" local ToNew = false //Insert string to the new table? for i = 1,#words do local word = words[i] if ToNew then //We've already got the first bit done, the rest goes to the new table newstring = newstring.." "..word else if (surface.GetTextSize( fullmsg..fullstr.." "..word )+elength > maxlen) then //Is it too long? ToNew = true if (i == 1) then //We're the only word! Some silly coder sent one big word! if (strnum == 1) then //We're also the first string! //Oh no! Character wrapping! //------- local fullword = "" local newword = "" local foundword = false for num, char in ipairs( string.ToTable( word ) ) do //ipairs, we need order! if foundword then newword = newword..char else if (surface.GetTextSize( fullmsg..fullstr..fullword..char )+elength > maxlen) then //Is it too long (again)? foundword = true fullstr = fullstr..fullword //Should be same as fullword, but just in case newword = char else fullword = fullword..char end end end newstring = newword //------- else //We're not the only string, so just word-wrap as a normal chatbox newstring = word end else //We're not the only word, so just word-wrap as a normal chatbox newstring = word end else //It's not too long! if (i == 1) then //No extra space, it's the first word fullstr = word else fullstr = fullstr.." "..word end end end end fullmsg = fullmsg..fullstr table.insert(msgargs, fullstr) //Put it in at the end table.insert(NewArgs, newstring) //Re-gather all arguments that appear after this one //_______ for i= k,#args do if (i>k) then table.insert(NewArgs, args[i] ) end end break //And we're done! else fullmsg = fullmsg..v end end if (type(v) == "table") and (v[1] == "emote") then //It's an emoticon! elength = elength+v[4] //Add our emote's length strnum = strnum+1 //Not a string, but still counts! if (surface.GetTextSize( fullmsg )+elength > maxlen) then //Are we too long? //Simplified version of the above NeedNewLine = true //Set New Line local ocol = Color(125,175,255) //Backup Colour for i=1,k do if ( ( type(args[i]) == "table") and (args[i].r and args[i].g and args[i].b)) then //Find a colour ocol=args[i] end end NewArgs = { ocol, v } //New arguments, the colour and emoticon for i= k,#args do //Find anything that appears after this if (i>k) then table.insert(NewArgs, args[i] ) end end break //And we're done! end end table.insert(msgargs, v) end