Copy ansi color from output as BBCode

Posted by Khonsu on Mon 08 Feb 2021 12:34 PM — 5 posts, 21,842 views.

#0
Hello. I want to start off by saying have almost no knowledge in Lua, or other languages really, and decided today to modify the ansi color copier to work for our forums and copy them as BBCode.

I have modified the copycolourcodes.xml and lotj_colours.lua to instead of copying &R &G etc to instead copy the codes with "[/color][color=#800000]" for the different colors. This works perfectly it seems. Edited out the line about added &w to the end since we don't need it for posting.

The problem I am running into, I think because of my limited knowledge on how to make this script, is that we will always have the [/color] at the very beginning of a line. This works great to end the color before a new color begins, but is there a simple way to have it remove the first [/color]?

For example:

&YYou sense a change in the &Glife &Yforces surrounding you.&w'&w

becomes:

[/color][color=#FFFF00]You sense a change in the [/color][color=#00FF00]life [/color][color=#FFFF00]forces surrounding you.[/color][color=#C0C0C0]'
Australia Forum Administrator #1
Can you please provide a link to where you found those files?
#2
I was emailed the copycolourcodes by another player some time ago. Originally I think it comes from a post on this forum:

https://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=8302

or perhaps

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=8821

but may have been modified since then?

I uploaded the versions I have to

https://drive.google.com/drive/folders/1oLS0UtfTtUlm8m3CTu4J2OTTFOybb8Uo?usp=sharing

The ones with RP in the title are the ones I edited, probably poorly, to work with our Roleplay channels and Forum we upload to.
Amended on Mon 08 Feb 2021 09:42 PM by Khonsu
USA Global Moderator #3
The one you have came from me originally (for Aardwolf) and then it looks like someone modified it for a different game. The problem is that it's really built for a kind of system that only has color codes at the beginning, not ones that open/close on both sides of a text like you want.

There are also a bunch of things in the .lua file that definitely won't work that you don't need anyway (and so might benefit from just getting rid of).

I think instead of starting from the one you were given you should instead start from the one in http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=8821

No matter what, you're going to have to manually adjust the result to remove the [/color] at the front and add one to the end.

In Lua you can do that with something like (right before the line that says SetClipboard(copystring))


if copystring:sub(1,8) == "[/color]" then
   copystring = copystring:sub(9).."[/color]"
end
Amended on Tue 09 Feb 2021 03:07 AM by Fiendish
#4
Awesome that works perfectly.

I tried to use the one from the forum post you listed but I got some errors. I'll dig into it more later and see if I can get it work.

Thank you guys again.

If anyone wants a copy of these files I'll keep the drive link I posted earlier alive as long as that's OK.