mIRC Home    About    Download    Register    News    Help

Print Thread
#209837 24/02/09 07:34 AM
Joined: Jan 2008
Posts: 8
A
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2008
Posts: 8
Okay, I had like 8 different scripts, designed to reply to specific triggers in various formats, and wanted to slim it down a bit. I went to an mIRC scripting channel for assistance, and this is what I ended up with.
Code:
on *:text:*:*:{
  if ($chan == #channelone) || ($chan == #channeltwo) || ($chan == #channelthree) {
    if ((*!site* iswm $1-) || (*!website* iswm $1-)) msg $iif($chan,$chan,$nick) http://site.com
    elseif ((*!forums* iswm $1-) || (*!forum* iswm $1-)) msg $iif($chan,$chan,$nick) http://forums.site.com
  }
  elseif ($chan == #otherchan) {
    ...
  }
}

I decided to narrow down a few others, now that I (thought) I knew the syntax, and wrote this one as well.
Code:
on *:text:*:#:{ if (Test 1 isin $1-) || (test one isin $1-) { describe $chan thanks $nick } }

Only one at a time will fire, whichever one comes first will work, whichever one comes second, won't. I'm told this is because you can't have multiple wildcard triggers or some such. Now I know, I could merge the two into one line script, BUT, these two need to be separate. Is there an easier way to configure multiple text triggers for a script? or is there something I'm missing somehow?

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
on *:TEXT:*:*: {
  if ($count($chan,#channel1,#channel2,#channel3,#channel4)) {
    if ($wildtok($1-,!*site*,1,32)) { msg $iif($chan,$chan,$nick) http://site.com }
  }
  if ($wildtok($1-,!*forum*,1,32)) { msg $iif($chan,$chan,$nick) http://forums.site.com }
  elseif ($count($chan,#channel5,#channel6,#channel7,#channel8)) {
    if ($istok(test1 test2 test3 test4,$1-,32)) { describe $chan thanks $nick }
  }
}

Tomao #209842 24/02/09 02:31 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Well $count is no equivalent, as it does a wildmatch. For example "$count($chan,#test,#anotherchannel)" will trigger at a chan "#testworld" too.


To the OP:
1) Make sure you don't have identical event definitions in the same scriptfile, or only the first one will fire.
Multiple on text definitions with different matchtext- and/or target definitions in the same scriptfile are OK. And you can have (for example) two "on *:text:*:#:" events, but they mustn't be in the same scriptfile.

2) Maye sure you use if-then-else conditions properly. If you have for example:
Code:
on *:text:*:#: {
  if (($chan == #channel1) || ($chan == #channel2)) {
    if (!trigger1 isin $1-) { msg $chan Reply1 - text contained wildtext "!trigger1" somewhere }
    elseif (!trigger2 isin $1-) { msg $chan Reply2 - text did not contain wildtext "!trigger1" but contained "!trigger2" }
  }
  elseif (($chan == #channel1) || ($chan == #channel3)) {
    if ($istok($1-,!trigger2,32)) { msg $chan Reply3 - text contained "!trigger2" somewhere as separate word }
  }
}
...If someone uses !trigger2 at #channel1, nothing will happen - the elseif is not processed because the first if-condition was already met ($chan == #channel1). You may change this behaviour by using "if" instead of the "elseif"
...If a message on #channel2 contained both !trigger1 and !trigger2, you'll only have Reply1 - because the if-condition for Reply1 was met, the elseif is not processed. Again you may want to replace this "elseif" with an "if".

Yet I don't see a big advantage in merging ALL your on text events; your different text triggers don't seem to share a common routine.
Maybe merging your triggers acc. to targets is a good alternative: you can put one or more channels in the target definition, you may use wildcards, and you may use "?" to match all private messages.
Example for separate trigger acc. to targets:
(Again the "elseif" here coud be "if" to allow multiple matches/replies)
Code:
on *:text:*:#chan1,#chan2,#chan3,?: {
  if ($1 == !trigger1) { msg $iif($chan,$chan,$nick) "!trigger1" was the first word of the text }
  elseif (!trigger2 isin $1-)  { msg $iif($chan,$chan,$nick) "!trigger2" was somewhere in the text }
  elseif ($istok($1-,!trigger3,32)) { msg $iif($chan,$chan,$nick) "!trigger3" was a word somewhere in the text }
  elseif ($count($1-,!trigger4,!trigger5,!trigger6)) {
    msg $iif($chan,$chan,$nick) text contained "!trigger4" or "!trigger5"  or "!trigger6" somewhere
  }
}

on *:text:*:#channel4: {
  if ($1 == !help) { ... }
  if (...) { ... }
}

on *:text:*:#channel5,#help*,#*mIRC*: {
  (...)
}


Finally you could separate !triggers from other text events like:
Code:
on *:text:!*:*: { 
  - all your definitions where the first char is an ! -
}
on *:text:*:*: { 
  - definitions where the first char is something else -
}

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
smile Thanks much, Horstl, for your diligent explanation.

