mIRC Home    About    Download    Register    News    Help

Print Thread
#234347 19/10/11 04:36 PM
Joined: Oct 2011
Posts: 3
I
iFabber Offline OP
Self-satisified door
OP Offline
Self-satisified door
I
Joined: Oct 2011
Posts: 3
Hello scripters!

I'm currently making a script for my bot, but I can't get it work.
I have 2 scripts (both are not mine). And I want to combine them together. But that's where the problems start.

Well the first script is a simple !treat script. When someone types !treat this will happen.
Code:
$me is thinking...
Who should I give a treat to?
I know it!
%random-username!
$me gives %random-username %treat!


This is the whole script of that part.

Code:
on $*:text:!treat:#:{
  if (!%f) { inc -u12 %f
    :pickagain
    var %nick = $nick(#,$r(1,$nick(#,0))), %treat = beer|pie|cookie|pluspoint|ban|pizza|love
    if ($istok($me $nick,%nick,32)) { goto pickagain }
    else {
      describe # is thinking...
      .timertreat1 1 3 msg # Who should I give a treat to?
      .timertreat2 1 6 msg # I know it!
      .timertreat3 1 8 msg # %nick $+ !
      .timertreat4 1 10 describe # gives %nick $+($gettok(%treat,$r(1,$numtok(%treat,124)),124),!) 
    }
  }
}


The second script is a !give script. When you type !give (beer|pie|cookie|pluspoint|ban|pizza|love) it will give that person the treat.
Code:
$nick gave %nick-receiver a %treat. This is %nick-receiver's %ammount %treat!


Code:
%treat == beer|pie|cookie|pluspoint|ban|pizza|love
%ammount == Ammount of treats given.
%nick-receiver == Person who will get the treat.


