mIRC Homepage
Posted By: amber Specific nicks for script command - 13/04/14 01:15 AM
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?
Posted By: patrickplays Re: Specific nicks for script command - 13/04/14 03:05 AM
Code:
on *:text:!coffee:#: {
 if ($nick == joe) {
  msg # blub
 } else {
  msg # blab
}
Posted By: judge2020 Re: Specific nicks for script command - 13/04/14 11:32 PM
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!
Posted By: amber Re: Specific nicks for script command - 14/04/14 01:42 AM
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
Posted By: Loki12583 Re: Specific nicks for script command - 14/04/14 02:12 AM
That's because the else needs to go on its own line

Code:
on *:text:!coffee:#: {
  if ($nick == joe) {
    msg # blub
  }
  else {
    msg # blab
  }
{
Posted By: amber Re: Specific nicks for script command - 14/04/14 02:41 AM
Thank you!! This worked. I appreciate the help!
Posted By: amber Re: Specific nicks for script command - 14/04/14 06:51 PM
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?
Posted By: judge2020 Re: Specific nicks for script command - 14/04/14 07:06 PM
under your if command
Code:
on *:TEXT:!command:#: {
THE CODE YOU SAID
}
Posted By: blessing Re: Specific nicks for script command - 15/04/14 03:01 AM
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 }
  }
}
Posted By: amber Re: Specific nicks for script command - 15/04/14 01:04 PM
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?
Posted By: Nillen Re: Specific nicks for script command - 15/04/14 01:09 PM
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.
Posted By: amber Re: Specific nicks for script command - 15/04/14 09:24 PM
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
Posted By: Nillen Re: Specific nicks for script command - 15/04/14 10:46 PM
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 }
  }
}
Posted By: blessing Re: Specific nicks for script command - 16/04/14 12:40 PM
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 }
  }
}
Posted By: Nillen Re: Specific nicks for script command - 16/04/14 02:13 PM
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
© mIRC Discussion Forums