Cookies!

By darkly57 on Apr 21, 2010

This is just a simple fun script that lets you give and take away cookies.

This wasn't meant to be a serious script, Just made it for my friend to prove I could :P

Thanks jsg55 for the $newnick thing ^_^

Right click a nickname in chat and/or nicklist and it will be in the menu.

I know this probably could have been done a lot easier, I just prefer doing things the longer way :P

menu query,nicklist {
  Cookie
  .Give Cookies:{
    if ($readini(cookies.ini, cookies, $1) != $null) {
      set %g.cookies $$?="Number of cookies to give?"
      writeini cookies.ini cookies $1 $calc($readini(cookies.ini, cookies, $1 + %g.cookies $+ ))
      DESCRIBE $chan has given %g.cookies cookies to $1 $+ , $1 now has $readini(cookies.ini, cookies, $1) cookies!
    }
    else {
      writeini cookies.ini cookies $1 0
      set %g.cookies $$?="Number of cookies to give?"
      writeini cookies.ini cookies $1 $calc($readini(cookies.ini, cookies, $1 + %g.cookies $+ ))
      DESCRIBE $chan has given %g.cookies cookies to $1 $+ , $1 now has $readini(cookies.ini, cookies, $1) cookies!
    }
  }
  .Take Cookies:{
    if ($readini(cookies.ini, cookies, $1) != $null) {
      set %t.cookies $$?="Number of cookies to take?"
      writeini cookies.ini cookies $1 $calc($readini(cookies.ini, cookies, $1 - %t.cookies $+ ))
      DESCRIBE $chan has taken %t.cookies cookies away from $1 $+ , $1 now has $readini(cookies.ini, cookies, $1) cookies!
    }
    else {
      writeini cookies.ini cookies $1 0
      set %t.cookies $$?="Number of cookies to take?"
      writeini cookies.ini cookies $1 $calc($readini(cookies.ini, cookies, $1 - %t.cookies $+ ))
      DESCRIBE $chan has taken %t.cookies cookies away from $1 $+ , $1 now has $readini(cookies.ini, cookies, $1) cookies!
    }
  }
}

on *:nick: { 
  if ($readini(cookies.ini, cookies, $nick) != $null) {
    var %x $readini(cookies.ini, cookies, $nick)
    remini cookies.ini cookies $nick
    writeini cookies.ini cookies $newnick %x
  }
}

Comments

Sign in to comment.
gooshie   -  Apr 24, 2010

WorldDMT
Yes, I understand all that and yet it won't affect 'accuracy' (once in awhile someone gets cookies and then has them taken away until they have zero and then change nicks). This script is gonna end up with a big pile of broke after awhile anyway. It's never gonna really be able to accurately keep track of cookies over any period of time anyway with people changing nicks, leaving, coming back as their original nick etc. More than anything else it needs a 'once a month empty the data file' routine.

 Respond  
WorldDMT   -  Apr 24, 2010

