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.