Page 1 of 1

Chat parse to out-game services

Posted: Sat Jul 11, 2015 11:00 pm
by Stionowl1943
Hello, i work on redirect ingame chat to my website via micromacro in real time.
I have problem with correctly parse strings with items name.

Example chat message catched by mm:

Code: Select all

SELL1 |Hitem:3466e 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498|h|cffa37d50[ITEMNAME1]|r|h SELL2 |Hitem:334ac 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498|h|cffa37d50[ITEMNAME2]|r|h
for delete useless strings i used:

Code: Select all

local parsemsg = str:gsub("|Hitem:.-|h|(%x+)","")
local parsemsg2 = parsemsg:gsub("|r|h", "")
print(parsemsg2)
effect

Code: Select all

SELL1 [ITEMNAME1] SELL2 [ITEMNAME2]
now im interested in to catch hex values with id/runes/attributes for build completly view of item. From my example i expect:

Code: Select all

3466e 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498
334ac 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498
i used

Code: Select all

local str_hex1 = string.match(str, "|Hitem:.+.|h|c");
local str_hex2 = str_hex1:gsub("|Hitem:","")
local str_hex3 = str_hex2:gsub("|h|c", "")
print("HEX: "..str_hex3)
but it works good only for 1 item.
In that example effect is:

Code: Select all

3466e 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498ffa37d50[Dagger of Extremes]|r|h SELL2 334ac 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498
I triend use parseItemLink(itemLink) from micromacro/rom/functions.lua but u have the same problem.
I spend a lot of hours for read LUA documentation about string modification and patterns, but i cant find good method.
So.. any idea how catch HEX values when i have more than 1 item?

Re: Chat parse to out-game services

Posted: Sun Jul 12, 2015 2:54 am
by rock5
".+" will match the largest matching string so from the first "|Hitem:" to the last "|h|c". If you use ".-" it will match the smallest string so would give you only the first item. If you want both you could use gmatch.

Code: Select all

for str_hex1 in str:gmatch("|Hitem:.-.|h|c") do
    str_hex2 = str_hex1:gsub("|Hitem:","")
    str_hex3 = str_hex2:gsub("|h|c", "")
    print("HEX: "..str_hex3)
end
I just tested that and it worked.

Code: Select all

HEX: 3466e 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498
HEX: 334ac 3 141264 c998c9d4 c844ca38 c9c0c9fc 7f26a 7f242 7f454 7f206 45e5 a498