Page 1 of 1

TCL script help..

PostPosted: June 4th, 2013, 6:05 pm
by Zehir
hello ,

i have a simple game called "timebomb" which allows u to put a timebomb in your friend's pants and asks u to cut correct cable to stop the bomb, if cant it booms and kicks the person :-)

Code: Select all
###############################################################################
#  Name:                                        Timebomb
#  Author:                                      jotham.read@gmail.com
#  Web Site:                                    http://radiosaurus.sporkism.org
#  Eggdrop Version:     1.6.x
#  Description:
#
#  This is a small TCL script for Eggdrop.  Timebomb is a game where one person
#  asks the Eggdrop bot to plant a timebomb in another users pants.  The target
#  user then needs to diffuse the bomb by cutting the correct wire, or be
#  kicked from the channel.
#
#  To start the game a user must type:
#    timebomb <nickname>
#  This will cause the target user to have a timebomb "stuffed in their pants"
#  once this occurs the user will have a number of seconds to diffuse the bomb.
#  Diffusing the bomb is done by typing:
#    cutwire <color>
#  The wire colors you can choose from are displayed when the bomb is planted.
#  This script will not allow bots (Users who are +b), or the bot running the
#  script, to be timebombed.
#
#  I know it sounds very silly but it is a rather fun game.
#
###############################################################################

bind  pub   -   timebomb  doTimebomb
bind  pub   -   cutwire   doCutWire

###############################################################################
# Configuration
#

set gTimebombMinimumDuration 20
set gTimebombMaximumDuration 60
set gWireChoices "Red Orange Yellow Green Blue Indigo Violet Black White Grey Brown Pink Mauve Beige Aquamarine Chartreuse Bisque Crimson Fuchsia Gold Ivory Khaki Lavender Lime Magenta Maroon Navy Olive Plum Silver Tan Teal Turquoise"
set gMaxWireCount 3

###############################################################################
# Internal Globals
#

set gTheScriptVersion "0.4"
set gTimebombActive 0
set gTimerId 0
set gTimebombTarget ""
set gTimebombChannel ""
set gCorrectWire ""
set gNumberNames "zero one two three four five six seven eight nine ten eleven twelve"

###############################################################################

proc note {msg} {
  putlog "% $msg"
}

proc IRCKick {theNick theChannel theReason} {
  note "Kicking $theNick in $theChannel (Reason: $theReason)"
  putserv "KICK $theChannel $theNick :$theReason"
}

proc IRCPrivMSG {theTarget messageString} {
  putserv "PRIVMSG $theTarget :$messageString"
}

proc IRCAction {theTarget messageString} {
  putserv "PRIVMSG $theTarget :\001ACTION $messageString\001"
}

proc MakeEnglishList {theList} {
  set theListLength [llength $theList]
  set returnString [lindex $theList 0]
  for {set x 1} {$x < $theListLength} {incr x} {
    if { $x == [expr $theListLength - 1] } {
      set returnString "$returnString and [lindex $theList $x]"
    } else {
      set returnString "$returnString, [lindex $theList $x]"
    }
  }
  return $returnString
}

proc SelectWires {wireCount} {
  global gWireChoices
  set totalWireCount [llength $gWireChoices]
  set selectedWires ""
  for {set x 0} {$x < $wireCount} {incr x} {
    set currentWire [lindex $gWireChoices [expr int( rand() * $totalWireCount )]]
    if { [lsearch $selectedWires $currentWire] == -1 } {
      lappend selectedWires $currentWire
    } else {
      set x [expr $x - 1]
    }
  }
  return $selectedWires
}

proc DetonateTimebomb {destroyTimer kickMessage} {
  global gTimebombTarget gTimerId gTimebombChannel gTimebombActive
  if { $destroyTimer } {
    killutimer $gTimerId
  }
  set gTimerId 0
  set gTimebombActive 0
  IRCKick $gTimebombTarget $gTimebombChannel $kickMessage
}

proc DiffuseTimebomb {wireCut} {
  global gTimerId gTimebombActive gTimebombTarget gTimebombChannel
  killutimer $gTimerId
  set gTimerId 0
  set gTimebombActive 0
  IRCPrivMSG $gTimebombChannel "$gTimebombTarget cut the $wireCut wire.  This has defused the bomb!"
}

proc StartTimeBomb {theStarter theNick theChannel} {
  global gTimebombActive gTimebombTarget gTimerId gTimebombChannel gNumberNames gCorrectWire
  global gMaxWireCount gTimebombMinimumDuration gTimebombMaximumDuration
  if { $gTimebombActive == 1 } {
    note "Timebomb not started for $theStarter (Reason: timebomb already active)"
    if { $theChannel != $gTimebombChannel } {
      IRCPrivMSG $theChannel "I don't have a single bomb to spare. :-("
    } else {
      IRCAction $theChannel "points at the bulge in the back of $gTimebombTarget's pants."
    }
  } else {
    set timerDuration [expr $gTimebombMinimumDuration + [expr int(rand() * ($gTimebombMaximumDuration - $gTimebombMinimumDuration))]]
    set gTimebombTarget $theNick
    set gTimebombChannel $theChannel
    set numberOfWires [expr 1 + int(rand() * ( $gMaxWireCount - 0 ))]
    set listOfWires [SelectWires $numberOfWires]
    set gCorrectWire [lindex $listOfWires [expr int( rand() * $numberOfWires )]]
    set wireListAsEnglish [MakeEnglishList $listOfWires]
    set wireCountAsEnglish [lindex $gNumberNames $numberOfWires]
    IRCAction $theChannel "stuffs the bomb into $gTimebombTarget's pants.  The display reads \[\002$timerDuration\002\] seconds."
    if { $numberOfWires == 1 } {
      IRCPrivMSG $theChannel "Diffuse the bomb by cutting the correct wire. There is $wireCountAsEnglish wire. It is $wireListAsEnglish."
    } else {
      IRCPrivMSG $theChannel "Diffuse the bomb by cutting the correct wire. There are $wireCountAsEnglish wires. They are $wireListAsEnglish."
    }
    note "Timebomb started by $theStarter (Bomb handed to $theNick it will detonate in $timerDuration seconds)"
    set gTimebombActive 1
    set gTimerId [utimer $timerDuration "DetonateTimebomb 0 {\002*BOOM!*\002}"]
  }
}

###############################################################################
# Eggdrop command binds
#

proc doCutWire {nick uhost hand chan arg} {
  global gTimebombActive gCorrectWire gTimebombTarget
  if { $gTimebombActive == 1 } {
    if { [string tolower $nick] == [string tolower $gTimebombTarget] } {
      if { [llength $arg] == 1 } {
        if { [string tolower $arg] == [string tolower $gCorrectWire] } {
          DiffuseTimebomb $gCorrectWire
        } else {
          DetonateTimebomb 1 "\002snip...*BOOM!*\002"
        }
      }
    }
  }
}

proc doTimebomb {nick uhost hand chan arg} {
  global botnick
  set theNick $nick
  if { [llength $arg] == 1 } {
    set theNick [lindex [split $arg] 0]
  }
  if { [string tolower $theNick] == [string tolower $botnick] } {
    set theNick $nick
    IRCKick $theNick $chan "I will not tollerate this!"
    return
  }
  if { [validuser $theNick] == 1 } {
    if { [matchattr $theNick "+b"] == 1 } {
      set theNick $nick
      IRCKick $theNick $chan "I will not tollerate that!"
      return
    }
  }
  StartTimeBomb $nick $theNick $chan
}

###############################################################################

note "timebomb$gTheScriptVersion: loaded";
note " with $gMaxWireCount wire maximum,"
note " and time range of $gTimebombMinimumDuration to $gTimebombMaximumDuration seconds.";


it is pitty that they didnt put re-join script inside :/ it would be nice to auto-join ppl who kicks by the game.. is it possible to add a code to auto-join after bomb kicks ?

can u help me about it pls ?

Re: TCL script help..

PostPosted: June 4th, 2013, 6:08 pm
by Gaddafi
I think it is possible for bot to auto invite the user who is kicked, but it is not possible to force that user to join back because that's IRC client releated. For some users and their clients, if they get invited, they auto join that channel, for some it is different (disabled).

Re: TCL script help..

PostPosted: June 4th, 2013, 6:19 pm
by Zehir
hmm, so what do u suggest ? my irc server is irc.icq.com ..

Re: TCL script help..

PostPosted: June 4th, 2013, 8:16 pm
by Gaddafi
The only way this could be done is that your bot has Oper status on server and then, you could write a script that bot will force join users back on the channel, there's no other way...

Re: TCL script help..

PostPosted: June 4th, 2013, 9:14 pm
by Zehir
my bot is SOP in channel.. is it possible to integrate inside the time bomb game ? a small code maybe ?

Re: TCL script help..

PostPosted: June 5th, 2013, 7:32 pm
by Gaddafi
SOP is only "valid" on one channel. I am talking about Network Operator (Oper). Told you, not possible...

Re: TCL script help..

PostPosted: June 5th, 2013, 10:09 pm
by Zehir
ok thank u for reply..

Re: TCL script help..

PostPosted: June 7th, 2013, 8:01 pm
by NullByte
Gaddafi is right. No one can force a user to join or rejoin. As Gaddafi said if the user has join-on-invite in his client, maybe the bot can invite the user back and that will make it rejoin, but otherwise it is not possible. To add additional info to Gaddafi's replies - only an IRC Network Administrator can force a user to join a channel and that's not on all ircds (in Fewona's ircd it is not supported, cause we do not like forcing users), but in UnrealIRCD there is /sajoin which forces a user to join, so if the eggdrop is identified as an IRC Network Administrator it can issue a command /sajoin nick #chan put in the script..
So really the best you can do is tell your friends/users to put auto-rejoin-on-kick in their client :)

Re: TCL script help..

PostPosted: July 3rd, 2013, 2:18 am
by uranus
The game timebomb is a rather nasty and dangerous game... since any user can ask the bot to kick other user(s) ;)

Re: TCL script help..

PostPosted: July 5th, 2013, 7:26 am
by Gaddafi
uranus wrote:The game timebomb is a rather nasty and dangerous game... since any user can ask the bot to kick other user(s) ;)

Yes, but if bot doesn't have op or hop status, there is nothing to be afraid of :D

Re: TCL script help..

PostPosted: August 13th, 2013, 4:58 am
by fewing
Really very nice information