Mafia game bot

By thegingon on Jun 28, 2013

This is Beta version of my mafia-bot script. please comment with any bug that you noticed.
If there is problem with on load script please do it Manualy.

Mafia is a game where a small number of players are secretly "Mafia", while the remainder are "Civilians", some of whom may have special abilities. The game has a Narrator (the bot), who runs the game rather than taking part as a player. At the start of the game each player is dealt a message that gives them their secret role as a player, as follow:

  • 1 or more Gangsters (Mafia)
  • 1 or more Detectives (Police) - a Civilian who can inspect players in the night as to whether or not they are mafia.
  • 1 Doctor - a Civilian who can elect someone to save in the night
  • 1 barmen - a Civilian who can make someone drunk next morning
  • A number of Civilians
    When roles have been assigned, the game proceeds through a series of "Night" and "Day" phases, starting with Night. The game continues until one side triumphs over the other - if all Mafia members are killed, then the Police win the game, but if the Police become outnumbered by the Mafia, then the Mafia win.

Night phase
The bot tells everyone that the night has started. The bot then asks the mafia players to vote for kill 1 player. At the same time the bot ask the police players to vote for follow 1 player. Also at the same time he asks the doctor to vote for save 1 player and asks the barman to vote for make 1 player drunk.

Day phase
The bot tells everyone that the mafia voted for kill . But also he tells about the Police, Doctor and barman results and what emerges from this...
During the daytime phase, the players deliberate over which suspected Mafia member they wish to nominate for lynching. Once nominations are made, the bot administers an election between the nominees, in which all players vote – whoever receives the most votes is lynched; they are dead, and may no longer participate in the game in any way. The role of the lynched player, whether mafia or citizen, is revealed.
Because players have less information and more freedom to deliberate during the day, the day phase tends to be longer than the night phase. The day phase either has a set time limit, 270 seconds.

How to Win
Mafia - All the policemen die
Police - All the gangsters die
Citizens - After all the policemen died, there is vote for the gangster. if you vote for him, they win the game.

basic commands
!start - start the game (Admin only)
!stop - stop the game (Admin only)
!players - show the active players

basic needs

  • mirc open ;)
  • cancel anti-flood system (or enter the bot to white-list)
  • op or more (he use "mode $chan +v $nick")
;§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
;§§               Made by: thegingon
;§§               Title:   Mafia bot       
;§§               Date:          25-06-2013
;§§               Description:  Mirc Mafia Bot
;§§
;§§               DO NOT CHANGE ANYTHING IN THIS FILE
;§§               
;§§               General Info:
;§§ 
;§§               The Mafia-Bot game is for 5-10 players.         
;§§               The basic roles for 5 players are:
;§§               2 Citizens, 1 Policeman, 1 Gangster (mafia) and 1 Doctor.
;§§               6 Players ~ +1 Gangster ; 7 Players ~ +1 Gangster +1 Policemen ; 8 Players ~ +1 Gangster +1 Policemen +1 Citizen ;
;§§               9 Players ~ +1 Gangster +1 Policemen +1 Citizen +1 barman Citizen; 10 Players ~ +1 Gangster +1 Policemen +1 barman Citizen +2 citizen ;
;§§               
;§§               roles Info:
;§§  
;§§               Citizen - Can only participate in the Vote of who to kick, Every day.
;§§               Policeman - Every night the Policeman can choose a player, that if the player kill someone (The mafia can choose to avoid kill), the policeman catch him.
;§§               Police - If there is 2 or more policemen they will vote for the player that they want to spy on him.
;§§               Gangster - Every night the Gangster can kill player.
;§§               mafia - If there is 2 or more Gangsters they will vote for the player that they want to kill.
;§§               Doctor - Every night The doctor can protect one player from kill
;§§               barman Citizen - Every night the barman can make 1 player got drunk, so in the day he will not be able to spoke.
;§§
;§§               List of Vars:
;§§ 
;§§               %Mafiachannel - The mafia game channel
;§§               %MafiaAdmin - The mafia game Admin
;§§               %Mafiarunning - var that check if the mafia game is running or not
;§§               %MafiaJoinTime - var that check if it is the time to join the mafia game or not
;§§               %MafiaRegPlayers - which players have joined the mafia game
;§§               %MafiaTimer - check if there is timer to start the game
;§§               %MafiaRoleFor $+ [4|5|6|7|8|9|10] - the number of players in each roles
;§§               %mafia - the players which in mafia
;§§               %police - the players which in police
;§§               %doctor - the player which is the doctor
;§§               %citizens - the players which are citizens
;§§               %barman - the player which is barman
;§§               %pl $+ (player name) - player role
;§§               %MafiaPlayers - the players that still in the game (not killed)
;§§               %ACmafia - the players which in mafia and still in the game
;§§               %ACpolice - the players which in police and still in the game
;§§               %ACdoctor - the player which is the doctor and still in the game
;§§               %ACcitizens - the players which are citizens and still in the game
;§§               %ACbarman - the player which is barman and still in the game
;§§               %MafiaNumNight - the number of the night
;§§               %VoteKillSwitch1 - VoteKill for 1 player/s system on/off
;§§               %VoteKillSwitch2 - VoteKill for 2+ player/s system on/off
;§§               %tokill - who to kill in Votekill for 1 player system
;§§               %WVF_ $+ $nick - the $nick vote for ___ >> mafia
;§§               %VF_ $+ $nick - how many votes for $nick >> mafia
;§§               %followSwitch1 - follow system for 1 player >> police
;§§               %followSwitch2 - follow system for 2+ player >> police
;§§               %tofollow - who to follow in follow system for 1 player              
;§§               %WFF_ $+ $nick - the nick vote for ____ >> police
;§§               %FF_ $+ $nick - how many votes for $nick >> police
;§§               %drunkSwitch - drunk system for 1 player >> barman           
;§§               %todrunk - who to drunk in drunk system for 1 player >> barman
;§§               %doctorSwitch - doctor system for 1 player >> doctor
;§§               %tosave - who to save in doctor system for 1 player >> doctor
;§§               %votekickswitch - vote kick system for channel >> morning
;§§               %WSVF_ $+ $nick - the nick vote for ______ >> morning
;§§               %VSF_ $+ $nick - how many votes for $nick >> morning
;§§               %yesorno - vote yes/no system >> morning
;§§               %WYN_ $+ $nick - the vote yes/no  >> morning
;§§               %YES - how many vote of yes >> morning
;§§               %no - how vote of NO >> morning
;§§               %gvoteswitch - last gangster vote system >> after police
;§§               %GF_ $+ $Nick - how many vote for $nick >> after police
;§§               %WGF_ $+ $nick - the nick vote for ____ >> after police
;§§               %gameover - nice line :)
;§§               
;§§                     
;§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§

