Apples to Apples

By tv3636 on Apr 22, 2009

Version 1.3

How to play Apples to Apples in general http://www.com-www.com/applestoapples/applestoapples-rules-official-partyset.html

Necessary .txt files apples.txt (Nouns) apples2.txt (Adjectives)

Set-up Download the 2 txt files linked above and place them in your mIRC directory. If you don't know what that directory is: //echo -a $mircdir Paste the code below into an empty remote file and enjoy :D

Commands !apples - Starts the game set up, waits for 8 players or somebody to say !go !join - Joins the game while waiting, cannot (yet) join while the game is going !go - Starts the game for all players who have !joined to n points, !go with no number is 7 points !play - Currently set up as a PM to the script holder, use this to play your card. Example: !play Apples -This would play the card Apples, assuming you had that card. !hand - Notifies you of your hand (you are automatically shown each round however) !leave - If you are in a game and want to remain in the channel but you want to stop playing, use this. !end - Ends the game !choose - If you are the judge, use this to choose the winning card. !remove - In the rare occasion somebody leaves and is not removed (only happens if they Ping out and don't return) operators in the channel can use this to remove them from the game.

Notes

  • I am new to using tokens so I realize my usage of them is probably weird/terrible, feedback is definitely appreciated. And the rest of my code probably isn't superb either. I'm really looking forward to getting constructive criticism on my code because I know it's nowhere near optimal but I don't exactly know how I could/should improve it

  • The game currently just ignores the round if a judge does not choose a card after 60 seconds, I'm not sure how I should deal with that case because it is bound to happen but for now that's what happens.

  • !play is currently set to be messaged in a PM. If you want to put this on your own client it can get very annoying getting a ton of PM's, so to change it simply substitute "%chan.ATA" for "?" in the on TEXT event for !play.

  • That's all I can think of for now, enjoy!

Update Log Version 1.1: Minor bugs fixed, added ability to join mid-game, other minor tweaks. I also made the game end after somebody gets 7 points which is how I am used to playing...if you really don't want it this way you can just remove the last if statement of the !choose on TEXT event. Version 1.2: Added tons more cards, added !remove feature, change $reads to $freads to improve speed, few other minor alterations. Added !go to go to a certain number of points, default is 7 with !go. Version 1.3: More minor edits since the last version, like !remove to remove somebody from the game in case they become inactive. Also fixed the bug where the game wouldn't work if somebody has a - in their nick.

;IRC Apples to Apples
;created by tv3636
;5/28/09
;Version 1.3

on *:LOAD:/ATAsetchan $?="Enter the channel you would like to play Apples to Apples in. (Including #)"
alias ATAsetchan { set %chan.ATA $1 | echo -a %chan.ATA is now the active channel for Apples to Apples }

alias ATAgethand {
  var %ATA.hand
  var %ATA.counter = 0
  while (%ATA.counter < 7) {
    %ATA.hand = %ATA.hand $+ $getcard $+ *
    inc %ATA.counter
  }
  return %ATA.hand
}

alias getcard {
  var %ATA.randnum = $rand(1,%ATA.len1)
  .fseek -l apples %ATA.randnum
  var %ATA.getcardout = $fread(apples)
  while (%ATA.randnum isin %ATA.usedcards) {
    %ATA.randnum = $rand(1,%ATA.len1)
    .fseek -l apples %ATA.randnum
    %ATA.getcardout = $fread(apples)
  }
  set %ATA.usedcards %ATA.usedcards %ATA.randnum
  return %ATA.getcardout
}

on *:TEXT:!apples:%chan.ATA:{
  if (%ATA.waiting != $true && %ATA.gameon != $true) {
    set %ATA.waiting $true
    set %ATA.waitinglist $nick
    set %ATA.players 1
    msg %chan.ATA 04Starting a game of Apples to Apples, say !join to join and !go to start the game.  4-8 players.
  }
}

on *:TEXT:!join:%chan.ATA:{
  if (%ATA.waiting == $true && $nick !isin %ATA.waitinglist) {
    set %ATA.waitinglist %ATA.waitinglist $nick
    inc %ATA.players
    msg %chan.ATA Current Players: %ATA.waitinglist
    if (%ATA.players == 8) { set %ATA.pointsneeded 7 | ATAgamestart }
  }
  if (%ATA.waiting == $false && $nick !isin %ATA.waitinglist && %ATA.players < 8) {
    set %ATA.waitinglist %ATA.waitinglist $nick
    inc %ATA.players
    msg %chan.ATA $nick has joined!
    ATAdeal $nick
    ATAmsghand $nick
  }
}

alias ATAgamestart {
  .fopen apples apples.txt
  .fopen apples2 apples2.txt
  set %ATA.len1 $lines(apples.txt)
  set %ATA.len2 $lines(apples2.txt)
  set %ATA.waiting $false
  set %ATA.gameon $true
  var %ATA.counter = 1
  while (%ATA.counter <= $numtok(%ATA.waitinglist,32) ) {
    ATAdeal $gettok(%ATA.waitinglist,%ATA.counter,32)
    .timerATA $+ %ATA.counter 1 %ATA.counter ATAmsghand $gettok(%ATA.waitinglist,%ATA.counter,32)
    inc %ATA.counter
  }
  msg %chan.ATA Game to %ATA.pointsneeded points is beginning, to play a card: /msg $me !play <card>
  .timerATA 1 %ATA.counter ATAround

}

on *:TEXT:!go*:%chan.ATA:{
  if (%ATA.waiting == $true && $nick isin %ATA.waitinglist) {
    if ($2 != $null && $calc($2) > 0) set %ATA.pointsneeded $2
    else set %ATA.pointsneeded 7
    ATAgamestart
  }
  else if (%ATA.waiting == $true) .notice $nick Sorry, you must be in the game to start it.
}

on *:TEXT:!end:%chan.ATA:{
  ATAgameend
}

alias ATAgameend {
  if (%ATA.gameon == $true || %ATA.waiting == $true) {
    msg %chan.ATA $ATAscores
    unset %ATA.*
    .timerata* off
    msg %chan.ATA Game over!
    .fclose apples apples.txt
    .fclose apples2 apples2.txt
  }
}

on *:TEXT:!play *:?:{
  if (%ATA.playable == $true && $findtok(%ATA. [ $+ [ $nick ] ],$2-,1,42) != $null && $nick !isin %ATA.played) {
    if ($nick != %ATA.judge) {
      var %ATA.tempcard = $2-
      .notice $nick Played card $2- successfully!
      set %ATA.played %ATA.played $+ $nick $+ * $+ $2- $+ *
      inc %ATA.cardsplayed
      var %useless = $read(apples.txt,w,$2-)
      set %ATA.usedcards $replace(%ATA.usedcards,$chr(32) $+ $readn $+ $chr(32),$chr(32))
      set %ATA. [ $+ [ $nick ] ] $reptok(%ATA. [ $+ [ $nick ] ],%ATA.tempcard,$getcard,1,42)
    }
    else .notice $nick You can't play a card this round, you're the judge!
    if (%ATA.cardsplayed == %ATA.players) ATAround2
  }
  else if ($findtok(%ATA. [ $+ [ $nick ] ],$2-,1,42) == $null && %ATA.gameon == $true) .notice $nick You don't have this card!
}

on *:TEXT:!choose *:%chan.ATA:{
  if ($nick == %ATA.judge && %ATA.playable == $false && * $+ $2- $+ * isin %ATA.played && %ATA.chosen != $true) {
    var %ATA.hold = $2-
    var %ATA.tempnick = $gettok(%ATA.played,$calc($findtok(%ATA.played,%ATA.hold,1,42) - 1),42)
    tokenize 42 %ATA. [ $+ [ %ATA.tempnick ] ]
    msg %chan.ATA 01,09 $+ %ATA.adjective $+  must describe 01,04 $+ %ATA.hold $+  well, 1 point for %ATA.tempnick $+ !
    set %ATA. [ $+ [ %ATA.tempnick ] ] $puttok(%ATA. [ $+ [ %ATA.tempnick ] ],$calc($1 + 1),1,42)
    set %ATA.chosen $true
    if ($calc($1 + 1) == %ATA.pointsneeded) {
      msg %chan.ATA Game over, %ATA.tempnick wins!
      ATAgameend
    }
    else ATAround3
  }
}

on *:TEXT:!hand:%chan.ATA:{
  ATAmsghand $nick
}

alias ATAdeal {
  var %ATA.tempname = $1
  set %ATA. [ $+ [ %ATA.tempname ] ] 0 $+ * $+ $ATAgethand
}

alias ATAmsghand {
  var %ATA.tempname = $1
  tokenize 42 %ATA. [ $+ [ %ATA.tempname ] ]
  .notice %ATA.tempname Your Hand: 01,04 $+ $2 $+  $+ , 01,04 $+ $3 $+  $+ , 01,04 $+ $4 $+  $+ , 01,04 $+ $5 $+  $+ , 01,04 $+ $6 $+  $+ , 01,04 $+ $7 $+  $+ , 01,04 $+ $8 $+ 
}

alias ATAround {
  unset %ATA.played
  set %ATA.cardsplayed 0
  set %ATA.chosen $false
  ATAchoosejudge
  var %ATA.randnum = $rand(1,%ATA.len2)
  .fseek -l apples2 %ATA.randnum
  set %ATA.adjective $fread(apples2)
  msg %chan.ATA The word for this round is 01,09 $+ %ATA.adjective $+  and the judge for this round is %ATA.judge $+ .
  set %ATA.playable $true
  .timerataround 1 60 ATAround2
}

alias ATAround2 {
  set %ATA.playable $false
  set %ATA.played2 Cards Played:
  var %x = 1
  while (%x <= $numtok(%ATA.played,42)) {
    if ($calc(%x % 2) == 0) set %ATA.played2 %ATA.played2 01,04 $+ $gettok(%ATA.played,%x,42) $+ ,
    inc %x
  }
  msg %chan.ATA $left(%ATA.played2,-1)
  if ($timer(ataround) != $null) .timerataround off
  .notice %ATA.judge Please choose a winning card by saying !choose <card>
  .timerataround2 1 60 ATAround3
}

alias ATAround3 {
  if ($timer(ataround2) != $null) .timerataround2 off
  .timerataround3 1 20 ATAround
  var %ATA.counter = 1
  msg %chan.ATA $ATAscores
  while (%ATA.counter <= $numtok(%ATA.waitinglist,32) ) {
    .timerATA $+ %ATA.counter 1 %ATA.counter ATAmsghand $gettok(%ATA.waitinglist,%ATA.counter,32)
    inc %ATA.counter
  }
}

alias ATAchoosejudge {
  if (%ATA.judgenumber == $null) {
    set %ATA.judgenumber $rand(1,%ATA.players)
  }
  if (%ATA.judgenumber < %ATA.players) inc %ATA.judgenumber
  else set %ATA.judgenumber 1
  set %ATA.judge $gettok(%ATA.waitinglist,%ATA.judgenumber,32)
}

alias ATAscores {
  var %ATA.count = 1
  var %ATA.scorestring = ~
  while (%ATA.count <= %ATA.players) {
    var %ATA.holdnick = $gettok(%ATA.waitinglist,%ATA.count,32)
    tokenize 42 %ATA. [ $+ [ %ATA.holdnick ] ]
    %ATA.scorestring = %ATA.scorestring %ATA.holdnick $+ : $1 ~
    inc %ATA.count
  }
  return Scores: %ATA.scorestring
}

alias ATAleftgame {
  if ($1 == %ATA.judge) {
    msg %chan.ATA The judge has left, a new round is beginning!
    ATAround
  }
  var %ATA.nickhold = $1
  if ($findtok(%ATA.played,%ATA.nickhold,1,42) != $null) set %ATA.played $deltok(%ATA.played,$findtok(%ATA.played,%ATA.nickhold,1,42)-$calc($findtok(%ATA.played,%ATA.nickhold,1,42) + 1),42)
  tokenize 32 %ATA.waitinglist
  if ($1 != %ATA.nickhold) set %ATA.waitinglist $remove(%ATA.waitinglist,$chr(32) $+ %ATA.nickhold)
  else set %ATA.waitinglist $remove(%ATA.waitinglist,%ATA.nickhold $+ $chr(32))
  unset %ATA. [ $+ [ %ATA.nickhold ] ]
  dec %ATA.players
}

on *:QUIT:{
  if ($nick isin %ATA.waitinglist && Ping Timeout !isin $1- && peer !isin $1-) ATAleftgame $nick
}

on *:PART:%chan.ATA:{
  if ($nick isin %ATA.waitinglist) ATAleftgame $nick
}

on *:TEXT:!leave:%chan.ATA:{ if ($nick isin %ATA.waitinglist) { ATAleftgame $nick | msg %chan.ATA $nick has left the game } }

on *:NICK:{
  if ($nick isin %ATA.waitinglist) {
    if ($nick == %ATA.judge) set %ATA.judge $newnick
    set %ATA.waitinglist $replace(%ATA.waitinglist,$nick,$newnick)
    if ($nick isin %ATA.played) set %ATA.played $replace(%ATA.played,$nick,$newnick)
    set %ATA. [ $+ [ $newnick ] ] %ATA. [ $+ [ $nick ] ]
    unset %ATA. [ $+ [ $nick ] ]
  }
}

on *:TEXT:!remove *:%chan.ATA:{ if ($2 isin %ATA.waitinglist && $nick isin %ATA.waitinglist && $nick isop %chan.ATA) { msg %chan.ATA $2 has been removed from the game | ATAleftgame $2  } }
Sign in to comment.
KholdStare88   -  Jul 14, 2010

Nice script. One thing to note was that at first the script didn't work for me also, since I placed the text files in the script directory instead of the mIRC (main) directory, and you get an endless loop since $lines == 0. Many people put .mrc files in mIRC/scripts, so that might be why some people say it can't run (and hurt your ratings).

 Respond  
tv3636   -  Jul 08, 2010

Ok I finally got a chance to access the txt files and now they are uploaded so that they won't expire again. Sorry about the wait!

 Respond  
WINdoze   -  May 21, 2010

That link does not work anymore :<

 Respond  
tv3636   -  Feb 13, 2010

Uhh, no, sorry. Haven't heard of anybody having that issue. If you want to talk to me in IRC so I can try to troubleshoot it with you I'm tv3636 on gamesurge.

 Respond  
Creekynoise   -  Feb 13, 2010

I just played it in my room, and it seems to be working okay, except for the scores are staying at 0. Any ideas?

 Respond  
tv3636   -  Feb 13, 2010

Finally updated the links! Sorry for the delay, I had to be home because the files are only on my home PC (and I've been at school)

 Respond  
Creekynoise   -  Feb 13, 2010

Would love to try this out, if the .txt files could be reuploaded that would be awesome!

 Respond  
CadetAndrew   -  Jan 08, 2010

Yea looks like the 2 .txt files aren't there anymore, anyone else here already use this script and have the files?

 Respond  
Fate1316   -  Oct 12, 2009

The 2 txt files are not available for downloads now.... Any idea where I can get them so I can try this out?

 Respond  
tv3636   -  Aug 11, 2009

Thanks a lot, I really appreciate it :D I believe it was a 4.7 because somebody couldn't figure it out and rated it a 2, and then never increased the rating when they figured out their issue..oh well. Thanks again!

 Respond  
Lzn64   -  Aug 11, 2009

Hi,

I rated you a 10, I have no idea why you had a 4.7, this works great and it's really fun. Thanks for fixing that bug, by the way :D

 Respond  
tv3636   -  May 28, 2009

fixed the bug Lzn64 :)

 Respond  
tv3636   -  May 27, 2009

Yeah..I used a "-" in a few strings that are essential in playing the game not realizing that it's a fairly common nickname character. I'll try to switch it to a character that's unusable in nicknames to avoid that error in the future. Glad you like it though :D And if you don't mind rating it I'd really appreciate it, somebody gave it a 2 because they couldn't get it to work at first (even though it was their error) and I think this definitely deserves better than a 4.5 :\

 Respond  
Lzn64   -  May 27, 2009

Hi,

My friends and I love this game and it's working well, there's just one bug we noticed -- if someone's nickname has a "-" symbol in it the script screws up pretty bad. Not sure if there's a fix for this, just something we found :)

