mIRC Homepage
Posted By: ToRmEnTeD talking script - 27/10/08 09:40 PM
Hey i am not good at this scripting stuff but i am trying to get a command to work so that when a users says a "keyword" it would trigger a response from the bot.
Seen them in some channels before that do what i want.

Heres what i been trying to play around with. I figured i could just make alot of them and it would work,

Code:

on 1:text:beer:#:describe $chan hands $$1 a Ice Cold Budweiser

 


and it displays results as

[5:40pm] * @ToRmEnTeD hands beer a Ice Cold Budweiser

well this does kinda work but it wont say the users name and it just seems a bit odd working....I need this to stay simple because i am well...very new at this.

If i could get someone to make me a example line that works likle that i would greatly apprecate it. Im just wanting to make a big list of them to add to my PNP script.
Thanks to anyone who helps
Posted By: RoCk Re: talking script - 27/10/08 09:44 PM

Code:

on *:TEXT:beer *:#: {
  if ($1 == $null) describe # hands $nick an Ice Cold Budweiser.
  elseif ($1 !ison #) describe # hands an Ice Cold Budweiser to the non-existent $1 and it falls to the floor.
  else describe # hands $nick(#,$nick(#,$1)) an Ice Cold Budweiser.
}

Posted By: ToRmEnTeD Re: talking script - 27/10/08 09:50 PM
that as is should work ? I get nothing from it at all that i can see
Posted By: ToRmEnTeD Re: talking script - 27/10/08 09:50 PM
wait let me check the edited one
Posted By: ToRmEnTeD Re: talking script - 27/10/08 09:53 PM
Yeah i still get nothing frown
Do i need to change anything first?
Posted By: RoCk Re: talking script - 27/10/08 09:55 PM

Sorry, this works.

Code:

on *:TEXT:beer*:#: {
  if ($2 == $null) describe # hands $nick an Ice Cold Budweiser.
  elseif ($2 == $me) {
    msg # Thank you sir, don't mind if I do. :-)
    describe # opens himself an Ice Cold Budweiser.
  }
  elseif ($2 !ison #) describe # hands an Ice Cold Budweiser to the non-existent $2 and it falls to the floor.
  else describe # hands $nick(#,$nick(#,$2)) an Ice Cold Budweiser.
}

Posted By: Horstl Re: talking script - 27/10/08 10:03 PM
You cannot use the space in the matchtext definition for a match of "beer" only...

Code:
on *:text:*:#: {

  ; first word is beer
  if ($1 == beer) {
    ; second paramater is a nick on this channel. give the beer to him, thanks to $nick
    if ($2 ison $chan) { describe $chan hands $2 a beer - salute to $nick $+ ! }

    ; second parameter is no nick on this channel, but there's a second parameter. spoil the beer.
    elseif ($2) { describe $chan hands a beer to the non-existant $2 and it falls to the floor. }

    ; no second parameter. plain beer.
    else { describe $chan hands $nick a beer. }
  }

  ; first word is peanuts
  elseif ($1 == peanuts) {
    ; something with another first word: peanuts
  }
}


EDIT: nevermind, you fixed it wink
Posted By: RoCk Re: talking script - 27/10/08 10:04 PM

I found that. I didn't realize I had put a space there, but thanks.
Posted By: ToRmEnTeD Re: talking script - 27/10/08 10:30 PM
yup that worked perfect. very nice work thanks to the both of you. Only leaves me with one question. Do i need to add anything if i wana drop down and add another one below it? or do i just keep stacking them as is ?
Posted By: Horstl Re: talking script - 27/10/08 10:49 PM
You can add more than one "on text" event in the same scriptfile.

on *:TEXT:beer*:#: { some code }
on *:TEXT:wine*:#: { some other code }
... this would work.

Now, if you decide to use my approach instead (and merge different things in one on-text-event):
You just cannot have an identical on text event in the same scriptfile (not a second on *:TEXT:*:#: { codes for if ($1 == beer) etc } ).
With "identical event" I mean identical in all three of <level>:TEXT:<matchtext>:<target>:<commands>
Separate scriptfiles with identical event definitions would work, but the idea was to use one event for all your "bar activities" smile
Posted By: Tomao Re: talking script - 27/10/08 11:00 PM
Yes, you can add as many words as you like to be triggered as shown below in red, based on Horstl's code. smile

Quote:

on *:TEXT:*:#: {
if ($1 == beer) || ($1 == soda) || ($1 == wine) {
if ($2 ison $chan) { describe $chan hands $2 a $1 - salute to $nick $+ ! }
elseif ($2) { describe $chan hands a $1 to the non-existant $2- and it falls to the floor. }
else { describe $chan hands $nick a $1 $+ . }
}
}


- a little bug. Edited.
Posted By: ToRmEnTeD Re: talking script - 28/10/08 09:59 PM
Ok so i ran into an issue pretty quick here. The code works exactly how i asked...however me being a newb bit me in my ass. I made one that says Hello to a user when a user types Hello....
During my test this worked fine..However once it was running in the room is soon realised that is was a problem.
Someone says Hello. the bot says Hello back...but then..lol
the people in the channel say hello to the user and guess what?
lol the script says hello to everyone that says hello back...
frown I never ever thought of that...
I have seen channels that have bots that do this kinda thing and done seem to have these issues so what would be the best way to fix these types of issues?
However
Posted By: RusselB Re: talking script - 28/10/08 10:20 PM
One option is to only reply if the name of the bot is included.
Eg. converstaion where Tormented is the bot
Quote:
<RusselB> Hello Tormented
<Tormented> Hello RusselB
<Frank> Hey there RusselB
<RusselB> ^5's Frank