;// load of mafia-bot \\
on *:load:{ 
  set %MafiaChannel $?("What is the Mafia Channel?")
  set %MafiaAdmin $?("Who is the Mafia game admin?")
  set %MafiaRunning false
  set %MafiaJoinTime false
  set %MafiaRegPlayers
  set %%MafiaTimer false
  set %MafiaNumNight 0
  set %MafiaRoleFor5 2,1,1,1,0
  set %MafiaRoleFor6 2,2,1,1,0
  set %MafiaRoleFor7 2,2,2,1,0
  set %MafiaRoleFor8 3,2,2,1,0
  set %MafiaRoleFor9 3,2,2,1,1
  set %MafiaRoleFor10 4,2,2,1,1
  set %VoteKillSwitch1 off
  set %VoteKillSwitch2 off
  set %FollowSwitch1 off
  set %FollowSwitch2 off
  set %drunkSwitch off
  set %doctorSwitch off
  set %votekickswitch off
  set %gvoteswitch off
  set %yesorno off
  set %gameover 8,87,8`%8,7%¸7,74,7`%7,4%¸4,45,4`%4,5%¸5,51,5`%5,1% 0,1 Game Over 5,1`%1,5%¸5,54,5`%5,4%¸4,47,4`%4,7%, 8,7`%7,8%, 0`
}
;// start game command \\
on *:TEXT:!start:%MafiaChannel:{
  if ($nick != %mafiaAdmin) { msg %mafiaChannel Sorry $nick [ $+ ] , But you are not my admin. My admin is %mafiaAdmin and he is the only one who able to start the game | return }
  elseif (%MafiaRunning == true) { notice $nick The game is running, please stop him before you start him again | return }
  else { startmafiagame }
}
;// stop game command \\
on *:Text:!stop:%MafiaChannel:{
  if ($nick != %mafiaAdmin) { msg %mafiaChannel Sorry $nick [ $+ ] , But you are not my admin. My admin is %mafiaAdmin and he is the only one who able to stop the game | return }
  elseif (%MafiaRunning == false) { notice $nick The game isn't running, please start him before you stom him again | return }
  else { stopmafiagame }
}

;// join to game \\
on *:text:!join:%mafiachannel:{
  if (%MafiaJoinTime == false) { return }
  else { 
    addplayer $nick
  }
}

;// part from game \\
on *:text:!part:%mafiachannel:{
  if (%MafiaJoinTime == false) { return }
  elseif (!$istok(%MafiaRegPlayers,$nick,44)) { return }
  delplayer $nick
}
;// part from channel >> part from game \\
on *:part:%mafiachannel:{
  if (%MafiaJoinTime == false) { return }
  if (!$istok(%MafiaRegPlayers,$nick,44)) { return }
  delplayer $nick
}

on *:text:!kill *:?:{ votekill1 $nick $2 | votekill2 $nick $2 }
on *:text:!flw *:?:{ follow1 $nick $2 | follow2 $nick $2 }
on *:text:!drk *:?:{ drunk1 $nick $2 }
on *:text:!sve *:?:{ save1 $nick $2 }
on *:text:!vote *:*:{ vote1 $nick $2 }
on *:text:!yes:#:{ ynvote $nick yes }
on *:text:!no:#:{ ynvote $nick no }
on *:text:!gvote *:*:{ gvote $nick $2 }
on *:text:!players:?:{ msg $nick Active players are: %MafiaPlayers }
on *:text:!players:#:{ msgcmaf Active players are: %MafiaPlayers }
;§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
;§§               aliases:
;§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§

;// msg to %MafiaChannel \\
alias msgcmaf {
  ;msg %mafiachannel 8,87,8`%8,7%¸7,74,7`%7,4%¸4,45,4`%4,5%¸5,51,5`%5,1% 0,1 $1- 5,1`%1,5%¸5,54,5`%5,4%¸4,47,4`%4,7%, 8,7`%7,8%, 0`
  msg %mafiachannel  $1-
}

