mIRC Home    About    Download    Register    News    Help

Print Thread
#181492 24/07/07 06:30 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Hello all,

I want to make the triggers of my scripts somewhat smarter.
At the moment, all my scripts use !trigger and then result with a channel message / pm message or whatever.
Depending on what I programmed.

Now, I want to give the user that choice.
So, every command will have 3 different ways of triggering and 3 different ways of responding.

Example:
!test = msg $chan Test is successfull.
-test = msg $nick Test is successfull.
.test = notice $nick Test is successfull.

Now I tested a little, but don't get anywhere.
Code:
alias prefix return -,!,.

alias transmit {
  if ($left($1,1) == !) { msg $chan $2- }
  elseif ($left($1,1) == -) { msg $nick $2- }
  elseif ($left($1,1) == -) { notice $nick $2- }
}

on *:TEXT:$+($prefix,test):#my-chan:{
  transmit Test was a success!
}


Does anyone have idea's on this?
Thanks in advance!

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Changes highlighted:
Quote:
alias prefix return -,!,.

alias transmit {
if ($left($1,1) == !) { msg $chan $2- }
elseif ($left($1,1) == -) { msg $nick $2- }
elseif ($left($1,1) == -) { notice $nick $2- }
}

on *:TEXT:$($+($prefix,test)):#my-chan:{
transmit $1 Test was a success!
}


Note that you have to pass the trigger to the transmit alias in order for it to check its value.

Edit: Didn't read the post correctly. Ignore the above and read qwerty's reply.

Last edited by starbucks_mafia; 24/07/07 08:18 PM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
alias _prefix return -,!,.

alias transmit {
  if ($left($1,1) == !) { echo -a msg $chan $2- }
  elseif ($left($1,1) == -) { echo -a msg $nick $2- }
  elseif ($left($1,1) == .) { echo -a notice $nick $2- }
}

On *:Text:*:#my-chan: {
  if ($istok($_prefix,$left($1,1),44)) {
    if ($mid($1,2-) == test) transmit $1 Test was a success!
  }
}


I changed the $prefix identifier to $_prefix as mIRC already uses that identifier.

Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Thanks for the responses guys.
I don't get it to work yet though.

@Sladekraven: I would like to make the comparison in the event syntax already, because otherwise I would have to re-code all my scripts. Plus I try to use on:TEXT:*:#:{ as little as possible. Since it limits the script to only that one event.

At the moment I use:
Code:
alias _prefix return -,!,.

alias transmit {
  if ($left($1,1) == !) { msg $chan $2- }
  elseif ($left($1,1) == -) { msg $nick $2- }
  elseif ($left($1,1) == .) { notice $nick $2- }
}

on *:TEXT:$($+($_prefix,test)):#my-chan:{
  transmit $1 Test was a success!
}


Do you know how to get this part to work: $($+($_prefix,test))
Because that aint working atm.

Thx again!

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The only way to match alternative strings in the event header is to use either a custom identifier (returning "*" conditionally) or regex. Here's an example of the latter:
Code:
alias _prefix return -!.

alias transmit {
  if ($1 == !) { msg $chan $2- }
  elseif ($1 == -) { msg $nick $2- }
  elseif ($1 == .) { notice $nick $2- }
}

on $*:TEXT:$($+(/^[,$_prefix,]test/iS)):#my-chan:{
  transmit $left($1,1) Test was a success!
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #181498 24/07/07 08:20 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Hmm, yeah this is working briljanlty, but the regex pattern is rather complicated. And since I will be using this technique for almost all my current and upcoming codes, I prefer something simpler.

Could you point out how that custom identifier variant would look like?

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
How is it complicated?

Change the test in the regex pattern to the word you want.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Code:
alias _prefix return -!.

alias prefixcheck if (?test iswm $1 && $left($1,1) isin $_prefix) return *

alias transmit {
  if ($1 == !) { msg $chan $2- }
  elseif ($1 == -) { msg $nick $2- }
  elseif ($1 == .) { notice $nick $2- }
}

on *:TEXT:$($prefixcheck($1)):#my-chan:{
  transmit $left($1,1) Test was a success!
}
So $prefixcheck($1) examines the first word and if that matches, the identifier returns "*", thus making the event itself match. Otherwise it (implictly) returns $null, which makes the event fail.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
True, alright I can live with that.
But is it compatible also with things like:
test*
test *

?

If so, its easy enough indeed.

Thx!

qwerty #181504 24/07/07 08:37 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Hmmm, alright clear qwerty. Thank you very much.
But basicly that will limit the flexibility even more, because all "triggers" have to be in the prefix-check alias.

I guess the best option is to go for the regex version.
And if it's as simple as Sladekraven says it is, it should be fine \o/

Thx a lot guys, appreciate the help once again grin

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
"Plus I try to use on:TEXT:*:#:{ as little as possible. Since it limits the script to only that one event."

Don't limit yourself.

Code:
on *:text:Hello:#:{ }
on *:text:Goodbye:#:{ }
on *:text:*:#:{
if ($1 == blah) { }
elseif ($1-2 == Hello Bot) { }
 }


this is valid and works in the same script.

DJ_Sol #181534 25/07/07 08:29 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Yeah I do understand that, but I try to keep my scripts as logical as possible. With the best chronological order in my opinion. And usually such an on TEXT event without limitation, doesn't belong at the end of the file.

But still, qwerty's solution is working great so far, except for timers and for example /play commands... but hey... I'm happy grin

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
There's nothing illogical about DJ_Sol's post.

The way it works (just for those who might be reading this and don't understand, not as an insult to your intelligence, OrionsBelt), is like this

Code:
on *:text:Hello:#:{
;do these commands if the person has entered the word Hello
;otherwise check the next ON TEXT event
}
on *:text:Goodbye:#:{
;do these commands if the person has entered the word Goodbye
;otherwise check the next ON TEXT event
}
on *:text:*:#:{
;this will catch any and all text entries that haven't already been matched.
  if ($1 == blah) { }
  elseif ($1-2 == Hello Bot) { }
}



Link Copied to Clipboard