Mafia

By Jelly on Apr 27, 2015

I don't remember if this is the final version or not but I felt like posting it anyway.

Written without use of ini storage just to make things a bit more fun (similar to pokescript)

code appended is circa april 2014 I believe

it's mafia (the party game)

;Mafia for #RAOAmazon on Freenode // http://www.reddit.com/r/random_acts_of_amazon by Robert Ward 
;Some code partially kanged from http://hawkee.com/snippet/9979/

;Chat commands

;Collect police arrest input via notice
on *:NOTICE:!arrest*:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActivePoliceman,$nick,44)) { msg $nick You are not an active Police Officer. | halt  }
  if (%PoliceVoteArrestTimer != on) { msg $nick It is not currently time to arrest somebody. | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot arrest yourself. | halt }
  if (%Policeman1 == $nick) { set %PoliceVote1 $2 | msg $nick You have voted to arrest $2 $+ . }
  if (%Policeman2 == $nick) { set %PoliceVote2 $2 | msg $nick You have voted to arrest $2 $+ . }
}

;Collect police arrest input via query/msg
on *:TEXT:!arrest*:?:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActivePoliceman,$nick,44)) { msg $nick You are not an active Police Officer. | halt  }
  if (%PoliceVoteArrestTimer != on) { msg $nick It is not currently time to arrest somebody. | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot arrest yourself. | halt }
  if (%Policeman1 == $nick) { set %PoliceVote1 $2 | msg $nick You have voted to arrest $2 $+ . }
  if (%Policeman2 == $nick) { set %PoliceVote2 $2 | msg $nick You have voted to arrest $2 $+ . }
}

;Collect police arrest input via police channel
on *:TEXT:!arrest*:#raoa_police:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActivePoliceman,$nick,44)) { msg $nick You are not an active Police Officer. | halt  }
  if (%PoliceVoteArrestTimer != on) { msg $nick It is not currently time to arrest somebody. | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot arrest yourself. | halt }
  if (%Policeman1 == $nick) { set %PoliceVote1 $2 | msg $nick You have voted to arrest $2 $+ . }
  if (%Policeman2 == $nick) { set %PoliceVote2 $2 | msg $nick You have voted to arrest $2 $+ . }
}

;Allow players to change their yes/no vote for the final hanging vote
on *:TEXT:!changevote:#raoagameroom: {
  /checkMafiaRunning
  /checkActivePlayer
  if (%FinalVoteTimer != on) { msg $nick It is not currently time to vote. | halt }
  if (!$istok(%FinalVotedPlayers,$nick,44)) { msg $nick You haven't voted yet, use !vote | halt }
  if ($2 == no) {
    inc %no
    inc %yes -1
    msg $nick You have changed your vote to no
    return
  }
  if ($2 == yes) {
    inc %yes
    inc %no -1
    msg $nick You have changed your vote to yes.
    return
  }
  else { msg $nick Invalid input, please use !changevote yes or !changevote no | halt }
}

;collect bartender's intoxication input via notice
on *:NOTICE:!intox*:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (%BartenderTimer != on) { return }
  if (!$istok(%ActiveBartender,$nick,44)) { return }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | return }
  if ($2 == $nick) { msg $nick You cannot intoxicate yourself. | return }
  set %PlayerToIntox $2
  msg $nick You have chosen to intoxicate $2 $+ .
}

;collect bartender's intoxication input via query/msg
on *:TEXT:!intox*:?:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (%BartenderTimer != on) { return }
  if (!$istok(%ActiveBartender,$nick,44)) { return }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | return }
  if ($2 == $nick) { msg $nick You cannot intoxicate yourself. | return }
  set %PlayerToIntox $2
  msg $nick You have chosen to intoxicate $2 $+ .
}

;collect detective's snooping input via notice
on *:NOTICE:!investigate*:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (%DetectiveTimer != on) { return }
  if (!$istok(%ActiveDetective,$nick,44)) { return }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | return }
  if ($2 == $nick) { msg $nick You cannot investigate yourself. | return }
  set %PlayerToSnoop $2
  msg $nick You have chosen to snoop on $2 $+ .
}

;collect detective's snooping input via query/msg
on *:TEXT:!investigate*:?:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (%DetectiveTimer != on) { return }
  if (!$istok(%ActiveDetective,$nick,44)) { return }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | return }
  if ($2 == $nick) { msg $nick You cannot investigate yourself. | return }
  set %PlayerToSnoop $2
  msg $nick You have chosen to snoop on $2 $+ .
}

;Allows players to join the game if they haven't already.
on *:TEXT:!join:#raoagameroom:{
  /checkMafiaRunning
  if ( %JoinPeriod == false ) { halt }
  elseif ( $istok(%Players,$nick,44) ) { msg $nick You are already a player. | halt }
  set %Players $addtok(%Players,$nick,44)
  set %Players2 $addtok(%Players2,$nick,44)
  set %ActivePlayers $addtok(%ActivePlayers,$nick,44)
  tellPlayers $nick has joined the game as player [ $numtok(%Players,44) ]
}

;Collect mafia kill input via notice
on *:NOTICE:!kill*:{
  /checkMafiaRunning
  /checkActivePlayer
  if (!$istok(%ActiveMafia,$nick,44)) { msg $nick You are not an active Mafia member. | halt }
  if (%MafiaVoteKillTimer != on) { msg $nick It is not currently time to kill somebody. | halt }
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot kill yourself. | halt  }
  if (%Mafia1 == $nick) { set %MafiaVote1 $2 | msg $nick You have selected $2 to be killed. }
  if (%Mafia2 == $nick) { set %MafiaVote2 $2 | msg $nick You have selected $2 to be killed. }
  if (%Mafia3 == $nick) { set %MafiaVote3 $2 | msg $nick You have selected $2 to be killed. }
}

;collect mafia kill input via query/msg
on *:TEXT:!kill*:?:{
  /checkMafiaRunning
  /checkActivePlayer
  if (!$istok(%ActiveMafia,$nick,44)) { msg $nick You are not an active Mafia member. | halt }
  if (%MafiaVoteKillTimer != on) { msg $nick It is not currently time to kill somebody. | halt }
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot kill yourself. | halt  }
  if (%Mafia1 == $nick) { set %MafiaVote1 $2 | msg $nick You have selected $2 to be killed. }
  if (%Mafia2 == $nick) { set %MafiaVote2 $2 | msg $nick You have selected $2 to be killed. }
  if (%Mafia3 == $nick) { set %MafiaVote3 $2 | msg $nick You have selected $2 to be killed. }
}

;collect mafia kill input in the mafia channel
on *:TEXT:!kill*:#raoa_mafia:{
  /checkMafiaRunning
  /checkActivePlayer
  if (!$istok(%ActiveMafia,$nick,44)) { msg $nick You are not an active Mafia member. | halt }
  if (%MafiaVoteKillTimer != on) { msg $nick It is not currently time to kill somebody. | halt }
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot kill yourself. | halt  }
  if (%Mafia1 == $nick) { set %MafiaVote1 $2 | msg $nick You have selected $2 to be killed. }
  if (%Mafia2 == $nick) { set %MafiaVote2 $2 | msg $nick You have selected $2 to be killed. }
  if (%Mafia3 == $nick) { set %MafiaVote3 $2 | msg $nick You have selected $2 to be killed. }
}

;kicks players from the game if they leave
on *:part:#raoagameroom:{
  /checkMafiaRunning
  if (!$istok(%Players,$nick,44)) { halt }
  else {
    set %Players $remtok(%Players,$nick,1,44)
    tellplayers  $nick has left the game (parted)
  }
}

;Take player input for a No on final vote
on *:TEXT:!no:#raoagameroom: {
  /checkMafiaRunning
  /checkActivePlayer
  if (%FinalVoteTimer != on) { msg $nick It is not currently time to vote. | halt }
  if (!$istok(%FinalVotedPlayers,$nick,44)) {
    inc %no
    set %FinalVotedPlayers $addtok(%FinalVotedPlayers,$nick,44)
    return
  }
  else { notice $nick You've already voted, to change your vote, use !changevote <yes|no> | halt  }
}

;List current active players
on *:TEXT:!players:#raoagameroom: {
  /checkmafiarunning
  /checkactiveplayer
  msg $nick %ActivePlayers
}

;Allow players to change their votes, adjust our variables and INI accordingly.
on *:TEXT:!revote*:#raoagameroom: {
  /checkMafiaRunning
  /checkActivePlayer
  if (%VoteTimer != on) { msg $nick It is not currently time to vote | halt }
  if (!$istok(%VotedPlayers,$nick,44)) { msg $nick Please use !vote | halt }
  inc %KillPlayer. $+ % [ $+ [ $nick ] $+ .VotedFor ] ]  -1
  writeini -n mafia.ini numVotesFor $2 %KillPlayer [ $+ [ . [ $+ [ $2 ] ] ] ] 
  set %PlayersVotedFor $remtok(%PlayersVotedFor,% $+ [ $nick $+ . $+ [ VotedFor ] ],44)
  set %PlayersVotedFor $addtok(%PlayersVotedFor,$2,44)
  set % $+ [ $nick $+ . $+ [ VotedFor ] ] $2
  inc %KillPlayer. $+ % [ $+ [ $nick ] $+ .VotedFor ] ] 
  writeini -n mafia.ini numVotesFor $2 %KillPlayer [ $+ [ . [ $+ [ $2 ] ] ] ] 
  writeini -n mafia.ini votesFor $nick $2
  msg $nick You have changed your vote to $2
}

;collect doctor's saving input via notice
on *:NOTICE:!save*:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActiveDoctor,$nick,44)) { msg $nick You are not an active Doctor | halt }
  if (%DoctorTimer != on) { msg $nick It is not currently time to save somebody. | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot save yourself. | halt }
  set %PlayerToSave $2
  msg $nick You have chosen to save $2 $+ .
}

;collect doctor's saving input via query/pm
on *:TEXT:!save*:?:{
  /checkMafiaRunning
  /checkActivePlayer
  if ($2 == $null) { msg $nick You need to specify another player | halt }
  if (!$istok(%ActiveDoctor,$nick,44)) { msg $nick You are not an active Doctor | halt }
  if (%DoctorTimer != on) { msg $nick It is not currently time to save somebody. | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  if ($2 == $nick) { msg $nick You cannot save yourself. | halt }
  set %PlayerToSave $2
  msg $nick You have chosen to save $2 $+ .
}

;Start the game, only usable by @ops. 
on *:TEXT:!start:#raoagameroom:{
  if ( $nick isop $chan ) {
    if ( %MafiaRunning == true ) { notice $nick The game is already running. | halt }
    elseif ( %MafiaRunning != true ) {
      set %MafiaRunning true
      set %JoinPeriod true
      tellPlayers Welcome to Mafia.
      tellPlayers You can join the game by typing !join within the next 30 seconds.
      /timer2 1 30 set %JoinPeriod false
      /timer398 1 30 initGame
    }
  }
  else { notice $nick You have to be an @op to start the game. }
}

;Stop the game, only usable by @ops
on *:TEXT:!stop:#raoagameroom:{
  if ( $nick isop $chan ) {
    if ( %MafiaRunning != false ) {
      haltgame
      tellplayers The game has been ended by $nick $+ .
      halt
    }
    if ( %MafiaRunning == false ) { notice $nick The game isn't running | halt }
  }
  else { notice $nick You have to be an @op to stop the game. | halt }
}

;Accept player vote input on who to hang 
on *:TEXT:!vote*:#raoagameroom: {
  /checkMafiaRunning
  /checkActivePlayer
  if (%VoteTimer != on) { msg $nick It is not currently time to vote. | halt }
  if ($istok(%VotedPlayers,$nick,44)) { msg $nick You've already voted, if you'd like to change your vote, use !revote | halt }
  if (!$istok(%ActivePlayers,$2,44)) { msg $nick That's not a valid player. Active players are: %ActivePlayers | halt }
  set %VotedPlayers $addtok(%VotedPlayers,$nick,44)
  inc %KillPlayer [ $+ [ . [ $+ [ $2 ] ] ] ] 
  writeini -n mafia.ini numVotesFor $2 %KillPlayer [ $+ [ . [ $+ [ $2 ] ] ] ] 
  set % $+ [ $nick $+ . $+ [ VotedFor ] ] $2
  writeini -n mafia.ini votesFor $nick $2
  set %PlayersVotedFor $addtok(%PlayersVotedFor,$2,44)
  msg $nick You have voted to hang $2
}

;Allows players to opt out of the game.
on *:TEXT:!quit:#raoagameroom:{
  if (%JoinPeriod == false) { halt }
  elseif (!$istok(%Players,$nick,44)) { msg $nick You are not currently playing | halt }
  else {
    set %Players $remtok(%Players,$nick,1,44)
    set %Players2 $remtok(%Players2,$nick,1,44)
    set %ActivePlayers $remtok(%ActivePlayers,$nick,1,44)
    tellplayers  $nick has left the game (quit)
  }
}

;Take player input for a yes on final vote
on *:TEXT:!yes:#raoagameroom: {
  /checkMafiaRunning
  /checkActivePlayer
  if (%FinalVoteTimer != on) { msg $nick It is not currently time to vote. | halt }
  if (!$istok(%FinalVotedPlayers,$nick,44)) {
    inc %yes
    set %FinalVotedPlayers $addtok(%FinalVotedPlayers,$nick,44)
  }
  else { notice $nick You've already voted, to change your vote, use !changevote <yes|no> | halt  }
}

;alias'

;Assign each player a role
alias assignRoles {
  /checkmafiarunning
  var %i 0
  var %n $numtok(%Players,44)
  var %AvailableRoles
  var %availableRoles $addtok(%AvailableRoles,Citizen,44)
  var %availableRoles $addtok(%AvailableRoles,Mafia1,44)
  var %availableRoles $addtok(%AvailableRoles,Doctor,44)
  set %thisGameRoles $addtok(%thisGameRoles, Doctor,44)
  var %AvailableRoles $addtok(%AvailableRoles,Policeman1,44)
  if ($numtok(%Players,44) > 4) {
    var %availableRoles $addtok(%AvailableRoles,Detective,44)
    set %thisGameRoles $addtok(%thisGameRoles, Detective,44)
  }
  if ($numtok(%players,44) > 6) { var %AvailableRoles $addtok(%AvailableRoles,Policeman2,44) }
  if ($numtok(%Players,44) >= 8) { var %AvailableRoles $addtok(%AvailableRoles,mafia2,44) }
  if ( $numtok(%players,44) > 8) {
    var %AvailableRoles $addtok(%AvailableRoles,Bartender,44)
    set %thisGameRoles $addtok(%thisGameRoles, Bartender,44)
  }
  if ($numtok(%players,44) >= 11) { var %AvailableRoles $addtok(%AvailableRoles,mafia3,44) }
  while (%i <= %n) {
    var %playerNum $rand(1,$numtok(%players2,44))
    set %player $gettok(%Players2,%playerNum,44)
    set %who $gettok(%Players2,%playerNum,44)
    if ($numtok(%Citizens,44) = 0) { goto 6 }
    if ($istok(%AvailableRoles,Doctor,44)) { goto 1 }
    if (!$istok(%AvailableRoles,Doctor,44)) { goto 2 }
    :1
    set %Doctor $addtok(%Doctor,%who,44)
    set %ActiveCitizens $addtok(%ActiveCitizens,%who,44)
    set %ActiveDoctor $addtok(%ActiveDoctor,%who,44)
    var %AvailableRoles $remtok(%AvailableRoles,Doctor,44)
    set %Players2 $deltok(%Players2,%PlayerNum,44)
    inc %i
    continue
    :2
    if ( !$istok(%AvailableRoles,Detective,44)) { goto 3 }
    else {
      set %Detective $addtok(%Detective,%who,44)
      set %ActiveCitizens $addtok(%ActiveCitizens,%who,44)
      set %ActiveDetective $addtok(%ActiveDetective,%who,44)
      var %AvailableRoles $remtok(%AvailableRoles,Detective,44)
      set %Players2 $deltok(%Players2,%PlayerNum,44)
      inc %i
      continue
    }
    :3
    if ( !$istok(%AvailableRoles,Policeman1,44)) {
      if (!$istok(%AvailableRoles,Policeman2,44)) { goto 4 }
      else {
        set %Policeman $addtok(%Policeman,%who,44)
        set %ActiveCitizens $addtok(%ActiveCitizens,%who,44)
        set %Policeman2 %who
        set %ActivePoliceman $addtok(%ActivePoliceman,%who,44)
        var %AvailableRoles $remtok(%AvailableRoles,Policeman2,44)
        set %Players2 $deltok(%Players2,%PlayerNum,44)
        inc %i
        continue
      }
    }
    else {
      set %Policeman $addtok(%Policeman,%who,44)
      set %ActiveCitizens $addtok(%ActiveCitizens,%who,44)
      set %Policeman1 %who
      set %ActivePoliceman $addtok(%ActivePoliceman,%who,44)
      var %AvailableRoles $remtok(%AvailableRoles,Policeman1,44)
      set %Players2 $deltok(%Players2,%PlayerNum,44)
      inc %i
      continue
    }
    :4
    if ( !$istok(%AvailableRoles,Bartender,44)) { goto 5 }
    else {
      set %bartender $addtok(%bartender,%who,44)
      set %ActiveCitizens $addtok(%ActiveCitizens,%who,44)
      set %ActiveBartender $addtok(%ActiveBartenders,%who,44)
      var %AvailableRoles $remtok(%AvailableRoles,Bartender,44)
      set %Players2 $deltok(%Players2,%PlayerNum,44)
      inc %i
      continue
    }
    :5
    if ( !$istok(%AvailableRoles,Mafia1,44)) {
      if (!$istok(%AvailableRoles,Mafia2,44)) {
        if (!$istok(%AvailableRoles,Mafia3,44)) { goto 6 }
        else {
          set %Mafia $addtok(%Mafia,%who,44)
          set %Mafia3 %who
          set %ActiveMafia $addtok(%ActiveMafia,%who,44)
          var %AvailableRoles $remtok(%AvailableRoles,Mafia3,44)
          set %Players2 $deltok(%Players2,%PlayerNum,44)
          inc %i
          continue
        }
      }
      else {
        set %Mafia $addtok(%Mafia,%who,44)
        set %Mafia2 %who
        set %ActiveMafia $addtok(%ActiveMafia,%who,44)
        var %AvailableRoles $remtok(%AvailableRoles,Mafia2,44)
        set %Players2 $deltok(%Players2,%PlayerNum,44)
        inc %i
        continue
      }
    }
    else {
      set %Mafia $addtok(%Mafia,%who,44)
      set %Mafia1 %who
      set %ActiveMafia $addtok(%ActiveMafia,%who,44)
      var %AvailableRoles $remtok(%AvailableRoles,Mafia1,44)
      set %Players2 $deltok(%Players2,%PlayerNum,44)
      inc %i
      continue
    }
    :6
    set %citizens $addtok(%citizens,%who,44)
    set %CitizensOnly $addtok(%CitizensOnly,%who,44)
    set %ActiveCitizensOnly $addtok(%ActiveCitizensOnly,%who,44)
    set %ActiveCitizens $addtok(%ActiveCitizens,%who,44)
    set %Players2 $deltok(%Players2,%PlayerNum,44)
    inc %i
    continue
  }
}

;calculate our final vote, hang if yes, don't hang if tie or no.
alias calcFinalVote {
  checkmafiarunning
  if (%yes > %no) {
    set %ActivePlayers $remtok(%ActivePlayers,%CurrentHighest,1,44)
    if ($istok(%ActiveDetective,%CurrentHighest,44)) { set %ActiveDetective $remtok(%ActiveDetective,%CurrentHighest,1,44) }
    if ($istok(%ActiveMafia,%CurrentHighest,44)) { set %ActiveMafia $remtok(%ActiveMafia,%CurrentHighest,1,44) }
    if ($istok(%ActiveCitizens,%CurrentHighest,44)) {
      set %ActiveCitizens $remtok(%ActiveCitizens,%CurrentHighest,1,44)
      set %ActiveCitizensOnly $remtok(%ActiveCitizensOnly,%CurrentHighest,1,44)
    }
    if ($istok(%ActiveDoctor,%CurrentHighest,44)) { set %ActiveDoctor $remtok(%ActiveDoctor,%CurrentHighest,1,44) }
    if ($istok(%ActiveBartender,%CurrentHighest,44)) { set %ActiveBartender $remtok(%ActiveBartender,%CurrentHighest,1,44) }
    set %FinalHangMessage Ooh, bad luck for %CurrentHighest $+ , the townsfolk have chosen to hang them.
    TellPlayers someone fuckin got hanged %currenthighest
  }
  if (%no >= %yes) {
    set %FinalHangMessage Good news for you %CurrentHighest $+ , the towns folk chose not to hang you!
    TellPlayers noone fuckin got hanged fuck %currenthighest 
  }
}

;Calculate the results of the hanging !!WORK IN PROGRESS!!
alias calcHang {
  checkmafiarunning
  if ( %PlayersVotedFor != $null ) {
    var %i 1
    var %n $numtok(%VotedPlayers,44)
    while (%i <= %n) {
      var %tempNick $gettok(%VotedPlayers,%i,44)
      var %tempNickVotedFor $readini(Mafia.ini,votesFor,%tempNick)
      var %tempNickVotedForCount $readini(mafia.ini,numVotesFor,%tempNickvotedfor)
      if (%i == 1) {
        set %CurrentHighest %tempNickVotedFor
        set %CurrentHighCount %tempNickVotedForCount
      }
      else {
        if (%tempNickVotedForCount > %CurrentHighCount) { 
          set %CurrentHighest %tempNickVotedFor
          set %CurrentHighCount %tempNickVotedForCount
        }
      }
      inc %i
    }
    set %SomeoneWasVotedFor yes
    set %hangMessage The citizens have selected %CurrentHighest to be hanged, with %CurrentHighCount votes.
  }
  if (%PlayersVotedFor == $null) {
    set %SomeoneWasVotedFor $null
    set %hangMessage The citizens elected not to hang anyone today.
  }
  /timer79 1 20 tellplayers %hangMessage
  /timer100 1 35 checkSecondVote
}

;calculate the results of the night, invalidating kills or arrests, etc. Build our output for the players 
alias calcNight {
  checkmafiarunning
  if (%ActiveBartender) {
    if (%PlayerToIntox) {
      if ($istok(%ActiveMafia,%PlayerToIntox,44)) {
        if ($numtok(%ActiveMafia,44) == 1) {
          set %PlayerToKill $null
          set %IntoxMessage %PlayerToIntox got a bit liquored up last night and had to stay at the bar.
        }
      }
      if (%PlayerToKill == %PlayerToIntox) {
        set %PlayerToKill $null
        set %IntoxMessage %PlayerToIntox might've had some bad luck last night, but luckily they got a bit too liquored up and had to stay at the bar.
      }
      if ($istok(%ActiveDoctor,%PlayerToIntox,44)) {
        set %PlayerToSave $null
        set %IntoxMessage %ActiveDoctor got a bit liquored up last night and had to stay at the bar.
      }
      if (%PlayerToIntox == %PlayerToSnoop) {
        set %PlayerToSnoop $null
        set %IntoxMessage Someone was snooping around %PlayerToIntox $+ 's house last night, but %PlayerToIntox was stuck at the bar.
      }
      if ($istok(%ActiveDetective,%PlayerToIntox,44)) {
        set %PlayerToSnoop $null
        set %IntoxMessage %PlayerToIntox got a bit liquored up last night and had to stay at the bar.
      }
      if ($istok(%ActivePoliceman,%PlayerToIntox,44)) {
        if ($numtok(%ActivePoliceman,44)) == 1) {
          set %PlayerToArrest $null
          set %IntoxMessage %PlayerToIntox got a bit liquored up last night and had to stay at the bar.
        }
      }
      if ($istok(%ActiveCitizens,%PlayerToIntox,44)) {
        if ($istok(%ActiveCitizensOnly,%PlayerToIntox,44)) {
          set %IntoxMessage %PlayerToIntox got a bit liquored up last night and had to stay at the bar.
        }
      }
    }
    if (%PlayerToIntox == $null) {
      set %IntoxMessage Looks like it was a quiet night at the bar, no one had to stay over night
    }
  }
  if (%ActiveDoctor != $null ) {
    if (%PlayerToSave != $null ) {
      if (%PlayerToSave == %PlayerToKill) {
        set %PlayerToKill $null
        set %MafiaInterceptedMessage %PlayerToSave was brutally gunned down by The Mafia last night...
        set %DoctorMessage but luckily The Doctor was around to keep them alive.
      }
      else { set %DoctorMessage The Doctor was watching over someone this evening, but it doesn't seem they needed any help. }
    }
    if (%PlayerToSave == $null) { set %DoctorMessage Looks like The Doctor was on call all evening and didn't make out last night. }
  }
  if (%ActivePoliceman != $null ) {
    if (%PlayerToArrest != $null) {
      if ($istok(%ActiveMafia,%PlayerToArrest,44)) {
        if ($numtok(%ActiveMafia,44) == 1 ) {
          set %PlayerToKill $null
          set %PoliceMessage The Police decided %PlayerToArrest should spend last night in a cell.
        }
      }
      if (%PlayerToArrest == %ActiveDetective) {
        set %PlayerToSnoop $null
        set %DetectiveMessage The Police arrested you before you could learn your target's role.
        set %PoliceMessage The Police decided %PlayerToArrest should spend last night in a cell.
      }
      else { set %PoliceMessage The Police decided %PlayerToArrest should spend last night in a cell. }
    }
    if (%PlayerToArrest == $null) { set %PoliceMessage Looks like the police were too busy eating doughnuts to arrest anyone last night. }
  }
  if (%ActiveDetective != $null ) {
    if (%PlayerToSnoop != $null) {
      if ($istok(%ActiveMafia,%PlayerToSnoop,44)) { set %DetectiveMessage %PlayerToSnoop is a member of The Mafia.  | halt  }
      if ($istok(%ActiveDoctor,%PlayerToSnoop,44)) { set %DetectiveMessage %PlayerToSnoop is The Doctor. | halt }
      if ($istok(%ActivePoliceman,%PlayerToSnoop,44) { set %DetectiveMessage %PlayerToSnoop is a Police Officer. | halt }
      if ($istok(%ActiveBartender,%PlayerToSnoop,44) { set %DetectMessage %PlayerToSnoop is The Bartender. | halt }
      if ($istok(%ActiveCitizensOnly,%PlayerToSnoop,44) { set %DetectiveMessage %PlayerToSnoop is a Citizen. | halt }
    }
  }
  if (%ActiveMafia != $null) {
    if (%PlayerToKill != $null) {
      if (%PlayerToKill == %Doctor) {
        set %ActiveMafia $remtok(%ActiveDoctor,%PlayerToKill,1,44)
        set %ActivePlayers $remtok(%ActivePlayers,%PlayerToKill,1,44)
        set %ActiveCitizens $remtok(%ActiveCitizens,%PlayerToKill,1,44)
      }
      if ($istok(%ActivePoliceman,%PlayerToKill,44)) {
        set %ActivePoliceman $remtok(%ActivePoliceman,%PlayerToKill,1,44)
        set %ActivePlayers $remtok(%ActivePlayers,%PlayerToKill,1,44)
        set %ActiveCitizens $remtok(%ActiveCitizens,%PlayerToKill,1,44)
      }
      if (%PlayerToKill == %Detective) {
        set %ActiveDetective $remtok(%ActiveDetective,%PlayerToKill,1,44)
        set %ActivePlayers $remtok(%ActivePlayers,%PlayerToKill,1,44)
        set %ActiveCitizens $remtok(%ActiveCitizens,%PlayerToKill,1,44)
      }
      if (%PlayerToKill == %Bartender) {
        set %ActiveBartender $remtok(%ActiveBartender,%PlayerToKill,1,44)
        set %ActivePlayers $remtok(%ActivePlayers,%PlayerToKill,1,44)
        set %ActiveCitizens $remtok(%ActiveCitizens,%PlayerToKill,1,44)
      }
      if ($istok(%ActiveCitizens,%PlayerToKill,44)) {
        set %ActiveCitizens $remtok(%ActiveCitizens,%PlayerToKill,1,44)
        set %ActivePlayers $remtok(%ActivePlayers,%PlayerToKill,1,44)
        set %ActiveCitizens $remtok(%ActiveCitizens,%PlayerToKill,1,44)
        set %ActiveCitizensOnly $remtok(%ActiveCitizensOnly,%PlayerToKill,1,44)
      }
      set %MafiaMessage Late last night, The Mafia rolled up to %PlayerToKill and brutally gunned them down.
    }
    if (%PlayerToKill == $null) { set %MafiaMessage Looks like The Mafia was busy last night, no one was killed. }
  }
}

;Call for the final yes/no vote once we've selected someone to be hanged
alias callFinalVote {
  checkmafiarunning
  tellplayers You have sixty seconds to vote !yes or !no on whether or not to hang %CurrentHighest $+ .
  set %FinalVoteTimer on
  set %yes 0
  set %no 0
  /timer81 1 60 set %FinalVoteTimer off
  /timer80 1 60 /calcFinalVote
}

;Call for the vote for someone to be hanged
alias callForVote {
  checkmafiarunning
  set %voteTimer on
  /timer77 1 120 set %voteTimer off
  tellPlayers It's the dawn of a new day. You have two minutes to discuss amongst yourselves whether or not to hang someone, and vote on who to hang.
  tellPlayers You can vote for someone by typing !vote <user>
  /timer74 1 60 tellplayers One minute remains
  /timer75 1 90 tellplayers Thirty seconds remain.
  /timer76 1 110 tellplayers Ten seconds remain.
}

;Check to make sure the user is an active player
alias checkActivePlayer { if (!$istok(%ActivePlayers,$nick,44)) { msg $nick You are not an active player | halt } }

;Check to see if the citizens have won
alias checkCitizenWin {
  if ($numtok(%ActiveMafia,44) == 0) {
    set %CitizenWin true 
    TellPlayers The Citizens have successfully hanged all of The Mafia members. Citizens win! Good game everybody!
    /gamecredits
    /haltgame
    halt
  }
}

;Check to make sure that mafia is currently running 
alias checkMafiaRunning { if (%MafiaRunning != true) { msg $nick The Mafia game is not currently running | halt } }

;Check to see if the mafia have won
alias checkMafiaWin { if ($numtok(%ActiveCitizens,44) == 0) { set %MafiaWin true } }

;Check to see if someone was nominated for hanging, call second vote if they were, otherwise start next night round
alias checkSecondVote {
  checkmafiarunning
  if (%SomeoneWasVotedFor != $null) {
    /callFinalVote
    /timer256 1 90 tellplayers %FinalHangMessage
    /timer267 1 90 /checkCitizenWin
}
}

;Decide who gets killed, arrested, etc, check to see if the mafia have won, initalize day time.
alias computeNight {
  checkmafiarunning
  /decideMafiaKill
  /decidePoliceArrest
  /calcNight
  /checkMafiaWin
  /dayTime
}

;Explain the night time, call for hanging 
alias dayTime {
  checkmafiarunning
  /explainNight
  if (%MafiaWin == true) {
    tellPlayers The Mafia have successfully killed all of the citizens. Mafia win! Good game everybody!
    /gameCredits
    /haltgame
    halt
  }
  /timer101 1 30 /callForVote
  /timer73 1 180 /calcHang
}

;Count our mafia and run the vote count accordingly 
alias decideMafiaKill {
  checkmafiarunning
  if ($numtok(%ActiveMafia,44) == 3 ) { /threeMafia }
  if ($numtok(%ActiveMafia,44) == 2 ) { /twoMafia }
  if ($numtok(%ActiveMafia,44) == 1 ) { /oneMafia }
}

;Count our police and run the vote count accordingly
alias decidePoliceArrest {
  checkmafiarunning
  if ($numtok(%ActivePoliceman,44) == 2) { /twoPolice }
  if ($numtok(%ActivePoliceman,44) == 1) { /onePolice }
}

;Devoice all players in the channel !!CURRENTLY UNUSED!!
alias devoiceall {
  checkmafiarunning
  var %i = 1
  while (%i <= $numtok(%ActivePlayers,44)) {
    mode #raoagameroom -v $gettok(%ActivePlayers,%i,44)
    inc %i
  }
}

;Explain each role to the players (only at the beginning of the game)
alias explainGame {
  checkmafiarunning
  tellplayers Each of you have been given a role, and each role has a function.
  /timer46 1 2 tellplayers Citizens are your run of the mill characters. All players by default are citizens. You can vote to hang (or not to hang) someone each day. If they hang all of the Mafia, the citizens win.
  /timer47 1 4 tellplayers Policeman can arrest a player for a night, cancelling any actions played by them. If there are two policemen, they must agree on who to arrest.
  if ($istok(%thisGameRoles,Doctor,44)) { /timer48 1 8 tellplayers The Doctor: Every night The doctor can protect one player from being killed. }
  if ($istok(%thisGameRoles,Detective,44)) { /timer49 1 6 tellplayers Detective: Every night, the Detective can investigate a player and learn their roles. Use this information wisely, revealing that you're the detective can get you killed. }
  if ($istok(%thisGameRoles,Bartender,44)) { /timer51 1 10 tellplayers The Bartender can intoxicate someone each night, negating anything done to them or by them during that evening. }
  /timer50 1 6 tellplayers The Mafia choose a player to kill each night. If all of the citizens die, the mafia win.
}

;Output the results of calcNight (tell players who died, was arrested, etc)
alias explainNight {
  checkmafiarunning
  if (%IntoxMessage != $null ) { /timer70 1 5 tellplayers %IntoxMessage }
  if (%MafiaInterceptedMessage != $null ) { /timer502 1 6 tellplayers %MafiaInterceptedMessage } 
  if (%DoctorMessage != $null ) { /timer71 1 7 tellplayers %DoctorMessage }
  if (%PoliceMessage != $null ) { /timer72 1 9 tellplayers %PoliceMessage }
  if (%DetectiveMessage != $null ) { notice %ActiveDetective %DetectiveMessage }
  if (%MafiaInterceptedMessage == $null) { /timer173 1 11 tellPlayers  %MafiaMessage | msg %PlayerToKill Oh dear, you are dead! }
}

;tell players eachother's roles
alias gameCredits {
  if (%Doctor != $null) { tellplayers Our Doctor: %Doctor $+ ! }
  if (%Mafia != $null) { tellplayers Our Mafia: %Mafia $+ ! }
  if (%Policeman != $null) { tellplayers Our Officers: %Policeman $+ ! }
  if (%Detective != $null) { tellplayers Our Detective: %Detective $+ ! }
  if (%Bartender != $null) { tellplayers Our Bartender: %Bartender $+ ! }
  if (%CitizensOnly != $null) { tellplayers And our regular ol' citizens: %CitizensOnly $+ ! }
}

;spin down the game, unset variables.
alias haltgame {
  checkmafiarunning
  set %MafiaRunning false
  set %JoinPeriod false
  unset %players*
  unset %CurrentPlayers
  unset %CitizenWin
  unset %CurrentHighCount
  unset %CurrentHighest
  unset %killplayer*
  unset %FinalHangMessage 
  unset %CitizensOnly
  unset %VotedPlayers
  unset %Mafia
  unset %MafiaInterceptedMessage
  unset %citizens
  unset %doctor
  unset %policeman
  unset %drunk
  unset %bartender
  unset %Active*
  unset %yes
  unset %no
  unset %Detective
  unset %availableroles
  unset %i
  unset %n
  unset %who
  unset %Mafia1
  unset %Mafia2
  unset %Mafia3
  unset %policeman1
  unset %policeman2
  unset %thisGameRoles
  unset %nightCount
  unset %MafiaVoteKillTimer
  unset %BartenderTimer
  unset %PoliceVoteArrestTimer
  unset %DoctorTimer
  unset %DetectiveTimer
  unset %IntoxMessage
  unset %DoctorMessage
  unset %DetectiveMessage
  unset %MafiaMessage
  unset %PoliceMessage
  unset %MafiaWin
  unset %CitizenWin
  unset %*.votedFor
  unset %Player
  unset %SomeoneWasVotedFor
  unset %PlayerToArrest
  unset %VoteTimer
  unset %tempNick
  unset %hangMessage
  unset %PlayerToSnoop 
  unset %PlayerToKill 

}

;initalize the game, end if not enough players, otherwise assign roles and begin the first round.
alias initGame {
  checkmafiarunning
  if ($numtok(%Players,44) < 4) {
    tellplayers Not enough players joined the game, try again with more players. The game has been ended.
    haltGame | return
  }
  tellplayers  Welcome to Mafia. Please sit tight while I assign your roles. Do not share your role with the other players!
  assignRoles
  tellplayers There are [ $numtok(%Players,44) ] players in this game, so the roles are: %thisGameRoles $+ , $numtok(%Mafia,44) Mafia members, $numtok(%Policeman,44) Policemen, and $numtok(%Citizens,44) Citizens.
  initGameRooms
  /timer35 1 10 tellroles
  /timer62 1 20 initGameRooms
  /timer63 1 25 explainGame
  tellPlayers The game will start in one minute.
  /timer64 1 60 /night
}

;Initialize the mafia and police rooms, invite the players as needed. 
alias initGameRooms {
  checkmafiarunning
  /timer31 1 3 /cs invite #raoa_mafia
  /timer32 1 3 /cs invite #raoa_police
  /timer33 1 5 /join #raoa_mafia
  /timer34 1 5 /join #raoa_police
  /timer37 1 9 /mode #raoa_mafia +isp
  /timer38 1 9 /mode #raoa_police +isp
  if (%mafia1) { /timer39 1 9 /invite %mafia1 #raoa_mafia }
  if (%Mafia2) { /timer40 1 9 /invite %mafia2 #raoa_mafia }
  if (%Mafia3) { /timer41 1 9 /invite %mafia3 #raoa_mafia }
  if (%Policeman1) { /timer42 1 9 /invite %policeman1 #raoa_police }
  if (%Policeman2) { /timer43 1 9 /invite %policeman2 #raoa_police }
  /timer44 1 9 notice %mafia Please type /join #raoa_mafia
  /timer45 1 9 notice %policeman Please type /join #raoa_police
}

;Night phase, unset relevant variables, prompt for player input and collect it. 
alias night {
  checkmafiarunning
  remove -b mafia.ini 
  inc %nightCount
  unset %yes
  unset %SomeoneWasVotedFor
  unset %VotedPlayers
  unset %CurrentHighest
  unset %CurrentHighCount
  unset %FinalVotedPlayers
  unset %PlayersVotedFor
  unset %no
  unset %MafiaInterceptedMessage
  unset %MafiaMessage
  unset %IntoxMessage
  unset %DoctorMessage
  unset %DetectiveMessage
  unset %PlayerToKill
  unset %PlayerToSave
  unset %PlayerToIntox
  unset %PlayerToArrest
  unset %PlayerToSnoop
  unset %HangMessage
  unset %KillPlayer*
  unset %FinalHangMessage 
  var %n $numtok(%Players,44)
  var %i 1
  while ( %i <= %n ) {
    var %tmpNick $gettok(%Players,%i,44)
    //unset % [ $+ [ %tmpNick ] $+ .VotedFor ]
    //unset %KillPlayer. [ $+ [ %tmpNick ] ]
    inc %i
  }
  set %MafiaVote1 PlaceHolder1
  set %MafiaVote2 PlaceHolder2
  set %MafiaVote3 PlaceHolder3
  set %PoliceVote1 PlaceHolder1
  set %PoliceVote2 PlaceHolder2
  tellplayers Welcome to the $ord(%nightCount) night, darkness has fallen over the town, and the denizens of the night begin to stir.
  tellplayers Night time lasts for 90 seconds, please wait for all players to make their moves. Remember players, you are not required to make a move every night.
  /timer500 1 90 /computeNight
  msg %ActiveMafia Wake up! Please look at #Raoa_mafia
  msg #RAOA_MAFIA Choose who to kill with !kill <user>
  msg #RAOA_MAFIA Active players are: %ActivePlayers
  msg #RAOA_MAFIA You have 60 seconds to decide, choose wisely.
  set %MafiaVoteKillTimer on
  /timer52 1 60 /set %MafiaVoteKillTimer off
  /timer53 1 50 /msg #RAOA_MAFIA 10 seconds remain to decide if you haven't yet.
  if ($numtok(%ActivePoliceman,44) != 0) {
    msg %ActivePoliceman Wake up! Please look at #Raoa_Police
    msg #RAOA_POLICE Choose someone to arrest with !arrest <user>
    msg #RAOA_POLICE Active players are: %ActivePlayers
    msg #RAOA_POLICE You have 60 seconds to decide, choose wisely.
    set %PoliceVoteArrestTimer on
    /timer54 1 60 /set %PoliceVoteArrestTimer off
    /timer55 1 50 /msg #RAOA_POLICE 10 seconds remain to decide if you haven't yet.
  }
  if ($numtok(%ActiveBartender,44) != 0) {
    msg %ActiveBartender Wake up! Choose someone to intoxicate by typing !intox <user>
    msg %ActiveBartender You have 60 seconds to decide, choose wisely.
    set %BartenderTimer on
    /timer56 1 60 /set %BartenderTimer off
    /timer57 1 50 /msg %ActiveBartender 10 seconds remain to decide if you haven't yet.
  }
  if ($numtok(%ActiveDoctor,44) != 0) {
    msg %ActiveDoctor Wake up! Choose someone to save by typing /msg $me !save <user> (or /notice $me !save <user> ) 
    msg %ActiveDoctor You have 60 seconds to decide, choose wisely.
    set %DoctorTimer on
    /timer58 1 60 /set %DoctorTimer off
    /timer59 1 50 /msg %ActiveDoctor 10 seconds remain to decide if you haven't yet.
  }
  if ($numtok(%ActiveDetective,44) != 0) {
    msg %ActiveDetective Choose someone to snoop on with /msg $me !investigate <user> (or /notice $me !investigate <user> )
    msg %ActiveDetective You have 60 seconds to decide, choose wisely.
    set %DetectiveTimer on
    /timer60 1 60 /set %DetectiveTimer off
    /timer61 1 50 /msg %ActiveDetective 10 seconds remain to decide if you haven't yet.
  }
}

;run through our mafia votes if we only have one active mafia member.
alias oneMafia {
  checkmafiarunning
  if (%MafiaVote1 != PlaceHolder1 ) { set %PlayerToKill %MafiaVote1 | return }
  if (%MafiaVote2 != PlaceHolder2 ) { set %PlayerToKill %MafiaVote2 | return }
  if (%MafiaVote3 != PlaceHolder3 ) { set %PlayerToKill %MafiaVote3 | return }
  else { set %PlayerToKill $null  }
}

;run through our police votes if we only have one active officer
alias onePolice {
  checkmafiarunning
  if (%PoliceVote1 != PlaceHolder1) { set %PlayerToArrest %PoliceVote1 | return }
  if (%PoliceVote2 != PlaceHolder2) { set %PlayerToArrest %PoliceVote2 | return }
  else { set %PlayerToArrest $null | return }
}

;start game without needing an op
alias startgame {
  if (%MafiaRunning == true) { echo -a Game already running | halt }
  else { 
    set %MafiaRunning true
    set %JoinPeriod true
    tellPlayers Welcome to Mafia.
    tellPlayers You can join the game by typing !join within the next 30 seconds.
    /timer2 1 30 set %JoinPeriod false
    /timer398 1 30 initGame
  }
}

;message the mafia channel with output
alias tellPlayers { msg #raoagameroom  $1- }

;pre-halt-game, tell players the roles

;Tell the players their roles
alias tellRoles {
  checkmafiarunning
  /timer3 1 1 notice %citizens You are a citizen.
  /timer4 1 4 notice %doctor Allons-y, %Doctor $+ , you are The Doctor!
  /timer5 1 7 notice %bartender You are The Bartender.
  /timer6 1 11 notice %policeman Howdy officer, you are a Police Officer.
  /timer9 1 19 notice %detective Grab your suit and trench coat, because you're The Detective, %Detective $+ .
  if ($numtok(%police,44) > 1 ) {
    /timer7 1 13 notice %policeman1 The chief of police asked me to introduce you to your partner, %policeman2 $+ . Send them a message with /msg %policeman2
    /timer10 1 13 notice %policeman2 The chief of police asked me to introduce you to your partner, %policeman1 $+ . Send them a message with /msg %policeman1
  }
  msg %Mafia You are in The Mafia.
  if ($numtok(%Mafia,44) == 2 ) {
    /timer8 1 16 notice %Mafia1 The Godfather has asked me to introduce you to the rest of the family, %Mafia2 $+ . Send them a message with /msg %Mafia2
    /timer11 1 16 notice %Mafia2 The Godfather has asked me to introduce you to the rest of the family, %Mafia1 $+ . Send them a message with /msg %Mafia1
  }
  if ($numtok(%Mafia,44) == 3 ) {
    /timer8 1 16 notice %Mafia1 The Godfather has asked me to introduce you to the rest of the family, %Mafia2 and %Mafia3 $+ . Send them a message with /msg %Mafia2 $+ , $+ %mafia3
    /timer12 1 16 notice %Mafia2 The Godfather has asked me to introduce you to the rest of the family, %Mafia1 and %Mafia3 $+ . Send them a message with /msg %Mafia1 $+ , $+ %mafia3
    /timer13 1 16 notice %Mafia3 The Godfather has asked me to introduce you to the rest of the family, %Mafia2 and %Mafia1 $+ . Send them a message with /msg %Mafia2 $+ , $+ %mafia1
  }
}

;run through our mafia votes if we have three active mafia members
alias threeMafia {
  checkmafiarunning
  if (%MafiaVote1 != %MafiaVote2 != %MafiaVote2) { set %PlayerToKill $null | return }
  if (%MafiaVote1 != %MafiaVote2) {
    if (%MafiaVote1 == %MafiaVote3) { set %PlayerToKill %MafiaVote1 | return }
    if (%MafiaVote2 == %MafiaVote3) { set %PlayerToKill %MafiaVote2 | return }
  }
  elseif (%MafiaVote1 == %MafiaVote2) { set %PlayerToKill %MafiaVote1 | return }
}

;Run through our mafia votes if we have 2 active mafia members.
alias twoMafia {
  checkmafiarunning
  if ( %MafiaVote1 == %MafiaVote2 ) { set %PlayerToKill %MafiaVote2 | return }
  if ( %MafiaVote2 == %MafiaVote3 ) { set %PlayerToKill %MafiaVote2 | return }
  if ( %MafiaVote3 == %MafiaVote1 ) { set %PlayerToKill %MafiaVote3 | return }
  else {
    if ( %MafiaVote1 != PlaceHolder1 ) {
      if (%MafiaVote2 == PlaceHolder2) {
        if (%MafiaVote3 == PlaceHolder3) { set %PlayerToKill %MafiaVote1 | Return }
      }
      if ( %MafiaVote2 != PlaceHolder2 ) {
        var %rand $rand(1,2)
        if (%rand == 1) { set %PlayerToKill %MafiaVote1 | return }
        else { set %PlayerToKill %MafiaVote2 | return }
      }
      else {
        if (%MafiaVote3 != PlaceHolder3) {
          var %rand $rand(1,2)
          if (%rand == 1) { set %PlayerToKill %MafiaVote1 | return }
          else { set %PlayerToKill %MafiaVote3 | return }
        }
      }
    }
    if ( %MafiaVote2 != PlaceHolder2 ) {
      if (%MafiaVote3 != Placeholder3) {
        var %rand $rand(1,2)
        if (%rand == 1) { set %PlayerToKill %MafiaVote2 | return }
        else {
          if (%MafiaVote2 != PlaceHolder2) { set %PlayerToKill %MafiaVote3 | return }
        }
      }
    }
    if (%MafiaVote1 == Placeholder1) {
      if (%MafiaVote2 == PlaceHolder2) {
        if (%MafiaVote3 != PlaceHolder3) { set %PlayerToKill %MafiaVote3 | return }
        else { set %PlayerToKill $null | return }
      }
      if (%MafiaVote2 != PlaceHolder2) { set %PlayerToKill %MafiaVote2 | return }
    }
    if (%MafiaVote2 == PlaceHolder2) {
      if (%MafiaVote3 != PlaceHolder3) { set %PlayerToKill %MafiaVote3 | return }
    }
  }
}

;run through our police votes if we have two active officers
alias twoPolice {
  checkmafiarunning
  if (%PoliceVote1 != PlaceHolder1) {
    if (%PoliceVote2 != PlaceHolder2) {
      if (%PoliceVote1 != %PoliceVote2) {
        var %rand $rand(1,2)
        if (%rand == 1) { set %PlayerToArrest %PoliceVote1 | return }
        else { set %PlayerToArrest %PoliceVote2 | return }
      }
      else { set %PlayerToArrest %PoliceVote1 | return }
    }
    else { set %PlayerToArrest %PoliceVote1 | return }
  }
  if (%PoliceVote2 != PlaceHolder2) {
    if (%PoliceVote1 == PlaceHolder1) { set %PlayerToArrest %PoliceVote2 | return }
  }
  if (%PoliceVote1 == PlaceHolder1) {
    if (%PoliceVote2 == PlaceHolder2) { set %PlayerToArrest $null | return }
  }
}

;Voice all players in the channel !!CURRENTLY UNUSED!!
alias voiceall {
  checkmafiarunning
  var %i = 1
  while (%i <= $numtok(%ActivePlayers,44)) {
    mode #raoagameroom +v $gettok(%ActivePlayers,%i,44)
    inc %i
  }
}

;TODO
;Play test hanging bit
;add nick check, kick players from mafia and police channels at game end

Comments

Sign in to comment.
dma   -  Aug 29, 2015

really where are the instuctios

 Respond  
cptpan   -  May 22, 2015

How about some fuc king instructions?

swaffel  -  Aug 27, 2015

indeed how to play? where is the help???

Sign in to comment

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.