;// alias for start game \\;
alias startmafiagame {
  // dual check to prevent restart game in a middle of a game cuz script error \\
  if (%MafiaRunning == true) { return }
  set %MafiaRunning true
  set %MafiaJoinTime true
  /mode %MafiaChannel +m
  msgcmaf Welcome to my mafia game. I will be your Admin and I'll Control the game. Do not send me messages If it is not required, Because I'm A Bot!
  msgcmaf I've created by Yoav sternberg, which is Thegingon on IRC at "Rizon" server, PM him if you have any question. 
  /timer101 1 3 /msgcmaf In this game your admin will be %mafiaAdmin $+ ,But don't tell him your role in the game.
  /timer102 1 5 /msgcmaf How to join the mafia game? Just write !join in this channel
  /timer111 1 6 /mode %MafiaChannel -m
}
;// alias for join player to the game \\
alias addplayer {
  ;// dual check to prevent add something in a middle of a game cuz script error \\
  if (%MafiaJoinTime == false) { return } 
  elseif ($istok(%MafiaRegPlayers,$1,44)) { notice $1 you have registered before to the game, please wait. | return }
  elseif ($numtok(%MafiaRegPlayers,44) > 10) { startgame | return }
  set %MafiaRegPlayers $addtok(%MafiaRegPlayers,$1,44)
  msgcmaf [ $1 ] has joined the game as player [ $numtok(%MafiaRegPlayers,44) ]
  checktostart
}
;// alias for part player from the game \\
alias delplayer {
  // dual check to prevent add something in a middle of a game cuz script error \\
  if (%MafiaJoinTime == false) { return } 
  set %MafiaRegPlayers $remtok(%MafiaRegPlayers,$1,1,44)
  msgcmaf [ $1 ] has left the game. Now there are [ $numtok(%MafiaRegPlayers,44) ] players.
  checktostart 
}

;// alias for stop game \\;
alias stopmafiagame  {
  ;// dual check to prevent stop game when there is no game cuz script error \\
  if (%MafiaRunning == false) { return }
  set %MafiaRunning false
  set %MafiaJoinTime false
  set %MafiaRegPlayers $null
  set %MafiaPlayers $null
  set %citizens $null
  set %doctor $null
  set %mafia $null
  set %barman $null
  set %police $null
  set %tofollow $null
  set %tokill $null
  set %todrunk $null
  set %tosave $null
  set %MafiaNumNight 0
  unset %pl*
  unset %WVF_*
  unset %VF_*
  unset %WFF_*
  unset %FF_*
  unset %WSVF_*
  unset %VSF_*
  unset %WGF_*
  unset %GF_*
  unset %WYN_*
  unset %yes
  unset %no
  mode %Mafiachannel -m
  set %VoteKillSwitch1 off
  set %VoteKillSwitch2 off
  set %FollowSwitch1 off
  set %FollowSwitch2 off
  set %doctorSwitch off
  set %votekickswitch off
  set %gvoteswitch off
  set %yesorno off
  unset %ACcitizens
  unset %ACdoctor
  unset %ACmafia
  unset %ACbarman
  unset %ACpolice
  set %MafiaTimer false
  set %drunkSwitch off
  timer* off
  msgcmaf This mafia game is Over!
  msgcmaf for restart the game request it from my lovely admin, [ %MafiaAdmin ] $+ .
}

;// alias for check if there is more then 5 players \\
alias checktostart {
  if ($numtok(%MafiaRegPlayers,44) < 5) {
    if (%MafiaTimer == true) {
      timer1 off
      timer2 off
      msgcmaf there are only [ $numtok(%MafiaRegPlayers,44) ] players right now.
      set %MafiaTimer false
    }
    return
  }
  elseif (%MafiaTimer == true) { return }
  else {
    msgcmaf More or exactly 5 players have joined the game. The game will start in 90 seconds...
    set %MafiaTimer true
    /timer1 1 45 /timertostart
  }
}
; // alias for voice group of people \\
alias voicethem {
  var %i = 1 
  while (%i <= $numtok(%MafiaPlayers,44)) {
    mode %mafiachannel +v $gettok(%MafiaPlayers,%i,44)
    inc %i     
  }
}
; // alias for devoice group of people \\
alias devoicethem {
  var %i = 1 
  while (%i <= $numtok(%MafiaRegPlayers,44)) {
    echo it %i
    mode %mafiachannel -v $gettok(%MafiaRegPlayers,%i,44)
    inc %i     
  }
}
;// alias for 45 seconds before the game starts \\
alias timertostart {
  msgcmaf The game will start in 45 seconds, please join if you want to play...
  /timer2 1 45 /startgame
}
;// alias for real start the game \\
alias startgame {
  set %MafiaJoinTime false
  msgcmaf Mafia is a game where a small number of players are secretly "Mafia", while the remainder are "Civilians", some of whom may have special abilities. The game has a Narrator, who runs the game rather than taking part as a player.
  msgcmaf Now I will send PM to each of the players with their roles, please keep your role in secret.
  if ($numtok(%MafiaRegPlayers,44) <= 8) { /timer3 1 3 /msgcmaf In [ $numtok(%MafiaRegPlayers,44) ] players game there are 4 roles - Citizen, Gangster, Doctor and Policemen }
  else { /timer3 1 3 /msgcmaf In [ $numtok(%MafiaRegPlayers,44) ] players game there are 5 roles - Citizen, Gangster, Doctor,Policemen and barman Citizen }
  /timer4 1 4 /role [ $numtok(%MafiaRegPlayers,44) ]
  msgcmaf I finished divide the roles for everyone. Now I'll PM you with your role, It should take up to 30 seconds.
  msgcmaf Please don't tell your role to anyone!
  /timer15 1 10 sendallrole
  set %MafiaPlayers %MafiaRegPlayers
  ;mode %mafiaChannel +m
  /timer5 1 18 /tellabout
  /timer6 1 40 /night
}
; // alias for make roles
alias role {
  var %i = 1
  var %roles = %MafiaRoleFor [ $+ [ $1 ] ]
  var %n = $1
  while (%n >= %i) {
    var %who = $gettok(%MafiaRegPlayers,%i,44)
    :startagain
    var %rand = $rand(1,5)
    if ($gettok(%roles,%rand,44) == 0) { goto startagain }
    goto %rand
    :1
    set %pl $+ %who citizen
    set %citizens $addtok(%citizens,%who,44)
    set %ACcitizens $addtok(%ACcitizens,%who,44)
    var %roles = $puttok(%roles,$calc($gettok(%roles,1,44) -1),1,44) 
    inc %i
    continue 
    :2
    set %pl $+ %who mafia
    set %mafia $addtok(%mafia,%who,44) 
    set %ACmafia $addtok(%ACmafia,%who,44)
    var %roles = $puttok(%roles,$calc($gettok(%roles,2,44) -1),2,44) 
    inc %i
    continue 
    :3
    set %pl $+ %who police
    set %police $addtok(%police,%who,44)
    set %ACpolice $addtok(%ACpolice,%who,44)
    var %roles = $puttok(%roles,$calc($gettok(%roles,3,44) -1),3,44) 
    inc %i
    continue
    :4 
    set %pl $+ %who doctor
    set %doctor $addtok(%doctor,%who,44)
    set %ACdoctor $addtok(%ACdoctor,%who,44)
    var %roles = $puttok(%roles,$calc($gettok(%roles,4,44) -1),4,44) 
    inc %i
    continue
    :5 
    set %pl $+ %who barman 
    set %barman $addtok(%barman,%who,44)
    set %ACbarman $addtok(%ACbarman,%who,44)
    var %roles = $puttok(%roles,$calc($gettok(%roles,5,44) -1),5,44) 
    inc %i
    continue
  }
}

;// alias for send roles to everybody \\
alias sendallrole {
  /timer201 1 2 /msg %citizens Hi! you are Citizen in this mafia game.
  /timer202 1 4 /msg %doctor Hi! you are The Doctor (Doctor Who ;)) in this mafia game.
  /timer203 1 6 /msg %barman Hi! you are barman in this mafia game.
  /timer204 1 8 /msg %police Hi! you are policeman in this mafia game.
  if ($numtok(%police,44) > 1) { /timer206 1 10 /msg %police In this game you won't work alone, Police members are %police }
  /timer205 1 12 /msg %mafia Hi! you are gangster in this mafia game.
  if ($numtok(%mafia,44) > 1) { /timer207 1 14 /msg %mafia In this game you won't work alone, mafia members are %mafia }
}

;// alias for what happend in the night \\
alias night {
  inc %MafiaNumNight
  unset %WVF_*
  unset %VF_*
  unset %WFF_*
  unset %FF_*
  unset %WSVF_*
  unset %VSF_*
  unset %yes
  unset %no
  unset %WYN_*
  unset %tokill
  unset %tosave
  unset %todrunk
  unset %tofollow
  mode %mafiachannel +m
  /devoicethem %mafiaplayers
  msgcmaf welcome to your $ord(%MafiaNumNight) night, Good night. It is now nighttime and everyone in the city is asleep...
  msgcmaf I'll send message to the mafia,the police and if the Doctor alive to him too.
  msgcmaf the length of the night is 60 seconds, please wait.
  /timer500 1 60 /resultofnight
  if ($numtok(%ACmafia,44) < 2) { 
    msg %ACmafia Wake Up! you have to choose who to kill. Syntex: !Kill <user>      Exmple: !kill %ACmafia
    msg %ACmafia Active players are: %mafiaplayers
    msg %ACmafia you have 50 seconds, Hurry up...
    set %VoteKillSwitch1 on
    /timer401 1 50 /set %voteKillSwitch1 off
    /timer405 1 40 /msg %ACmafia 10 Seconds left for the night...
  }
  elseif ($numtok(%ACmafia,44) > 1) { 
    msg %ACmafia Wake Up! you have to vote for choosing who to kill. Syntex: !Kill <user>      Exmple: !kill admin 
    msg %ACmafia Active players are: %mafiaplayers
    msg %acmafia talk with your friends at the mafia, $replace(%ACmafia,$chr(44),$chr(32) $+ and $+ $chr(32)) $+ , to choose. If will be a tie, one of them will randomly be choosen
    set %voteKillSwitch2 on
    /timer402 1 50 /set %voteKillSwitch2 off
    /timer406 1 39 /msg %ACmafia 10 Seconds left for the night...
  }
  if ($numtok(%ACpolice,44) < 2) {
    msg %ACpolice Wake Up! you have to choose who to follow. you can follow the gangster only, not the victim. Syntex: !flw <user>      Exmple: !flw %ACpolice
    msg %ACmafia Active players are: %mafiaplayers
    msg %ACmafia you have 50 seconds, Hurry up...
    set %followSwitch1 on
    /timer403 1 50 /set %followSwitch1 off
    /timer407 1 41 /msg %ACpolice 10 Seconds left for the night...

  }
  elseif ($numtok(%ACpolice,44) > 1) { 
    msg %ACpolice Wake Up! you have to vote for choosing who to follow. Syntex: !flw <user>      Exmple: !flw admin 
    msg %ACpolice Active players are: %mafiaplayers
    msg %ACpolice talk with your friends at the police, $replace(%ACpolice,$chr(44),$chr(32) $+ and $+ $chr(32)) $+ , to choose. If will be a tie, one of them will randomly be choosen
    set %followSwitch2 on
    /timer404 1 50 /set %followSwitch2 off 
    /timer408 1 40 /msg %ACpolice 10 Seconds left for the night...
  }
  if (%ACbarman) {
    msg %ACbarman Wake Up! You have to make something to get drunk. Syntex: !drk <user>      Exmple: !drk %ACbarman
    msg %ACbarmen Active players are: %mafiaplayers
    msg %ACbarman you have 50 seconds, Hurry up... 
    set %drunkSwitch on
    /timer409 1 50 /set %drunkSwitch off
    /timer410 1 41 /msg %ACbarman 10 Seconds left for the night...
  }
  if (%ACdoctor) {
    msg %ACdoctor Wake Up! You have to try save 1 player life. Syntex: !sve <user>      Exmple: !sve %ACdoctor
    msg %ACdoctor Active players are: %mafiaplayers
    msg %ACdoctor you have 50 seconds, Hurry up... 
    set %doctorSwitch on
    /timer411 1 50 /set %doctorSwitch off
    /timer412 1 39 /msg %ACdoctor 10 Seconds left for the night...
  }
}

;// alias to tell what every role can do \\
alias tellabout {
  msgcmaf Now, When everyone know his role, It's the time to explain what every role can do. 
  /timer208 1 2 msgcmaf  Citizen - Can only participate in the Vote of who to kick, Every day.
  /timer209 1 4 msgcmaf Policeman - Every night the Policeman can choose a player, that if the player kill someone, the policeman catch him. if there are 2+ poliemen they'll make a vote for who to watch.
  /timer210 1 6 msgcmaf Gangster - Every night the Gangster can kill player. if there are 2+ Gangsters they'll make a vote for who to Execute.
  /timer211 1 8 msgcmaf Doctor - Every night The doctor can protect one player from kill
  /timer212 1 10 msgcmaf barman Citizen - Every night the barman can make 1 player got drunk, so in the day he will not be able to spoke.
}

;// alias for kill <X> for 1 user at PM \\
alias votekill1 {
  if (%VoteKillSwitch1 == off) { return }
  elseif ($1 !isin %ACmafia) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  set %tokill $2
  msg $1 You'll kill $2 $+ ,  If you want to kill Someone else, write !kill <nick>
  msg $1 Active players are: %mafiaplayers
}

;// alias for kill <X> for 2 users at PM \\
alias votekill2 {
  if (%VoteKillSwitch2 == off) { return }
  elseif ($1 !isin %ACmafia) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  if ($eval($+(%, WVF_, $1), 2) != $null) { 
    var %whvf = $eval($+(%, WVF_, $1), 2)
    set $+(%,VF_,%whvf) $calc($eval($+(%,VF_,%whvf),2) - 1)
  }
  if ($+(%,VF_,$2) == $null) { set $+(%,VF_$2) 0 } 
  set $+(%,WVF_,$1) $2
  inc $+(%,VF_,$2)
  msg $1 You voted for kill $2 $+ , If you want to vote for kill someone else, write !kill <nick>
  msg $1 Active players are: %mafiaplayers
}
; // alias for follow <X> for 1 user at PM \\
alias follow1 {
  if (%FollowSwitch1 == off) { return }
  elseif ($1 !isin %ACpolice) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  set %tofollow $2
  msg $1 You'll follow $2 $+ , If you want to follow Someone else, write !flw <nick>
  msg $1 Active players are: %mafiaplayers

}

;// alias for follow <X> for 2 users at PM \\
alias follow2 {
  if (%FollowSwitch2 == off) { return }
  elseif ($1 !isin %ACpolice) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  if ($eval($+(%, WFF_, $1), 2) != $null) { 
    var %whff = $eval($+(%, WFF_, $1), 2)
    set $+(%,FF_,%whff) $calc($eval($+(%,FF_,%whff),2) - 1) 
  }
  if ($+(%,FF_,$2) == $null) { set $+(%,FF_$2) 0 } 
  set $+(%,WFF_,$1) $2
  inc $+(%,FF_,$2)
  msg $1 You voted for follow $2 $+ , If you want to vote for follow Someone else, write !flw <nick>
  msg $1 Active players are: %mafiaplayers
}

;// alias for make <X> drunk for 1 user at PM \\
alias drunk1 {
  if (%drunkSwitch == off) { return }
  elseif ($1 !isin %ACbarman) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  set %todrunk $2
  msg $1 You'll make $2 got drunk $+ , If you want to make Someone else drunk instead, write !drk <nick>
  msg $1 Active players are: %mafiaplayers

}

;// alias for save <X>for 1 user at PM \\
alias save1 {
  if (%doctorSwitch == off) { return }
  elseif ($1 !isin %ACdoctor) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  elseif ($2 == $1) { msg $1 sorry, but you can't save your own life. active players: %mafiaplayers | return }
  set %tosave $2
  msg $1 You'll save $2 life this round $+ , If you want to save Someone else, write !sve <nick>
  msg $1 Active players are: %mafiaplayers

}

; // aliases for the results of the night \\
alias NRmafia {
  if ($numtok(%ACmafia,44) < 2) {
    if (!%tokill) { return $null }
    return %tokill
  }
  elseif ($numtok(%ACmafia,44) > 1) {
    var %i = 1 
    while ($var(VF_*, %i)) {
      var %listofkill = $addtok(%listofkill,$+($eval($v1,2),$v1),44)
      inc %i 
    }
    var %listofkill = $remove(%listofkill,$chr(37) $+ VF_)
    var %listofkill = $sorttok(%listofkill,44,ar)
    var %regex = $regex($gettok(%listofkill,1,44),/^(\d*)(.+)$/)
    return $regml(2)
  }
}
alias NRpolice {
  if ($numtok(%ACpolice,44) < 2) {
    if (!%tofollow) { return $null }
    return %tofollow
  }
  elseif ($numtok(%ACpolice,44) > 1) {
    var %i = 1 
    while ($var(FF_*, %i)) {
      var %listoffollow = $addtok(%listoffollow,$+($eval($v1,2),$v1),44)
      inc %i 
    }
    var %listoffollow = $remove(%listoffollow,$chr(37) $+ FF_)
    var %listoffollow = $sorttok(%listoffollow,44,ar)
    var %regex = $regex($gettok(%listoffollow,1,44),/^(\d.)(\D+)$/)
    return $regml(2)
  }
}

alias NRdoctor {
  if (!%tosave) { return $null }
  return %tosave
}

alias NRbarman {
  if (!%todrunk) { return $null }
  return %todrunk
}

alias resultofnight {
  ; mafia didn't kill
  if ($nrmafia == $null) { 
    msgcmaf The mafia decided to kill... Nobody!
    if ($NRbarman != $null) {
      BTW $nrbarman was on the bar tonight, So now he drunk and won't be able to speak this morning.
    }
  }

  ; police catch the gangster/s

  elseif ($istok(%acmafia,$nrpolice,44)) { 
    msgcmaf The mafia tried to kill someone in this town, tonight.
    msgcmaf But, The police caught one of the gangsters while he was trying to kill!
    if ($numtok(%acmafia,44) == 1) { msgcmaf $nrpolice is the gangster, which means that police won! | endgame police | return }
    elseif ($numtok(%acmafia,44) > 1) { 
      /timer800 1 3 /msgcmaf $nrpolice didn't work alone, and he kept his right for remain silent. The court ruled his sentence to 30 years in jail.
      set %acmafia $remtok(%acmafia,$nrpolice,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$nrpolice,44)
      /timer801 1 5 /msgcmaf his partner escaped so - Nobody killed tonight. 
    }
  }
  ; doctor save the victim
  elseif ($NRmafia == $NRdoctor) {
    msgcmaf The mafia tried to kill someone in this town, tonight.
    msgcmaf They shot him, but the doctor came fast and saved his life. so - Nobody killed tonight, thanks to the doctor. 
    if ($NRbarman != $null) {
      BTW $nrbarman was on the bar tonight, So now he drunk and won't be able to speak this morning.
    }

  }
  else {
    msgcmaf The mafia tried to kill someone in this town, tonight.
    msgcmaf The police followed the wrong man and The doctor was at Gallifrey. The mafia killed... $nrmafia $+ !
    msgcmaf $nrmafia was $replace($eval($+(%,pl,$nrmafia),2),citizen,an innocent citizen,mafia,gangster,doctor,the 11th doctor,police,a policeman) $+ ! 
    if ($eval($+(%,pl,$nrmafia),2) == mafia) {
      if ($numtok(%acmafia,44) == 1) {
        msgcmaf $nrmafia the gangster killed himself, Which means that police won!
        endgame police
        return
      }
      elseif ($numtok(%acmafia,44) > 1) {
        msgcmaf the mafia killed $nrmafia because the police almost caught him.
        set %acmafia $remtok(%acmafia,$nrmafia,44)
        set %MafiaPlayers $remtok(%MafiaPlayers,$nrmafia,44)

      }
    }
    elseif ($eval($+(%,pl,$nrmafia),2) == police) {
      if ($numtok(%acpolice,44) == 1) { 
        msgcmaf $nrmafia was the only policeman in the town, but he died
        morningoutpolice 
        return
      }
      elseif ($numtok(%acpolice,44) > 1) {
        msgcmaf There are still some Policemen in the town.
        set %acpolice $remtok(%acpolice,$nrmafia,44)
        set %MafiaPlayers $remtok(%MafiaPlayers,$nrmafia,44)

      }
    }
    elseif ($eval($+(%,pl,$nrmafia),2) == citizen) {
      msgcmaf an innocent citizen was murdered, the police was helpless.
      set %accitizens $remtok(%accitizens,$nrmafia,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$nrmafia,44)

    }
    elseif ($eval($+(%,pl,$nrmafia),2) == doctor) {
      msgcmaf The 11th doctor (of the town ,of course) was murdered by a mafia called "Daleks".
      set %acdoctor $remtok(%acdoctor,$nrmafia,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$nrmafia,44)
    }
    elseif ($eval($+(%,pl,$nrmafia),2) == barman) {
      msgcmaf The barman if the town was murdered, what all the citizens will do from now?
      set %acbarman $remtok(%acbarman,$nrmafia,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$nrmafia,44)

    }
  }
  if ($NRbarman != $null) {
    BTW $nrbarman was on the bar tonight, So now he drunk and won't be able to speak this morning.
  }
  timer900 1 8 /morning
}

; // alias for end of game \\
alias endgame {
  devoicethem
  if ($1 == mafia) { 
    devoicethem %MafiaRegPlayers
    msgcmaf Game Over! The mafia team won the game
    timer1000 1 2 /msgcmaf Good work for %mafia $+ !
    timer1001 1 4 /msgcmaf maybe next time, police. the policemen are %police
    timer1002 1 6 /msgcmaf The doctor was %doctor and the citizens was  %citizens $+ .
    timer1003 1 8 /msgcmaf $iif(%barman,also you had a barman $+ $chr(44) which was %barman $+ .,%gameover)
    timer1004 1 10 /stopmafiagame  
  }
  elseif ($1 == police) { 
    msgcmaf Game Over! The police team won the game
    timer1000 1 2 /msgcmaf Good work for %police $+ !
    timer1001 1 4 /msgcmaf maybe next time, mafia. the gangsters are %mafia
    timer1002 1 6 /msgcmaf The doctor was %doctor and the citizens was  %citizens $+ .
    timer1003 1 8 /msgcmaf $iif(%barman,also you had a barman $+ $chr(44) which was %barman $+ .)
    timer1004 1 10 /stopmafiagame  
  }
  elseif ($1 == citizens) {
    msgcmaf Game Over! The citizen caught the Gangster and hang him, So it is their won and not police won!
    timer1000 1 2 /msgcmaf Good work for the citizens - %citizens $+ , for the doctor - %doctor and for the barman - %barman $+ .
    timer1001 1 4 /msgcmaf maybe next time, mafia. the gangsters are %mafia
    timer1002 1 6 /msgcmaf It is not your win police, The police was %police $+ .
    timer1004 1 10 /stopmafiagame  

  }
}

; // alias for morning \\
alias morning {
  msgcmaf Good morning! Welcome to the tenants' meeting of the town.
  msgcmaf As you may know, there are at least 1 gangster at the town.
  msgcmaf Every morning you will be able to vote for kick out on of the citizens in the town.
  /timer901 1 3 /msgcmaf First, we will Discuss about who will stand for vote about kick him from the town.
  /timer902 1 6 /msgcmaf write here, on the channel window, !Vote <nick>  , for exmple if you want to vote to kick admin then you have to write - !vote admin
  /timer903 1 9 /msgcmaf You'll have for this 150 seconds, starting now.
  /timer950 1 10 /msgcmaf Active players are: %mafiaplayers
  /timer904 1 11 /set %votekickswitch on
  /timer905 1 12 /voicethem %mafiaplayers
  /timer906 1 13 /drunkhim
  /timer1100 1 150 /set %votekickswitch off
  /timer1110 1 150 /devoicethem %MafiaPlayers
  /timer1101 1 151 /msgcmaf The vote for who will stand for vote about kick out from the town has done.
  /timer1109 1 154 /saykick
  /timer1102 1 153 /msgcmaf You will vote YES or NOT if to kick out from the town for...
  /timer1103 1 155 /msgcmaf you have 120 seconds for that.
  /timer1104 1 157 /set %yesorno on
  /timer1107 1 158 /msgcmaf write !Yes if you want to kick him out from the town, write !No if you want him to stay at the town
  /timer1111 1 159 /voicethem %MafiaPlayers
  /timer1105 1 277 /set %yesorno off
  /timer1106 1 279 /resultmorning 
}

; // alias for drunk \\
alias drunkhim {
  mode %mafiachannel -v $nrbarman
}
alias saykick {
  /msgcmaf For kick $whotokick
}

; // alias for voting system \\
alias vote1 {
  if (%votekickswitch == off) { return }
  elseif ($1 !isin %MafiaPlayers) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  if ($eval($+(%, WSVF_, $1), 2) != $null) { 
    var %whvf = $eval($+(%, WSVF_, $1), 2)
    set $+(%,VSF_,%whvf) $calc($eval($+(%,VSF_,%whvf),2) - 1)
  }
  if ($+(%,VSF_,$2) == $null) { set $+(%,VSF_$2) 0 } 
  set $+(%,WSVF_,$1) $2
  inc $+(%,VSF_,$2)
  msg $1 You voted for kill $2 $+ , If you want to vote for kill another player, write !vote <nick>
  /msg $1 Active players are: %mafiaplayers
}

; // alias to get info who to kick \\
alias whotokick {
  var %i = 1 
  while ($var(VSF_*, %i)) {
    var %listovote = $addtok(%listovote,$+($eval($v1,2),$v1),44)
    inc %i 
  }
  var %listovote = $remove(%listovote,$chr(37) $+ VSF_)
  var %listovote = $sorttok(%listovote,44,ar)
  var %regex = $regex($gettok(%listovote,1,44),/^(\d*)(.+)$/)
  return $regml(2)
}
; // alias for yes/no system
alias ynvote {
  if (%yesorno == off) { return }
  elseif ($1 !isin %MafiaPlayers) { return }
  if ($eval($+(%, WYN_, $1), 2) != $null) { 
    dec $+(%,$eval($+(%, WYN_, $1), 2))
  }
  inc $+(%,$2)
  set $+(%, WYN_, $1) $2
  notice $1 You voted $2 for kick out $whotokick $+ ! to change your vote just write $iif($2 == yes,!not,!yes)
  msgcmaf It is $iif(%yes,%yes,0) votes for kick $whotokick and $iif(%no,%no,0) votes for don't kick $whotokick $+ .
}

; // alias for results of morning \\
alias resultmorning {
  if (!%yes) { set %yes 0 }
  if (!%no) { set %no 0 }
  if (%no >= %yes) {
    msgcmaf $whotokick will stay in our lovely town! %yes citizens voted for his kick out, And %no citizen voted against it.
    night
  }
  elseif (%yes > %no) {
    msgcmaf $whotokick will kicked out from our lovely town! %yes citizens voted for his kick out, And %no citizen voted against it.
    msgcmaf $whotokick was $replace($eval($+(%,pl,$whotokick),2),citizen,an innocent citizen,mafia,gangster,doctor,the 11th doctor,police,a policeman) $+ ! 
    if ($eval($+(%,pl,$whotokick),2) == mafia) {
      if ($numtok(%acmafia,44) == 1) {
        msgcmaf $whotokick the only gangster in the town left, Which means that police won!
        endgame police
        return
      }
      elseif ($numtok(%acmafia,44) > 1) {
        msgcmaf $whotokick left the town, But there is another gangsters in the town.
        set %acmafia $remtok(%acmafia,$whotokick,44)
        set %MafiaPlayers $remtok(%MafiaPlayers,$whotokick,44)
        night
      }
    }
    elseif ($eval($+(%,pl,$whotokick),2) == police) {
      if ($numtok(%acpolice,44) == 1) { 
        msgcmaf $whotokick was the only policeman in the town, but he left the city.
        morningoutpolice 
      }
      elseif ($numtok(%acpolice,44) > 1) {
        msgcmaf There are still some Policemen in the town.
        set %acpolice $remtok(%acpolice,$whotokick,44)
        set %MafiaPlayers $remtok(%MafiaPlayers,$whotokick,44)
        night
      }
    }
    elseif ($eval($+(%,pl,$whotokick),2) == citizen) {
      msgcmaf an innocent citizen left the town.
      set %accitizens $remtok(%accitizens,$whotokick,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$whotokick,44)
      night
    }
    elseif ($eval($+(%,pl,$whotokick),2) == doctor) {
      msgcmaf The 11th doctor (of the town ,of course) left the town to england, 23rd century...
      set %acdoctor $remtok(%acdoctor,$whotokick,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$whotokick,44)
      night
    }
    elseif ($eval($+(%,pl,$whotokick),2) == barman) {
      msgcmaf The barman left the town, what all the citizens will do from now?
      set %acbarman $remtok(%acbarman,$whotokick,44)
      set %MafiaPlayers $remtok(%MafiaPlayers,$whotokick,44)
      night
    } 
  }
}

;// alias for morning without police \\
alias morningoutpolice {
  devoicethem %mafiaplayers
  msgcmaf As you know, There is no police in the town But $numtok(%acmafia,44) gangsters.
  if ($numtok(%acmafia,44) > 1) { msgcmaf So, the police lost, Mafia won. Gog and Magog in the town. | endgame mafia | return }
  msgcmaf You have one chance to hang him. active players are: %mafiaplayers .
  /timer1500 1 2 /msgcmaf to vote who is the gangster simpely write !gvote <nick>     for exmple: !gvote admin
  /timer1550 1 3 /msgcmaf Active players are: %mafiaplayers
  /timer1501 1 3 /set %gvoteswitch on
  /timer1502 1 4 /msgcmaf You have 120 seconds for that.
  /timer1503 1 5 /voicethem %mafiaplayers
  /timer1504 1 124 /set %gvoteswitch off
  /timer1505 1 125 /resultofafterpolice

}
; // alias for after police vote system \\
alias gvote {
  if (%gvoteswitch == off) { return }
  elseif ($1 !isin %MafiaPlayers) { return }
  elseif ($2 !isin %MafiaPlayers) { msg $1 sorry, but $2 isn't alive/play mafia. active players: %MafiaPlayers | return }
  if ($eval($+(%, WGF_, $1), 2) != $null) { 
    var %whvf = $eval($+(%, WGF_, $1), 2)
    set $+(%,GF_,%whvf) $calc($eval($+(%,GF_,%whvf),2) - 1)
  }
  if ($+(%,GF_,$2) == $null) { set $+(%,GF_$2) 0 } 
  set $+(%,WGF_,$1) $2
  inc $+(%,GF_,$2)
  msg $1 You voted for hang $2 $+ , If you want to vote for hang Someone else, write !Gvote <nick>
}

; // alias for after police vote system, who will hang \\
; // alias to get info who to kick \\
alias whotohang {
  var %i = 1 
  while ($var(GF_*, %i)) {
    var %listovote = $addtok(%listovote,$+($eval($v1,2),$v1),44)
    inc %i 
  }
  var %listovote = $remove(%listovote,$chr(37) $+ GF_)
  var %listovote = $sorttok(%listovote,44,ar)
  var %regex = $regex($gettok(%listovote,1,44),/^(\d*)(.+)$/)
  return $regml(2)
}

; // alias for the results of after police \\
alias resultofafterpolice {
  msgcmaf The vote has done! 
  gvotefor
  if ($whotohang != $gettok(%acpolice,1,44)) && ($+(%pl,$whotohang) != mafia)  {
    /timer2000 1 2 msgcmaf But, $whotohang wasn't from the mafia, $whotohang was $replace($eval($+(%,pl,$whotohang),2),citizen,an innocent citizen,mafia,gangster,doctor,the 11th doctor,police,a policeman) $+ !
    /timer2001 1 3 endgame mafia
    return
  }
  /timer2002 1 2 msgcmaf Well, $whotohand was...................................................................................
  /timer2003 1 5 msgcmaf $whotohand was Gangster
  /timer2004 1 6 endgame citizens
}

alias gvotefor {
  msgcmaf the player with the most votes was... $whotohang $+ !
}

Comments

Sign in to comment.
cptpan   -  Jul 08, 2014

Try this game we've just developed: http://www.textgangsters.com

 Respond  
Blackout10   -  Jun 30, 2014

Great game. While playing i notived one problem but its an easy fix, go to lines 397 and 398. Where it says
msg %ACmafia Active players are: %mafiaplayers
msg %ACmafia you have 50 seconds, Hurry up...
Change both of the %ACmafia to %ACpolice
otherwise the game plays very well

 Respond  
Menteroth   -  Oct 10, 2013

you forgot a ; on line 160

"// dual check to prevent restart game in a middle of a game cuz script error \"

 Respond  
cptpan   -  Sep 24, 2013

I don't even

 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.