@gooshie:> if %x { is the same as if (%x != $null) {

wrong that can work in this code but it's never same try this

set %var 0

//if (%var) echo -a true | else echo -a not
//if (%var != $null) echo -a true | else echo -a not

0 is not empty

 Respond  
Bielie   -  Apr 22, 2010

no but its kwooll :D

 Respond  
darkly57   -  Apr 22, 2010

Yes...But that's not the point of this script. And I don't even think thats my original script..

That doesn't do the same thing as mine.

 Respond  
Bielie   -  Apr 22, 2010

this cant be done with a on text event?

Just make it randomize some cookie name u made up. And put it in a .txt file.

on *:text:!cookie*:#: {
 if ($(,$+(%,flood,$nick))) { return }
    set -u3 $+(%,flood,$nick)

var %cookie = $read(Cookie.txt)
var %cookie2 = $readini(Cookie.ini,cookie,$nick)
var %true = 1
var %false = 0

if ( %cookie2 == %true ) { notice $nick You already have a cookie. You can get rid of it by eating it. (Syntax: !eat cookie) | return }

describe $chan $2 Received a %cookie .
writeini cookie.ini Cookie $nick %true
halt
}

on *:text:!eat cookie:#: {
 if ($(,$+(%,flood2,$nick))) { return }
    set -u3 $+(%,flood2,$nick)

if (%cookie2 == 0) { notice $nick Sorry but you dont have a cookie. Get one by typing: !cookie | Return }

if (%cookie2 == $null) { notice $nick Sorry but you dont have a cookie. Get one by typing: !cookie | Return }

if (%cookie2 == 1) { 
notice $nick You just ate your cookie! 
writeini Cookie.ini Cookie $nick %false
halt
}
 Respond  
darkly57   -  Apr 22, 2010

Ah, and yes, I meant the arguments at the end, Couldn't think of the name :P

Well. I've learned a lot today. Thanks for all the help :)

 Respond  
gooshie   -  Apr 22, 2010

The -l switch restricts the alias to local so it can not be called
for instance from the command line or a different script file.
Mostly unnecessary.

Yup, the $iif() is an inline if/else condition statement.

"do extras on the end of alias's" ??? ..do you mean pass arguments?
Well, yup the cookie($1 give) passes those two items as $1 and $2
(I kept $1 first on purpose if I had said cookie(give $1) then it
could have worked just the same as long as I changed it around in
the alias to match which can get confusing.)

 Respond  
darkly57   -  Apr 22, 2010

Okay...Now can I ask a little about that? :P

What does the -l do in the alias?

and I think this is right, but $iif is like...$iff(4 = 4,this,that) is the same as if (4 = 4) { this }
else { that }
?

And I also never knew you could do extras on the end of alias's. That's interesting...That will be helpful.

 Respond  
gooshie   -  Apr 22, 2010

You could also maybe do something like this.

menu query,nicklist {
  Cookie
  .Give Cookies:cookies($1 give)
  .Take Cookies:cookies($1 take)
}

alias -l cookies {
      var %cookies $iif($readini(cookies.ini,cookies,$1),$v1,0)
      var %x.cookies $$?="Number of cookies to $2?"
      %cookies = $calc(%cookies $iif($2 = give,+,-) %x.cookies)
      writeini cookies.ini cookies $1 %cookies
      DESCRIBE # has $2 $+ n %x.cookies cookies $iif($2 = give,to,away from) $1 $+ , $1 now has %cookies cookies!
   }
}
__________________________________________________________________________________________________________________
 Respond  
darkly57   -  Apr 22, 2010

Hmm, Yeah, Yours is equivalent. I'm still kinda learning all this stuff, I mean, I can get a lot of stuff done, but I take a lot more steps then I end up having to.

Thanks for all the input.

And about the negatives, I wasn't really trying to avoid it. It's mostly just for fun, So giving people negative's is more fun that it saying "They don't have any cookies to take!" ;)

 Respond  
gooshie   -  Apr 22, 2010
menu query,nicklist {
  Cookie
  .Give Cookies:{
    var %cookies $iif($readini(cookies.ini,cookies,$1),$v1,0),%g.cookies $$?="Number of cookies to give?"
      %cookies = $calc(%cookies + %g.cookies)
      writeini cookies.ini cookies $1 %cookies
      DESCRIBE # has given %g.cookies cookies to $1 $+ , $1 now has %cookies cookies!
  }
  .Take Cookies:{
    var %cookies $iif($readini(cookies.ini,cookies,$1),$v1,0),%t.cookies $$?="Number of cookies to take?"
      %cookies = $calc(%cookies - %t.cookies)
      writeini cookies.ini cookies $1 %cookies
      DESCRIBE # has taken %t.cookies cookies away from $1 $+ , $1 now has %cookies cookies!
  }
}

______________________________________________________________________________________________________________

This should be functional equivalent to the original menu although you may wish do do something about taking cookies away from someone who has none thus avoiding negative cookies.

 Respond  
gooshie   -  Apr 22, 2010

if %x { is the same as if (%x != $null) {

In other words your just checking if something is there.

The point of moving the var %x to before the condition
check is to eliminate having to make a 2nd harddrive read
for the same data when it is found to exist.

 Respond  
darkly57   -  Apr 22, 2010

gooshie: But we wouldn't want to do it unless the person already had "cookies". So the != $null part is needed. Unless there is something in your's that i'm not seeing...

 Respond  
gooshie   -  Apr 22, 2010
on *:nick: { 
  var %x $readini(cookies.ini, cookies, $nick)
  if %x {
    remini cookies.ini cookies $nick
    writeini cookies.ini cookies $newnick %x
  }
}
 Respond  
darkly57   -  Apr 21, 2010

Ah, That's exactly what I was looking for.

I was searching the help files for something like $newnick...didn't think it would be so obvious :P

Thanks.

 Respond  
jsg55   -  Apr 21, 2010

"I'm trying to figure out when someone changes their nick...It will change the ini to match the new nick. If anyone can help me with that, That'd be great :D"
how about
on *:nick: {
if ($readini(cookies.ini, cookies, $nick) != $null) {
var %x $readini(cookies.ini, cookies, $nick)
remini cookies.ini cookies $nick
writeini cookies.ini cookies $newnick %x
}
}
if thats what your asking for lol
i apologize if its not the most compact piece of work ever

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.