how to fire a trigger when receive messages without newline characters?

Posted by Jcl on Tue 16 Apr 2013 09:46 AM — 11 posts, 41,553 views.

#0
When receive messages without newline characters, how can I fire a trigger?
For example, MUD server send a message "100/100> ", a second later, MUD server send another message "99/100> ", and so on.
Client will displays messages as "100/100> 99/100> ...".
I need to fire a trigger when incoming number less than "80/100> ", how can I do it?

Thanks.
#1
There's various things on the forum that answer exactly that question.

I'd like you to try and find it, for the best possible answer.

However, I'd probably use in IF statement.

"100/100" would need to be "(.+)\/100" (Regex, will use LUA as well). I don't know the full line, so you can do the matchline yourself.

if "%1" < 100 then
Note("This trigger has fired successfully.")
end -- if statement.

If you can't find what I'm talking about, please respond saying so, and I shall fetch it.

EDIT: Actually, how about <= 100 instead? That's less than or equal to.
Amended on Wed 17 Apr 2013 04:20 PM by AnalogConspiracy
USA Global Moderator #2
Quote:
There's various things on the forum that answer exactly that question.
Erm...sort of, but not well.

Jcl, if you enable the "Convert IAC EOR/GA to new line" option in Game->Configure->Output, does that break those chunks up into multiple lines?
#3
AnalogConspiracy said:

There's various things on the forum that answer exactly that question.

I'd like you to try and find it, for the best possible answer.

However, I'd probably use in IF statement.

"100/100" would need to be "(.+)\/100" (Regex, will use LUA as well). I don't know the full line, so you can do the matchline yourself.

if "%1" < 100 then
Note("This trigger has fired successfully.")
end -- if statement.

If you can't find what I'm talking about, please respond saying so, and I shall fetch it.

EDIT: Actually, how about <= 100 instead? That's less than or equal to.


Thanks for your post.
The question is not about the trigger itself, but the line has not been terminated by a newline character.
I will try OnPluginPacketReceived later.
#4
Fiendish said:

Quote:
There's various things on the forum that answer exactly that question.
Erm...sort of, but not well.

Jcl, if you enable the "Convert IAC EOR/GA to new line" option in Game->Configure->Output, does that break those chunks up into multiple lines?


Yes, it works, but only once!
Before, it displays:
Quote:

100/100> 99/100> 98/100> 97/100> 96/100> ...

After enable the "Convert IAC EOR/GA to new line" option, it displays:
Quote:

100/100>
99/100> 98/100> 97/100> 96/100> ...


I searched the forum and found OnPluginPacketReceived. I will try it later.

Thanks a lot.
Australia Forum Administrator #5
Template:faq=11
Please read the MUSHclient FAQ - point 11.
#6
Nick Gammon said:

(faq=11)


I have tried using OnPluginPacketReceived, and it worked.
But I found that parsing all packets in Lua have performance problems. It is as slow as Zmud!
Can you setup a option about whether to resolve the prompt line in C++ ?
Australia Forum Administrator #7
Can you show your plugin? A simple string replace shouldn't take that long.
#8
Nick Gammon said:

Can you show your plugin? A simple string replace shouldn't take that long.




local prompt_expr1 = ".%[256D.%[1;32m%d+/%d+.%[1;33m>%s.%[2;37;0m"
local prompt_expr2 = ".%[256D.%[1;32m(%d+)/(%d+).%[1;33m>%s.%[2;37;0m"
function OnPluginPacketReceived(sText)
	local nText = string.gsub(sText, prompt_expr1, function(s)
		local mana, hp = string.match(s, prompt_expr2)
		SetStatus("" .. mana .. "/" .. hp)
		return ""
	end)
	return nText
end -- function
Amended on Sat 20 Apr 2013 05:10 AM by Jcl
Australia Forum Administrator #9
What's the SetStatus doing there? That will take a little while. It's not the place for it.

Detect your mana in the trigger and do the SetStatus there.
#10
Nick Gammon said:

What's the SetStatus doing there? That will take a little while. It's not the place for it.

Detect your mana in the trigger and do the SetStatus there.


I need to detect mana to do something automatically, and I need to see it for do something manually.
Do you have any good suggestions?