mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2014
Posts: 7
A
amber Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Apr 2014
Posts: 7
Hi, Im sure this gets asked but I am really new to scripting. Like just a few days into it. lol I've gotten the hang of it pretty well but I'd like to ask this:

How do I get the bot to recognize a specific username?

For example: Anyone can come in and say !coffee and the bot says gives so and so a cup of coffee.

But if specifically Joe comes in and he says !coffee I'd like for the bot to say something specific about Joe and just recognize him. Like "gets Joe's favorite cup and pours coffee in it".

Does this make sense? And if so, is there a way to do this?

Joined: Mar 2014
Posts: 52
P
Babel fish
Offline
Babel fish
P
Joined: Mar 2014
Posts: 52
Code:
on *:text:!coffee:#: {
 if ($nick == joe) {
  msg # blub
 } else {
  msg # blab
}

Last edited by patrickplays; 13/04/14 03:20 AM.
Joined: Mar 2014
Posts: 215
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
Also if you'd like his username to be displayed you would put $nick somewhere in the message. If you want a punctuation right after the name you would

$+ ($nick,!) which will show as joe!


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Apr 2014
Posts: 7
A
amber Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Apr 2014
Posts: 7
Well it worked... Kind of. This is exactly what it's doing

*ambiebot gives Joe a cup of coffee in his favorite cup.
*ambiebot gives Joe a cup of coffee.

At the same time. So even though it's working, it's giving the person the customized coffee, and also the general one.

Help? lol

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
That's because the else needs to go on its own line

Code:
on *:text:!coffee:#: {
  if ($nick == joe) {
    msg # blub
  }
  else {
    msg # blab
  }
{

Joined: Apr 2014
Posts: 7
A
amber Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Apr 2014
Posts: 7
Thank you!! This worked. I appreciate the help!

Joined: Apr 2014
Posts: 7
A
amber Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Apr 2014
Posts: 7
needing just a bit more help! blush

So I got the script to work, now I'd like to do a randomization on what the general response will be. I know it's this:
Code:
var %hi = $rand(1,3)
if (%hi == 1) { msg # Hello $nick }
elseif (%hi == 2) { msg # what's up $nick }
elseif (%hi == 3) { msg # Welcome $nick }


But where do I put it? Under the coffee command, I have other commands. Do I put it directly on the next line after the coffee command, or can I put it on the bottom line under all the commands I've made thus far?

I'll explain better if this doesnt make sense. lol Basically what Im asking is where does it go?

Joined: Mar 2014
Posts: 215
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
under your if command
Code:
on *:TEXT:!command:#: {
THE CODE YOU SAID
}


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
You can improve the code like this.
Code:
on *:text:!coffee:#:{
  ; store your vip user into %vip.user variable
  var %vip.user joe dad mom sister brother

  ; check if $nick is vip.user
  if $istok(%vip.user,$nick,32) {

    ; so $nick is vip.user.. give $nick special random msg.
    var %r $rand(1,3)
    if %r == 1 { msg # blah }
    if %r == 2 { msg # bleh }
    if %r == 3 { msg # bluh }
  }
  else {
    ; not vip.user.. give $nick another random msg.

    var %r $rand(1,2)
    if %r == 1 { msg # hah }
    if %r == 2 { msg # heh }
  }
}

Joined: Apr 2014
Posts: 7
A
amber Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Apr 2014
Posts: 7
Thank you! I got that working.

Now... last thing and I'll stop pestering you, maybe! :P

Say I wanted a dark blend coffee. how would I get

!coffee dark blend

into

*ambiebot gives amber a fresh cup of dark blend coffee.

Does this make sense and if so, how do I get it to do that?

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
If your message is "!coffee dark blend", !coffee would then be $1, dark would be $2 and blend would be $3. If you want to use $2 and everything that is after in a sentence, you would put $2- in your script.
Example:
Code:
on *:text:!test*:#: {
msg # $2- 
}
User: !test to show you
Bot: to show you

So for instance,
Code:
on *:text:!coffee*:#: {
msg # /me gives $nick a fresh cup of $2- coffee.
}

Would give you the results you want.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2014
Posts: 7
A
amber Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Apr 2014
Posts: 7
That doesnt make any sense to me, can you be a bit more descriptive on where that should go, and what it should say? I'm still a newbie at this stuff. lol blush

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Code:
on *:text:!coffee*:#:{
  ; Store your vip user into %vip.user variable
  var %vip.user username username2 username3 etc
  ; Make sure there's no message after !coffee
  if ($2 == $null) {
    ; Make sure that the user is a VIP
    if $istok(%vip.user,$nick,32) {
      ; Random between 1 and 3.
      var %r $rand(1,3)
      if (%r == 1) { msg # /me gives $nick a cup of coffee in his favorite cup. | return }
      if (%r == 2) { msg # bleh | return }
      if (%r == 3) { msg # bluh | return }
    }
    ; If user isn't a VIP
    else {
    ; Random between 1 and 2.
      var %r $rand(1,2)
      if (%r == 1) { msg # /me throws a cup of coffee to $nick $+ . | return }
      if (%r == 2) { msg # heh | return }
    }
  }
  ;If another message is posted after, the above code won't go, so this goes.
  ; Make sure that the user is a VIP
  if $istok(%vip.user,$nick,32) {
    ; Random between 1 and 3.
    var %r $rand(1,3)
    if (%r == 1)  { msg # /me gives $nick a cup of $2- coffee in his favorite cup. | return }
    if (%r == 2)  { msg # bleh $2- | return }
    if (%r == 3)  { msg # bluh $2- | return }
  }
  ; If user isn't a VIP
  else {
    ; Random between 1 and 2.
    var %r $rand(1,2)
    if (%r == 1) { msg # /me throws a cup of $2- coffee to $nick $+ . | return }
    if (%r == 2) { msg # heh | return }
  }
}


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
The code can be shortened using $iif().
$iif() is same as if {..} | else {..}.

//echo $iif(%a,yes,no) is same as //if %a { echo yes } | else { echo no }
If %a has value it will echoes yes, otherwise no.

So, we simply put $iif() into the message.
msg # /me gives $nick a cup of $iif($2,$2-,$null) coffee in his favorite cup.

If $2 has value, $2- will be added to msg, otherwise nothing will be added.

Code:
on *:text:!coffee*:#:{
  ; Store your vip user into %vip.user variable
  var %vip.user username username2 username3 etc
  ; Make sure that the user is a VIP
  if $istok(%vip.user,$nick,32) {
    ; Random between 1 and 3.
    var %r $rand(1,3)
    if (%r == 1)  { msg # /me gives $nick a cup of $iif($2,$2-,$null) coffee in his favorite cup. | return }
    if (%r == 2)  { msg # bleh $2- | return }
    if (%r == 3)  { msg # bluh $2- | return }
  }
  ; If user isn't a VIP
  else {
    ; Random between 1 and 2.
    var %r $rand(1,2)
    if (%r == 1) { msg # /me throws a cup of $iif($2,$2-,$null) coffee to $nick $+ . | return }
    if (%r == 2) { msg # heh | return }
  }
}

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Oh nice! I did not actually know this. I had seen the statement before but never taken the time to read up on it properly. Thanks for the info sir smile


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Link Copied to Clipboard