mIRC Homepage

Checking a text event against a variable

Posted By: Xelah

Checking a text event against a variable - 22/03/10 03:10 AM

This is for a text based game I've been playing for years and wanted to create a bot to help my team. I've got it working as is, but every time the game is over, I have to recode parts of it and it's gotten very tedious as the bot has gotten much more complicated.

Every team in the game has a value that is attached to anything that affects them and my bot watches for our value and the values of our allies when the irc newsfeed posts what is going on in the game.

My event currently looks like this:
Code:
on 1:TEXT:*CM*[DKNIGHTS]*[*:#:{


[DKNIGHTS] is the value associated with my team and my bot lets us know we've just attacked someone. The problem is that [DKNIGHTS] is not always assigned to us, and the same goes for the tags assigned to our friends. The second [ is there to check to see if we are first in the line of text or second. If there isn't a [ after our tag, then it is us who have just been attacked.

I wanted to use ISIN to watch all newsfeed items that indicate an attack, but that doesn't allow me to find out what order the brackets are in and it can't tell us if we are attacking or being attacked. There is a lot of functionally meaningless gibberish between the brackets and I can't try to include that in the isin.


To try to curb this a little, I wrote a small script that lets me assign our value to a variable called %ourtag

I tried running it through like this:
Code:
on 1:TEXT:*CM*%ourtag*[*:#:{


But when I do that, mIRC reads %ourtag literally instead of the value assigned to %ourtag. Adding spaces before and after %ourtag did not help. The only way I can even get the bot to read the value is to make it not look for any other text with it.

Code:
on 1:TEXT:%ourtag:#:{


The newsfeed will never just spit out our tag, and if it did, it would be the most useless bit of info it has ever told us.

Basically, I'm looking for a way to have the script tell me when %ourtag appears in a line of text with a bracket after it and when certain letters appear at the beginning (the letters tell us what kind of attack it is and whether or not we need to worry).

Any help would be greatly appreciated.
Posted By: qwerty

Re: Checking a text event against a variable - 22/03/10 03:20 AM

Try
Code:
on 1:TEXT:$($+(*CM*,%ourtag,*[*)):#:{
Type /help $(...) for more information.
Posted By: Xelah

Re: Checking a text event against a variable - 22/03/10 03:32 AM

wow, that was easy.

On behalf of my team, Epic Thanks.
Posted By: Tomao

Re: Checking a text event against a variable - 22/03/10 03:48 AM

You can also use regex, but is a bit complicated. This strips control codes and will match %ourtag:
Code:
on $1:TEXT:$(/(\52CM\52\133\Q $+ %ourtag $+ \E\135\52\133\52)/iS):#: {
© 2021 mIRC Discussion Forums