Can anyone tell me how to split these into a table with the colour code and text. I am tying to get to the same layout as the styles table from triggers.
"a @Bblue @wpotion"
"an adventurer's head"
"@Y(@w!@Y(@WEyes of the Wolf@Y)@w!@Y)@w"
This is as far as I have got after like 9 hours and it doesn't work at all.
More test data:
a long spike
@R(@w!@R(@rLight Relief@R)@w!@R)
@ya @ypot of @Ygold
an adventurer's head
a Pet Store Employee ID Card
a @WT@wrusty @RA@wylorian @YM@wace
@WGueldar's @wcrafted leather bracer
goblin ceremonial robes
a bone sword
a helm made from a dragon's skull
a bone sword
an evil looking black dagger
ornate robes
a bright ball of light
a well used backpack
a @Bblue @wpotion
a potion of protection
@Y(@w!@Y(@WEyes of the Wolf@Y)@w!@Y)
@wa @rdragon@R'@rs @Wbr@wea@Wth
@wa @rdragon@R'@rs @Wbr@wea@Wth
@WChalice of the @B<(@W=@YWatchmen@W=@B)>
a potion of protection
@G(@w!@G(@cGreen Tea@G)@w!@G)
@RVladia's @WShopping Bag
@YAylorian @CAcademy @Wcanoe
@YAcademy Healing Potion
an @RAardwolf @WAdventurer's Guide@w (type @Rread guide@w)
a potion of protection
@YAylorian @CAcademy @Wcanoe
Thanks
"a @Bblue @wpotion"
"an adventurer's head"
"@Y(@w!@Y(@WEyes of the Wolf@Y)@w!@Y)@w"
This is as far as I have got after like 9 hours and it doesn't work at all.
function string_test()
colours={}
colours={
R = "darkred",
B = "darkblue",
C = "darkcyan",
M = "darkmagenta",
Y = "darkyellow",
G = "darkgreen",
W = "darkwhite",
D = "gray",
r = "red",
b = "blue",
c = "cyan",
m = "magenta",
y = "yellow",
g = "green",
w = "white"
}
bground="black"
inv_description="a @Bblue @wpotion"
inv_description="a bone sword"
inv_description="@Y(@w!@Y(@WEyes of the Wolf@Y)@w!@Y)@w"
t={}
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
for i,v in pairs(split(inv_description, "\@([BCMYGWDrbcmygw])")) do
colour = inv_description:match("\@([BCMYGWDrbcmygw])", i+1)
if colour == "" then
colour = "white"
else
colour = colours[colour]
end
t[i]={
["textcolour"]=colour,
["backcolour"]=bground,
["length"]=string.len(v),
["style"]=0,
["text"]=v
}
end
tprint(t)
end
More test data:
a long spike
@R(@w!@R(@rLight Relief@R)@w!@R)
@ya @ypot of @Ygold
an adventurer's head
a Pet Store Employee ID Card
a @WT@wrusty @RA@wylorian @YM@wace
@WGueldar's @wcrafted leather bracer
goblin ceremonial robes
a bone sword
a helm made from a dragon's skull
a bone sword
an evil looking black dagger
ornate robes
a bright ball of light
a well used backpack
a @Bblue @wpotion
a potion of protection
@Y(@w!@Y(@WEyes of the Wolf@Y)@w!@Y)
@wa @rdragon@R'@rs @Wbr@wea@Wth
@wa @rdragon@R'@rs @Wbr@wea@Wth
@WChalice of the @B<(@W=@YWatchmen@W=@B)>
a potion of protection
@G(@w!@G(@cGreen Tea@G)@w!@G)
@RVladia's @WShopping Bag
@YAylorian @CAcademy @Wcanoe
@YAcademy Healing Potion
an @RAardwolf @WAdventurer's Guide@w (type @Rread guide@w)
a potion of protection
@YAylorian @CAcademy @Wcanoe
Thanks