This is the code for the !give section.
Code:
  on *:TEXT:!*:#: {

    if (!give isin $1-) && (!$4) {

      if ($2 ison $chan) { set %nick-receiver $2 }
      elseif ($3 ison $chan) { set %nick-receiver $3 }
      else { set %nick-receiver $nick }

      if (%nick-receiver == $me) { .timer 1 2 msg # Thank you $nick :) }

      if (cookie isin $1-) { set %cookie [ $+ [ %nick-receiver ] ] $calc(%cookie [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a cookie. This is %nick-receiver $+ 's $ord( %cookie [ $+ [ %nick-receiver ] ] ) cookie. | halt }
      elseif (pie isin $1-) { set %pie [ $+ [ %nick-receiver ] ] $calc(%pie [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a hot apple pie. This is %nick-receiver $+ 's $ord( %pie [ $+ [ %nick-receiver ] ] ) pie. | halt }
      elseif (beer isin $1-) { set %beer [ $+ [ %nick-receiver ] ] $calc(%beer [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a beer. This is %nick-receiver $+ 's $ord( %beer [ $+ [ %nick-receiver ] ] ) beer. | halt }
      elseif (pluspoint isin $1-) { set %pluspoint [ $+ [ %nick-receiver ] ] $calc(%pluspoint [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave2 %nick-receiver a pluspoint. This is %nick-receiver $+ 's $ord( %pluspoint [ $+ [ %nick-receiver ] ] ) pluspoint. | halt }
      elseif (ban isin $1-) { set %ban [ $+ [ %nick-receiver ] ] $calc(%ban [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a ban. This is %nick-receiver $+ 's $ord( %ban [ $+ [ %nick-receiver ] ] ) ban. | halt }
      elseif (pizza isin $1-) { set %pizza [ $+ [ %nick-receiver ] ] $calc(%pizza [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a hot large pizza. This is %nick-receiver $+ 's $ord( %pizza [ $+ [ %nick-receiver ] ] ) pizza. | halt }
      elseif (love isin $1-) { set %love [ $+ [ %nick-receiver ] ] $calc(%love [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver love. This is the $ord( %love [ $+ [ %nick-receiver ] ] ) one who loves %nick-receiver | halt }
    }
  }


Well, as I said. I wanna combine these 2 scripts.
I want to link the !treat to !give.
So when the bot picks a name to give the treat to, the bot will use the !give command to give it.
But I can't figure out how.

Can someone please help me?
And I'm new to mIRC scripting. So please explain it too laugh

Grtz. iFabber

iFabber #234349 19/10/11 06:27 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, you could just have them in two separate script files and they'd work fine. But if you want them together... a simple ELSEIF suffices:

Code:
on *:TEXT:!*:#: {
  if (!give isin $1-) && (!$4) {
    if ($2 ison $chan) { set %nick-receiver $2 }
    elseif ($3 ison $chan) { set %nick-receiver $3 }
    else { set %nick-receiver $nick }
    if (%nick-receiver == $me) { .timer 1 2 msg # Thank you $nick :) }
    if (cookie isin $1-) { set %cookie [ $+ [ %nick-receiver ] ] $calc(%cookie [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a cookie. This is %nick-receiver $+ 's $ord( %cookie [ $+ [ %nick-receiver ] ] ) cookie. | halt }
    elseif (pie isin $1-) { set %pie [ $+ [ %nick-receiver ] ] $calc(%pie [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a hot apple pie. This is %nick-receiver $+ 's $ord( %pie [ $+ [ %nick-receiver ] ] ) pie. | halt }
    elseif (beer isin $1-) { set %beer [ $+ [ %nick-receiver ] ] $calc(%beer [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a beer. This is %nick-receiver $+ 's $ord( %beer [ $+ [ %nick-receiver ] ] ) beer. | halt }
    elseif (pluspoint isin $1-) { set %pluspoint [ $+ [ %nick-receiver ] ] $calc(%pluspoint [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave2 %nick-receiver a pluspoint. This is %nick-receiver $+ 's $ord( %pluspoint [ $+ [ %nick-receiver ] ] ) pluspoint. | halt }
    elseif (ban isin $1-) { set %ban [ $+ [ %nick-receiver ] ] $calc(%ban [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a ban. This is %nick-receiver $+ 's $ord( %ban [ $+ [ %nick-receiver ] ] ) ban. | halt }
    elseif (pizza isin $1-) { set %pizza [ $+ [ %nick-receiver ] ] $calc(%pizza [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver a hot large pizza. This is %nick-receiver $+ 's $ord( %pizza [ $+ [ %nick-receiver ] ] ) pizza. | halt }
    elseif (love isin $1-) { set %love [ $+ [ %nick-receiver ] ] $calc(%love [ $+ [ %nick-receiver ] ] + 1) | msg # $nick gave %nick-receiver love. This is the $ord( %love [ $+ [ %nick-receiver ] ] ) one who loves %nick-receiver | halt }
  }
  elseif ($1 == !treat) {
    if (!%f) { inc -u12 %f
      :pickagain
      var %nick = $nick(#,$r(1,$nick(#,0))), %treat = beer|pie|cookie|pluspoint|ban|pizza|love
      if ($istok($me $nick,%nick,32)) { goto pickagain }
      else {
        describe # is thinking...
        .timertreat1 1 3 msg # Who should I give a treat to?
        .timertreat2 1 6 msg # I know it!
        .timertreat3 1 8 msg # %nick $+ !
        .timertreat4 1 10 describe # gives %nick $+($gettok(%treat,$r(1,$numtok(%treat,124)),124),!) 
      }
    }
  }
}


Now, that gives you a basic script. I'll give you a cleaned up script in a few minutes...


Invision Support
#Invision on irc.irchighway.net
Riamus2 #234350 19/10/11 06:53 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Riamus2, I believe ifabber wants those two scripts combined to perform the treat and give automatically within the same function, not just combine them to work individually:
Quote:
I want to link the !treat to !give. So when the bot picks a name to give the treat to, the bot will use the !give command to give it.

Riamus2 #234351 19/10/11 07:06 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, here's an updated version (untested, but should work):
Code:
on *:TEXT:*:#: {
  tokenize 32 $strip($1-)
  if ($1 == !give) && (!$4) {
    if (%f) { halt }
    set -u12 %f On
    if ($2 ison $chan) { var %nick-receiver = $2, %gift = $3 }
    elseif ($3 ison $chan) { var %nick-receiver = $3, %gift = $2 }
    else { var %nick-receiver = $0, %gift = $2 }
    if (%nick-receiver == $me) { .timer 1 2 msg # Thank you $nick :) }
    if ($istok(cookie pie beer pluspoint ban pizza love,%gift,32)) {
      var %count = $readini(gifts.ini,%nick-receiver,%gift)
      inc %count
      writeini -n gifts.ini %nick-receiver %gift %count
      var %gift = $replace(%gift,pie,hot apple pie,pizza,hot large pizza)
      if (%gift = love) { msg $chan $nick gave %nick-receiver love. This is the $ord(%count) one who loves %nick-receiver $+ . }
      else { msg $chan $nick gave %nick-receiver %gift $+ .  This is %nick-receiver $+ 's $ord(%count) %gift $+ . }
    }
  }
  elseif ($1 == !treat) {
    if (%f) { halt }
    set -u12 %f On
    var %nick = $nick(#,$r(1,$nick(#,0))), %treat = beer|pie|cookie|pluspoint|ban|pizza|love
    while (%nick == $me || %nick == $nick) { var %nick = $nick(#,$r(1,$nick(#,0))) }
    describe # is thinking...
    .timertreat1 1 3 msg # Who should I give a treat to?
    .timertreat2 1 6 msg # I know it!
    .timertreat3 1 8 msg # %nick $+ !
    .timertreat4 1 10 describe # gives %nick $+($gettok(%treat,$r(1,$numtok(%treat,124)),124),!) 
  }
}


Explanation:
We're starting by stripping the control codes from the text using tokenize. Note that you can do this on the event line as well. I just put it here because it's easier to see what is happening. Next, we have the IF/ELSEIF to decide which "command" is used (!treat or !give). In the !give section, we start out with flood control (this is the same in the !treat section). I used /set instead of /inc from personal preference and instead of indenting everything even further, I just halt the script if %f is set instead of checking if it's not set. Then we set the receiver and gift variables. By setting the gift at the same time you're setting the receiver, it saves time later. Also, we're going to use /var instead of /set so the variable is local. You really don't need it to remain set after the command is finished. As you already had, it will send a thank you if you $me is the receiver. Next, we're going to see if the gift is a valid gift. You can add additional gifts to this line if you want to at a later time. Separate them by spaces like the rest.

Now, here's a change. We're going to store these in an INI file instead of as variables. You normally don't want to use dynamic variables for anything that will create a LOT of different variables. Because the nick is part of the variable name, you could easily end up with hundreds of variables for each gift and that really isn't a good idea. By using an INI file, you avoid that entirely. So this next part looks to see what the current count is for the gift to that receiver and then increments it by 1. Note that if the receiver had never received that gift, the increment would make it equal to 1. We then write the new count to the INI file so it's there for the next time.

The $replace() part is there to allow for a shorter overall code. Most of your message lines are the same format, but some gifts are given more words. Instead of writing each line separately, you can save time by doing this. The $replace() will only need gifts that have additional words when displayed (pie becomes hot apple pie, pizza becomes hot large pizza). Anything that remains as-is doesn't need to be included in the $replace(). If you add more gifts later, you will want to use this as necessary for similar gifts.

The next IF/ELSE part is because the gift of love is displayed differently than all other gifts, so we do have to have a separate message line for that one. All other gifts use a single message line.

Now, for the !treat section, we again start with flood control. After that, I replaced the goto with a while loop. The rest remained the same.

With both commands, you can easily add additional gifts by editing only a few lines by using this method... the list of gifts lines (one for !treat and one for !gift) and possibly the $replace() line for !gift. The only other thing that you may need to add is another IF/ELSEIF/ELSE line like is done for love if you want a completely different display of the gift. But for most, that shouldn't be necessary.


Invision Support
#Invision on irc.irchighway.net
Tomao #234352 19/10/11 07:07 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
@Tomao: Oops, you're right. I missed that. I'll edit the script to do that.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #234353 19/10/11 07:13 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, here's the fixed version that allows !treat to do a !gift. It's the same explanation as before, but the gift part is in an alias so it can be done from both !gift and !treat without duplicating the code in both sections.

Code:
on *:TEXT:*:#: {
  tokenize 32 $strip($1-)
  if ($1 == !give) && (!$4) {
    if ($2 ison $chan) { var %nick-receiver = $2, %gift = $3 }
    elseif ($3 ison $chan) { var %nick-receiver = $3, %gift = $2 }
    else { var %nick-receiver = $0, %gift = $2 }
    if (%nick-receiver == $me) { .timer 1 2 msg # Thank you $nick :) }
    givegift %nick-receiver %gift
  }
  elseif ($1 == !treat) {
    if (!%f) {
      set -u12 %f On
      var %nick = $nick(#,$r(1,$nick(#,0))), %treat = beer|pie|cookie|pluspoint|ban|pizza|love
      while (%nick == $me || %nick == $nick) { var %nick = $nick(#,$r(1,$nick(#,0))) }
      describe # is thinking...
      .timertreat1 1 3 msg # Who should I give a treat to?
      .timertreat2 1 6 msg # I know it!
      .timertreat3 1 8 msg # %nick $+ !
      .timertreat4 1 10 givegift %nick $gettok(%treat,$r(1,$numtok(%treat,124)),124)
    }
  }
}

alias givegift {
  if ($istok(cookie pie beer pluspoint ban pizza love,$2,32)) {
    var %count = $readini(gifts.ini,$1,$2)
    inc %count
    writeini -n gifts.ini $1 $2 %count
    var %gift = $replace($2,pie,hot apple pie,pizza,hot large pizza)
    if (%gift = love) { msg $chan $nick gave $1 love. This is the $ord(%count) one who loves $1 $+ . }
    else { msg $chan $nick gave $1 %gift $+ .  This is $1 $+ 's $ord(%count) %gift $+ . }
  }
}


Btw, you can unset your variables that are no longer used (this does clear your current counts. If you want to save those, it will require some extra work):

/unset %nick-receiver
/unset %cookie*
/unset %pie*
/unset %beer*
/unset %pluspoint*
/unset %ban*
/unset %pizza*
/unset %love*


Also, a note on flood control. You can place a single flood control at the start of the script instead of one for each command. However, doing so may or may not be desirable depending on your needs. For example, having it at the beginning will make it so you can use only one or the other command once every 12 seconds. Having it separate lets you use each command once every 12 seconds. Having them separate also lets you set different times on the flood control if you want, or disable the flood control for one of them. It's entirely up to you.

Last edited by Riamus2; 19/10/11 07:20 PM.

Invision Support
#Invision on irc.irchighway.net
iFabber #234434 25/10/11 05:45 AM
Joined: Oct 2011
Posts: 3
I
iFabber Offline OP
Self-satisified door
OP Offline
Self-satisified door
I
Joined: Oct 2011
Posts: 3
Thanks!

As I said before. I'm a newbie at mIRC scripting. I know some basic things etc. Also both scripts are not mine. So I don't know each function in the script.

But thanks for explaining it!
My problem is solved now laugh

iFabber #234481 27/10/11 03:08 PM
Joined: Oct 2011
Posts: 3
I
iFabber Offline OP
Self-satisified door
OP Offline
Self-satisified door
I
Joined: Oct 2011
Posts: 3
I'm sorry to say it.
But the script doesn't work as it supposed to do.

When I type !give %gift. This is the message from my bot.
Code:
iFabber gave 2 a %gift. This is 2's 2nd cookie.


And when I type !give love. This is the message.
Code:
iFabber gave $nick a beer. This is $nick's 1st beer.


Also when you type !treat the last sentence doesn't appear.
So Bot is thinking, Who should I give a treat to? I know it! %nick-receiver! And then nothing.
But what should happen is that the bot gives the treat via !give %gift.

I don't know what's wrong...

This is the edited script. I edited some things because there were some typing errors.

Code:
on *:TEXT:*:#: {
  tokenize 32 $strip($1-)
  if ($1 == !give) && (!$4) {
    if ($2 ison $chan) { var %nick-receiver = $2, %gift = $3 }
    elseif ($3 ison $chan) { var %nick-receiver = $3, %gift = $2 }
    else { var %nick-receiver = $0, %gift = $2 }
    if (%nick-receiver == $me) { .timer 1 2 msg # Thank you $nick :) }
    givegift %nick-receiver %gift
  }
  elseif ($1 == !treat) {
    if (!%f) {
      set -u12 %f On
      var %nick = $nick(#,$r(1,$nick(#,0))), %treat = beer|pie|cookie|pluspoint|ban|pizza|love
      while (%nick == $me || %nick == $nick) { var %nick = $nick(#,$r(1,$nick(#,0))) }
      describe # is thinking...
      .timertreat1 1 3 msg # Who should I give a treat to?
      .timertreat2 1 6 msg # I know it!
      .timertreat3 1 8 msg # %nick $+ !
      .timertreat4 1 10 givegift %nick $gettok(%treat,$r(1,$numtok(%treat,124)),124)
    }
  }
}

alias givegift {
  if ($istok(cookie pie beer pluspoint ban pizza love,$2,32)) {
    var %count = $readini(gifts.ini,$1,$2)
    inc %count
    writeini -n gifts.ini $1 $2 %count
    var %gift = $replace(beer,pie,cookie,pluspoint,ban,pizza,love)
    if (%gift = love) { msg $chan $nick gave $1 love. This is the $ord(%count) one who loves $1 $+ . }
    else { msg $chan $nick gave $1 %gift $+ .  This is $1 $+ 's $ord(%count) %gift $+ . }
  }
}

iFabber #234486 27/10/11 03:41 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Sorry, made a mistake when I was changing around something I had written.

Change:
Code:
    else { var %nick-receiver = $0, %gift = $2 }


To:
Code:
    else { var %nick-receiver = $nick, %gift = $2 }


As far as !treat, put an echo at the top of the givegift alias...
Code:
alias givegift {
  echo -a Data: $1-


Then do !treat and see what appears after Data:. You should have a nick as well as a gift and the gift must be in the list of gifts in the alias. Let me know your results.

Edit: Also, it looks like you changed this line:
Code:
    var %gift = $replace(beer,pie,cookie,pluspoint,ban,pizza,love)


You need to change it back to what it was. If you don't want "pie" to become "hot apple pie" and "pizza" to become "hot large pizza", then you can change each of those to whatever you want. But you can't change it the way you did. If there is a reason you made that change, please explain it and I'll help you to change it.

Last edited by Riamus2; 27/10/11 03:58 PM.

Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard