;Family Feud Script Version 1.7 by tv3636
;Runs a channel wide game of Family Feud with questions and answers specified in a txt file (Default .txt file name is FamFeud.txt)
;For update log check http://www.hawkee.com/snippet/5714/
;February 28th, 2009
;Enjoy :D

;--------------- Buzzen Chat -------------------

;Edited for Buzzen chat & SF_GamesBot by j3nX
;alias dcoll & show from WF4.0 with thanks.
;Works in SoulFly connection, untested in others

;-----------------------------------------------

/*
Commands:
!FFstart number
-------------
Starts the game
"!start 1" starts a 1 round game, "!start unlimited or !start" starts an unlimited game
-------------
!stop
-------------
Stops the game
-------------
!score
-------------
Notices a user his/her score
-------------
!scores
-------------
Notices a user the current scores.
*/

;Reads from a text file and grabs a random line's Question and answers in the format: Question*Answer1-Answer2-Answer3-Answer4-Answer5-Answer6-Answer7-Answer8

; Regular text events

menu menubar {
  -
  Family Feud
  .Set Room && Start the Feud!:.set %chanFF $chan | FFstart $me $chan unlimited
  .Reset Score Files : write -c FFScores.ini | write -c FFScores.txt | echo -a »»» All Family Feud Scores Reset | msg $chan S eTahoma;0 Family Feud Scores Reset |^: 
  .-
  .Edit Questions:run text\FamFeud.txt
  .View Current FF Channel: echo $dspot(»»» Family Feud channel currently set to %chanFF $+ .)
  .-
  .$iif(%FF.on == 2,Stop):/FFStop $me $chan
  -
}


on *:TEXT:!start*:%chanFF:{
  if (!%msg.spam. [ $+ [ $nick ] ]) { 
    if ($2 != $null) { FFstart $nick $chan $2 | set -u5 %msg.spam. [ $+ [ $nick ] ] $true }
    else { FFstart $nick $chan unlimited | set -u5 %msg.spam. [ $+ [ $nick ] ] $true }
  }
}

alias FFstart {
  if ( %FF.on != 2 ) {
    DOcoll darkred b [br] (f)(*) Family Feud has been started by $1 (*) (F)
    set %FF.answerz 0
    set %FF.on 2
    set %FF.roundsplayed 1
    if ($3 == unlimited) { unset %FF.roundsplayed }
    else { set %FF.rounds $3 }
    game
  }
  else { .notice $chan $1 The game's already running $nick $+ . (fl) }
}

on *:TEXT:!stop:%chanFF:{ 
  if (!%msg.spam. [ $+ [ $nick ] ]) {
    FFstop $nick $chan 
    set -u5 %msg.spam. [ $+ [ $nick ] ] $true  
  }
}

on *:TEXT:!score:%chanFF:{ 
  if (!%msg.spam. [ $+ [ $nick ] ]) {
    DoStat
    set -u5 %msg.spam. [ $+ [ $nick ] ] $true
  }
} 

alias FFstop { 
  if ( %FF.on == 2 ) {
    if ($1 != $null) DOcoll green b [br] (brb) Family Feud stopped by $1 $+ . :-#
    else DOcoll green b (brb) Game over! :(
    .timerdowhat 1 3 DoWhat
    .timer1 off
    .timer2 off
    .timer3 off
    unset %FF.*
  }
  else { .notice $chan $1 Stop what $nick $+ .? 8-) }
}

on *:TEXT:!help:%chanFF:{
  if (!%msg.spam. [ $+ [ $nick ] ]) {
    DOcommands | set -u5 %msg.spam. [ $+ [ $nick ] ] $true
  }
}

;Text events for all 8 answers

on *:TEXT:%FF.a1:%chanFF:{
  DOcoll darkred b [br] (r*) Survey says, 50 points! $bdc($nick) got the #1 answer, %FF.a1 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 50 | addpoint $nick 50
  unset %FF.a1
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a2:%chanFF:{
  DOcoll green b [br] (r*) Survey says, 35 points! $bdc($nick) got the #2 answer, %FF.a2 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 35 | addpoint $nick 35
  unset %FF.a2
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a3:%chanFF:{
  DOcoll darkred b [br] (r*) Survey says, 28 points! $bdc($nick) got the #3 10answer, %FF.a3 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 28 | addpoint $nick 28
  unset %FF.a3
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a4:%chanFF:{
  DOcoll green b [br] (r*) Survey says, 20 points! $bdc($nick) got the #4 answer, %FF.a4 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 20 | addpoint $nick 20
  unset %FF.a4
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a5:%chanFF:{
  DOcoll darkred b [br] (r*) Survey says, 15 points! $bdc($nick) got the #5 answer, %FF.a5 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 15 | addpoint $nick 15
  /unset %FF.a5
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a6:%chanFF:{
  DOcoll green b [br] (r*) Survey says, 10 points! $bdc($nick) got the #6 answer, %FF.a6 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 10 | addpoint $nick 10
  unset %FF.a6
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a7:%chanFF:{
  DOcoll darkred b [br] (r*) Survey says, 8 points! $bdc($nick) got the #7 answer, %FF.a7 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 8 | addpoint $nick 8
  unset %FF.a7
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

on *:TEXT:%FF.a8:%chanFF:{
  DOcoll green b [br] (r*) Survey says, 5 points! $bdc($nick) got the #8 answer, %FF.a8 $+ !
  inc %FF.score. [ $+ [ $nick ] ] 5 | addpoint $nick 50
  unset %FF.a8
  set %FF.answerz %FF.answerz + 1
  check %FF.answerz
}

;Checks to see if all answers have been said before time limit is up
alias check {
  if ( $1 == %FF.dashes ) { 
    .timer1 off
    .timer3 off
    game2 
  }
}

alias docoll { 
  if ($1-2 == darkgreen b) { show S Tahoma;0 $3-  } 
  elseif ($1-2 == teal b) { show S Tahoma;0 $3-  } 
  elseif ($1-2 == darkblue b) { show S \rTahoma;0 $3-  } 
  elseif ($1-2 == red b) { show S eTahoma;0 $3-  }
  elseif ($1-2 == purple b) { show S Tahoma;0  $3-  }
  elseif ($1-2 == red b) { show S eTahoma;0 $3-  } 
  elseif ($1-2 == red bb) { show S eTahoma;0 $3-   }
  elseif ($1-2 == gold b) { show S Tahoma;0 $3-   } 
  elseif ($1-2 == green b) { show S Tahoma;0 $3-  }
  elseif ($1-2 == blue b) { show S \rTahoma;0 $3-  } 
  elseif ($1-2 == darkred b) { show S eTahoma;0 $3-  } 
  elseif ($1-2 == black b) { show S Tahoma;0    $3-  } 
  elseif ($1-2 == black r) { show S Tahoma;0     $3-  } 
  elseif ($1-2 == navy b) { show S Tahoma;0 $3-  } 
  elseif ($1-2 == dark b) { show S Tahoma;0 $3-  } 
}

alias show { msg %chanFF $1- } 

alias DOcommands {
  notice $chan $nick [br] (#) type !Start ~ to Begin Unlimited Game. [br] (#) type !Start 2 ~ to Begin Game of 2 Rounds etc. [br] (#) type !Stop ~ to End Game. [br] (#) type !Score ~ to See Your Score. 
}

alias question {
  set %FF.line $read(text\FamFeud.txt)
  set %FF.num $pos(%FF.line, *, 1)
  set %FF.length $len(%FF.line)
  set %FF.numA %FF.length - %FF.num
  set %FF.numQ %FF.num - 1
  set %FF.dashes $count(%FF.line, -)

  set %FF.answers $right(%FF.line, %FF.numA)
  set %FF.question $left(%FF.line, %FF.numQ)

  set %FF.numcom $pos(%FF.answers, -, 1) - 1
  set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
  set %FF.a1 $left(%FF.answers, %FF.numcom)
  set %FF.answers $right(%FF.answers, %FF.numcom2)
  if ( %FF.dashes > 0 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a2 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }
  if ( %FF.dashes > 1 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a3 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }
  if ( %FF.dashes > 2 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a4 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }
  if ( %FF.dashes > 3 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a5 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }
  if ( %FF.dashes > 4 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a6 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }
  if ( %FF.dashes > 5 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a7 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }

  if ( %FF.dashes == 0 ) { set %FF.a1 %FF.answers }
  if ( %FF.dashes == 1 ) { set %FF.a2 %FF.answers }
  if ( %FF.dashes == 2 ) { set %FF.a3 %FF.answers }
  if ( %FF.dashes == 3 ) { set %FF.a4 %FF.answers }
  if ( %FF.dashes == 4 ) { set %FF.a5 %FF.answers }
  if ( %FF.dashes == 5 ) { set %FF.a6 %FF.answers }
  if ( %FF.dashes == 6 ) { set %FF.a7 %FF.answers }
  if ( %FF.dashes == 7 ) { set %FF.a8 %FF.answers }
  if ( %FF.dashes > 7 ) {
    set %FF.numcom $pos(%FF.answers, -, 1) - 1
    set %FF.numcom2 $len(%FF.answers) - $pos(%FF.answers, -, 1)
    set %FF.a8 $left(%FF.answers, %FF.numcom)
    set %FF.answers $right(%FF.answers, %FF.numcom2)
  }
  inc %FF.dashes

  ;I was having issues with my other answer variables and timers so I just made a second set for the check alias.
  set %FF.answerz 0
  set %FF.a12 %FF.a1
  set %FF.a22 %FF.a2
  set %FF.a32 %FF.a3
  set %FF.a42 %FF.a4
  set %FF.a52 %FF.a5
  set %FF.a62 %FF.a6
  set %FF.a72 %FF.a7
  set %FF.a82 %FF.a8
  if (%FF.roundsplayed != $null) { DOcoll dark b [br] (*) Round %FF.roundsplayed / %FF.rounds Question ( $+ $readn $+ / $+ $lines(text\FamFeud.txt) $+ ): %FF.question }
  else { 
    .timerquestion 1 1 DOcoll dark b [br] (*) Question ( $+ $readn $+ / $+ $lines(text\FamFeud.txt) $+ ): %FF.question 8-| 
    .timercommands 1 2 DOcoll green b [br] Type !help for Family Feud Commands.
    .timeranswers 1 3 DOcoll darkred b [br] (yn) There are %FF.dashes answers! |^:
  }
}

alias game {
  if (%FF.roundsplayed == $null || %FF.roundsplayed <= %FF.rounds) {
    question
    .timer1 1 70 game2
    .timer3 1 40 remaining
  }
  else { FFstop }
}

alias game2 {
  if ( %FF.dashes == 1 ) { DOcoll teal b [br] (o) Time's Up! The answer was: %FF.a12 }
  if ( %FF.dashes == 2 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 and %FF.a22 }
  if ( %FF.dashes == 3 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 $+ , %FF.a22 $+ , and %FF.a32 }
  if ( %FF.dashes == 4 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 $+ , %FF.a22 $+ , %FF.a32 $+ , and %FF.a42 }
  if ( %FF.dashes == 5 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 $+ , %FF.a22 $+ , %FF.a32 $+ , %FF.a42 $+ , and %FF.a52 }
  if ( %FF.dashes == 6 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 $+ , %FF.a22 $+ , %FF.a32 $+ , %FF.a42 $+ , %FF.a52 $+ , and %FF.a62 }
  if ( %FF.dashes == 7 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 $+ , %FF.a22 $+ , %FF.a32 $+ , %FF.a42 $+ , %FF.a52 $+ , %FF.a62 $+ , and %FF.a72 }
  if ( %FF.dashes == 8 ) { DOcoll teal b [br] (o) Time's Up! The answers were (in order): %FF.a12 $+ , %FF.a22 $+ , %FF.a32 $+ , %FF.a42 $+ , %FF.a52 $+ , %FF.a62 $+ , %FF.a72 $+ , and %FF.a82 }
  if (%FF.roundsplayed != $null) { inc %FF.roundsplayed }
  unset %FF.a*
  if (%FF.roundsplayed > %FF.rounds) { FFstop }
  if (%FF.on == 2) { DOcoll darkred b [br] (f) Next question in 35 seconds. (o) [br] (#) Type !Score to see your current score (#) }
  if (%FF.on == 2) { .timerscoreit 1 1 DOWhat }
  if (%FF.on == 2) { .timer2 1 40 game }
  ;40 second delay between questions.
}

alias remaining {
  set %FF.remain The remaining answers are:
  if ( %FF.a1 != $null ) { set %FF.remain %FF.remain #1 }
  if ( %FF.a2 != $null ) { set %FF.remain %FF.remain #2 }
  if ( %FF.a3 != $null ) { set %FF.remain %FF.remain #3 }
  if ( %FF.a4 != $null ) { set %FF.remain %FF.remain #4 }
  if ( %FF.a5 != $null ) { set %FF.remain %FF.remain #5 }
  if ( %FF.a6 != $null ) { set %FF.remain %FF.remain #6 }
  if ( %FF.a7 != $null ) { set %FF.remain %FF.remain #7 }
  if ( %FF.a8 != $null ) { set %FF.remain %FF.remain #8 }
  DOcoll darkred b [br] (yn) %FF.remain
}

alias AddPoint { 
  var %Score $readini(FFScores.ini, $1, score) 
  inc %Score $2 
  writeini FFScores.ini $1 score %Score 
} 

alias DoSort { 
  var %a = 1, %b = $ini(FFScores.ini,0) 
  .remove FFScores.txt 
  while (%a <= %b) { 
    write FFScores.txt $ini(FFScores.ini,%a) $readini(FFScores.ini,$ini(FFScores.ini,%a),score) 
    inc %a 
  } 
  filter -ffcteu 2 32 FFScores.txt FFScores.txt 
}

alias DoWhat { 
  DoSort 
  Docoll purple b [br] (#)~~~ Family Feud's Current Leaders ~~~(#)  
  if ($read(FFScores.txt,1)) { Docoll purple b 1. ({) $gettok($read(FFScores.txt,1),1,32) with (H) $gettok($read(FFScores.txt,1),2,32) } 
  if ($read(FFScores.txt,2)) { Docoll purple b 2. ({) $gettok($read(FFScores.txt,2),1,32) with (H) $gettok($read(FFScores.txt,2),2,32) } 
  if ($read(FFScores.txt,3)) { Docoll purple b 3. ({) $gettok($read(FFScores.txt,3),1,32) with (H) $gettok($read(FFScores.txt,3),2,32) } 
  if ($read(FFScores.txt,4)) { Docoll purple b 4. ({) $gettok($read(FFScores.txt,4),1,32) with (H) $gettok($read(FFScores.txt,4),2,32) } 
  if ($read(FFScores.txt,5)) { Docoll purple b 5. ({) $gettok($read(FFScores.txt,5),1,32) with (H) $gettok($read(FFScores.txt,5),2,32) } 
}
alias DoStat { 
  DoSort 
  if (!$read(FFScores.txt,w,* $+ $nick $+ *)) { 
    notice $chan $nick [br] I'm sorry, :S but you have no score! 
  } 
  else $read(FFScores.txt,w,* $+ $nick $+ *) { 
    notice $chan $nick [br] (*) Your current Feud score is ({) $gettok($read(FFScores.txt, $readn),2,32) [br] (*) Current Feud Leader is ({) $gettok($read(FFScores.txt,1),1,32) with (H) $gettok($read(FFScores.txt,1),2,32)  
  } 
}

;Accounts for nickname changes mid-game.
on *:NICK:{
  if ( %FF.score. [ $+ [ $nick ] ] != $null ) {
    set %FF.score. [ $+ [ $newnick ] ] %FF.score. [ $+ [ $nick ] ]
    unset %FF.score. [ $+ [ $nick ] ]
  }
}


;If you have another feature you would like to see, let me know and I'll add it if possible!