Another option, is to set a variable, so that the bot only responds to the same command if issued more than a minute apart.

There are probably other options, but those are the first two that occur to me.
Posted By: ToRmEnTeD Re: talking script - 28/10/08 11:12 PM
hmm I tried to do it with my nick and i cant seem to get it to trigger....but i have not been able to get any thing thats more than 1 word to trigger.

Code:

on *:TEXT:hello ToRmEnTeD*:#: {
  if ($2 == $null) describe # Hello $nick Hows it going ? :)

}



 


Thats how it is on my script
Posted By: RusselB Re: talking script - 29/10/08 12:11 AM
Change $2 to $3 as your matchtext section of the ON TEXT event will recognize hello as $1 and ToRmEnTeD as $2

Also, just in case you weren't aware of this, it's impossible for you to trigger your own ON TEXT events, so if you are running the code, someone else will have to send the message "hello Tormented" (without the quotes) for the script to trigger..
Posted By: Tomao Re: talking script - 29/10/08 01:50 AM
Code:
on *:TEXT:*:#: {
  var %x = /^(hello|hey|hi)\s $+ $me $+ /Si
  if ($regex($1-,%x)) { describe # Hello $nick $+ , hows it going ? :) }
}


You can use $regex to achieve this. You can add more greeting words to it as shown above.

This script will only be triggered when your name is being greeted, as in:

Hello ToRmEnTeD, Hey Tormented or hi tormented
Posted By: Tomao Re: talking script - 29/10/08 04:47 AM
You can also do it this way:

Code:
on $*:TEXT:/^(hey|hello|hi)\s(ToRmEnTeD)$/Si:#: { describe # Hello $nick $+ , hows it going ? :) }
Posted By: RusselB Re: talking script - 29/10/08 06:05 AM
I admit I'm still learning about regex, but wondered if something similar could be done so that it responds with one message if my nick had -afk attached to it, but a different message if it didn't.

To the OP, sorry to horn in on your topic, but this got me wondering.
Posted By: ToRmEnTeD Re: talking script - 29/10/08 09:09 AM
Originally Posted By: Tomao
You can also do it this way:

Code:


on $*:TEXT:/^(hey|hello|hi)\s(ToRmEnTeD)$/Si:#: { describe # Hello $nick $+ , hows it going ? :) }






hey ...IT WORKS! smile Thanks man!
Posted By: Tomao Re: talking script - 29/10/08 11:07 PM
RusselB, can you please give an example of what you've wondered about in your question?
Posted By: RusselB Re: talking script - 30/10/08 04:49 AM
Code:
on *:TEXT:*:#: {
  var %x = /^(hello|hey|hi)\s $+ $me $+ /Si
  if ($regex($1-,%x)) {
    if $right($me,4) != -afk {
      describe # Hello $nick $+ , hows it going ? :)
    }
    else {
      describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :)
  }
}

This works, just wondered if there was a better way to do it, such as having it all in the ON TEXT event, or if it makes any difference.
Posted By: Tomao Re: talking script - 30/10/08 09:21 PM
Nice one, RusselB. It works very well. I made a previous post attempting to use something else but to no avail, compared to yours.

However, the var can be omitted and gathered in the on text event as such:

Code:
on $*:TEXT:$(/^(hello|hey|hi|hello,|hey,|hi,)\s( $+ $me $+ )$/Si):#: {
  if ($regex($1-,$regml(2))) { if ($right($me,4) != -afk) { describe # Hello $nick $+ , hows it going ? :) }
    else { describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :) }
  }
}


Comma match is added in case people use hi, <nickname> instead of hi <nickname>
Posted By: DJ_Sol Re: talking script - 30/10/08 10:17 PM
Well I used a testing script I got off of here last year to test the evaluation time of different identifiers and comparisons. The conclusion was that 'isin' was actually the fastest. I also found using "else" is slower than alternative methods.

Code:
on *:TEXT:*:#:{
  if ($1 isin hi.hello.hey) && ($2 == $me) {
    if {$right($me,4) == -afk) { describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :) | return }
    describe # Hello $nick $+ , hows it going ? :)
  }
}


Something I have to ask though is about the -afk. If you are indeed afk this would require the user to say Hey -afkRusselB ! Also, no punctuation afterwards would be allowed. Hey RusselB! wouldnt work since $2 is RusselB! and not $me which is RusselB.

Any thoughts about this?
Posted By: Tomao Re: talking script - 30/10/08 11:11 PM
I believe his away nickname is RusselB-afk

Code:
//echo -a $right(ResselB-afk,4)


I think regex works decently well in this case for matching purposes. I have addressed the ! and . punctuation so that people can call hi RusselB! or hi, RusselB. or Hi russellb or without any. The nickname being called is not case sensitive because of /i modifier.

And it will not trigger when someone calls out in this fashion: hi russelb <followed by words>

Code:
on $*:TEXT:$(/^(hello|hey|hi|hello,|hey,|hi,)\s( $+ $me $+ )(!|.|)$/Si):#: {
  if ($regex($1-,$regml(2))) { if ($right($me,4) != -afk) { describe # Hello $nick $+ , hows it going ? :) }
    else { describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :) }
  }
}
Posted By: DJ_Sol Re: talking script - 31/10/08 02:27 AM
Yeah thats a good use of regex.
© mIRC Discussion Forums