Joined: Jan 2008
Posts: 8
A
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2008
Posts: 8
So you're saying with the inclusion of a simple ! in the trigger string before the *, like so:
Code:
on *:text:!*:*:{
  if ($chan == #channelone) || ($chan == #channeltwo) || ($chan == #channelthree) {
    if ((*!site* iswm $1-) || (*!website* iswm $1-)) msg $iif($chan,$chan,$nick) http://site.com
    elseif ((*!forums* iswm $1-) || (*!forum* iswm $1-)) msg $iif($chan,$chan,$nick) http://forums.site.com
  }
}

on *:text:*:#:{ if (Test 1 isin $1-) || (test one isin $1-) { describe $chan thanks $nick } }

that both will work in the same scriptfile simultaneously?

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I don't think that's what Horstl meant, but I will leave it for him to explain further.
I would like to add that, if I may, you can have as many on text events as you like, so long they don't look the same from one another:
Code:
on *:TEXT:*!site*:*: { ... }
on *:TEXT:*!website*:*: { ... }
on *:TEXT:*!forum*:*: { ... }
on *:TEXT:*!forums*:*: { ... }
on *:TEXT:*:*: { if (Test 1 isin $1-) || (test one isin $1-) { describe $chan thanks $nick } }
The above events will work simultaneously, because the match text section of those ON TEXT events differ. You will only run into problems if all of the sections of the event are the same, or if a proceeding event has a match text section that will match those returns. This explains why your two codes won't work at the same time within the same remote.

Tomao #209878 25/02/09 12:27 PM
Joined: Jan 2008
Posts: 8
A
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2008
Posts: 8
I know, I had it 4 that would reply in PMs if PMd, and 4 that would reply in channel if it was said in the channel, and some for actions, and what not. I don't remember what all they were originally, after condensing them to that. In all honesty, when I started working on all this, I'd hoped it would be something as simple as
Code:
on *:TEXT:*!site*,*!website*:*: { ... }
and have ended up learning more scripting than I think I knew back in the v2.14 days.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Originally Posted By: Horstl
1) Make sure you don't have identical event definitions in the same scriptfile, or only the first one will fire.
Multiple on text definitions with different matchtext- and/or target definitions in the same scriptfile are OK.
Just a clarification (general reply, even if you knew this already): the rule is that only the first matching event in each file fires. This is true even if matchtexts are different. Consider this example:
Code:
on *:text:*world*:#: msg # you said WORLD
on *:text:*hello*:#: msg # you said HELLO

Matchtexts are different, yet if a person says "hello world!", the response of the script will be
Quote:
you said WORLD
and not
Quote:
you said WORLD
you said HELLO

That means if you want your hello script to always respond, you'd have to put it in a separate file (or alternatively combine the events).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Yes, but... smile
Maybe some more examples will help:
Code:
on *:text:!*:*:{
  if (bla isin $1-) || (blubb isin $1-) { echo $target Trigger1: $v1 isin $1- }
}

on *:text:*:*:{
  if (test isin $1-) { echo $target Trigger2: test isin $1- }
}

on *:text:*123*:*: { echo $target Trigger3: 123 isin $1- }

"!bla" will match the matchtext definition "!*" and the target definition "*" of Trigger1. It also matches the isin condition - output.

"!test" will match the matchtext and target definitions of Trigger1, but not the isin condition - no output.
As it already matched the definitions of Trigger1, Trigger2 will NOT be processed. (If you place Trigger2 in another scriptfile it would of course.)

"this is a test 123" will not match the definitions of Trigger1. It matches the matchtext and target definitions of Trigger2 though, and it's isin condition - output. Because it already matched a text event definition in this scriptfile, Trigger3 isn't processed.

"123" will match the matchtext and target definitions of Trigger2 , thus Trigger3 will not be processed. It didn't match the isin condition of Trigger2 though, therefore no output.

If you want to have the text "this is a test 123" produce a reply to both "test" and "123", you'll have to place them in different scriptfiles, or merge into one event:
Code:
on *:text:*:*: {
  if (test isin $1-) { echo $target test isin $1- }
  if (123 isin $1-) { echo $target 123 isin $1- }
}
Both if-conditions will be checked because no "elseif" is used here. The first output occurs by matching "test", the second output by matching "123".
________

Another set of examples, now with different target definitions (and without the text events above, or having them in another scriptfile!):
Code:
on *:text:*:#123,?: {
  if (abc isin $1-) { echo $target Trigger1: abc isin $1- }
}

on *:text:*abc*:#: { echo $target Trigger2: abc isin $1- }

on *:text:*a*:*: { echo $target Trigger3: a isin $1- }

If "abc" occurs in channel #123 or in a query, Trigger 1 will fire.
If "abc" occurs in any other channel, Trigger2 will fire.
Any other text that contains "a" will fire at Trigger3 - but only if it's NOT a query or channel #123, because Trigger 1 already "consumed" the event (matchtext and target definition did match, it's just the isin condition who failed)


___
Edit: I should check for new replies first, especially if they make it short smile

Last edited by Horstl; 25/02/09 04:50 PM.

Link Copied to Clipboard