Thanks for this, though, we seriously love it and appreciate your time and effort!

 Respond  
tv3636   -  May 02, 2009

Awesome, thanks :)

 Respond  
Scrb   -  May 02, 2009

sorry! nevermind! I just got it to work. Good script, by the way! I love it now that it works. xD

 Respond  
tv3636   -  May 02, 2009

The entire script (everything in the code text box) goes into a remote file.

Good luck figuring it out yourself but I could probably help you a lot if you want to either go to gamesurge or tell me what server I can contact you on. I know it's not a problem with a script because I'm using the exact same script and it works fine. (or at least runs, there may still be a few very small bugs I'm unaware of)

 Respond  
Scrb   -  May 02, 2009

well, quick question. I'm going to try my best to work with it myself and with a few friends to figure out my problem. Anyway, do you stick the entire script into remote, or do some parts go into aliases?

 Respond  
tv3636   -  May 02, 2009

If you can tell me what server you're on / go to irc.gamesurge.net and msg tv3636 I can help you through IRC, that would be easiest. I will be on for another hour or so most likely and then back tomorrow for the day.

 Respond  
Scrb   -  May 02, 2009

sorry, having a little trouble here. I'm not entirely sure why it isn't working. I downloaded the files and placed them in the correct spot, I copied and replaced the correct part of the code to the remote slot, and yet the game isn't starting up for me. I'm not sure if you can help me, but I'm just a little troubled here. o_o;

 Respond  
tv3636   -  Apr 26, 2009

In case anyone is interested: I've made a TON of minor updates in the past few days to make it as perfect as I possibly could, as far as I know there are no bugs with this version. If you find any, even a very small/trivial one, please let me know as I want the script to be perfect. And of course let me know if you have suggestions. Or just let me know if you even like it :s

 Respond  
tv3636   -  Apr 24, 2009

uhh ok lol glad you figured it out then. If you were the one who rated it a 2 I'd really appreciate if you raised the rating, I think it deserves a bit more than that :/

 Respond  
winni2   -  Apr 24, 2009

hello, I am Italian. the game is very nice thank you. : D

 Respond  
tv3636   -  Apr 23, 2009

Updated a few things, and to winni2: I've been using the script for hours and it has been working fine (aside from minor bugs which I fixed)

 Respond  
tv3636   -  Apr 23, 2009

I'm sorry but I don't exactly understand your issue. Are you absolutely sure you have the txt files in the right place? I am using this exact same code and it's working fine, I don't know what your problem would be other than incorrect placement of the script or txt files. If you for some reason put the code in a remote file with more scripts check your brackets for your other scripts to make sure they're not messing anything up.

 Respond  
winni2   -  Apr 23, 2009

hello, I uploaded apples but when I type !JION then !go Stops script mirc

 Respond  
tv3636   -  Apr 22, 2009

Oh right I totally forgot about that, I had that on my list of things to add but I never got around to it. I'll fix that soon :)

Edit: Added.

 Respond  
Kirby   -  Apr 22, 2009

Cool tv3636. =]

The only thing I would change is $nick to perhaps $address()? I won't be able to play the game if I were to change my nick, and that would be a bit inconvenient. If address form cannot be done, then how about a on Nick that adjusts for each of the players?

 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.