Ok, here's an updated version (untested, but should work):
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.