egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lottery

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
garfwen
Halfop


Joined: 12 Mar 2008
Posts: 61

PostPosted: Mon Dec 01, 2008 12:54 pm    Post subject: Lottery Reply with quote

Hello


Im looking for a simple script like:

Pvt eggdrop:
<GaRfWeN>!start 4
(4 is the number of max users)
<GaRfWeN>!prize CSS-Acount

Channel:
<Eggdrop>Lottery starting! Max users 4
<nick1>!reg
<nick2>!reg
<nick1>!regs
<Eggdrop>Regs atm 2/4: nick1 , nick2
<nick3>!reg
<nick4>!reg
<Eggdrop> Ok we have a winner ! $WinnerNick

The winner should be sorted

Can you do something like that ? Razz

Ty.
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 254
Location: Oswiecim / Poland

PostPosted: Mon Dec 01, 2008 4:07 pm    Post subject: Reply with quote

Code:
# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

bind pub - !start start_proc
bind pub - !prize prize_proc
bind pub - !reg reg_proc
bind pub - !regs regs_proc

set game_status 0
set game_prize ""
set reg_status 0
set max_players 0
set player_list [list]

proc start_proc { nick uhost hand chan arg } {
   global max_players game_status

   if {$game_status == 0} {
      set players_num [lindex [split $arg] 0]

      if {[regexp {^([0-9]+)$} $players_num]} {
         set max_players $players_num
         set game_status 1
      }
   }
}

proc prize_proc { nick uhost hand chan arg } {
   global game_status reg_status max_players game_prize

   if {$game_prize == ""} {
      if {$game_status == 1} {
         if {$arg != ""} {
            set game_prize $arg
            set reg_status 1

            putquick "PRIVMSG $chan :Lottery starting! Max users: $max_players (prize: $game_prize)"
         }
      }
   }
}

proc reg_proc { nick uhost hand chan arg } {
   global reg_status player_list max_players game_status game_prize

   if {$reg_status == 1} {
      set player_exists 0

      foreach new_player $player_list {
         set gimme_host [lindex [split $new_player ";"] 1]
         if {$gimme_host == $uhost} {
            set player_exists 1
            break
         }
      }

      if {$player_exists == 0} {
         lappend player_list "$nick;$uhost"

         if {[llength $player_list] == $max_players} {
            set lottery_winner [expr {int(rand() * $max_players)}]

            set the_winner_is [lindex [split [lindex $player_list $lottery_winner] ";"] 0]

            putquick "PRIVMSG $chan :Ok we have a winner ! $the_winner_is"

            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
         }
      }
   }
}

proc regs_proc { nick uhost hand chan arg } {
   global reg_status max_players game_prize player_list

   set current_in [llength $player_list]

   set rdy_player_list [list]

   foreach lt_player $player_list {
      if {$lt_player != ""} {
         set need_only_nick [lindex [split $lt_player ";"] 0]
         lappend rdy_player_list $need_only_nick
      }
   }

   if {$rdy_player_list == ""} {
      set rdy_player_list "-"
   } {
      set rdy_player_list [join $rdy_player_list ", "]
   }

   if {$reg_status == 1} {
      putquick "PRIVMSG $chan :Regs atm $current_in/$max_players: $rdy_player_list (prize: $game_prize)"
   }
}

putlog "lottery.tcl ver 0.1 by tomekk loaded"


try it Wink

there can't be two nicks with the same name in da lottery Smile (based on user host)

script is working in "memory", after restart u need to start lottery again etc.. Smile
_________________
feel free to correct my english Smile
Back to top
View user's profile Send private message Visit poster's website
garfwen
Halfop


Joined: 12 Mar 2008
Posts: 61

PostPosted: Fri Dec 05, 2008 4:36 pm    Post subject: Reply with quote

its working Razz

thanks !!! Very Happy
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 254
Location: Oswiecim / Poland

PostPosted: Sun Dec 27, 2015 1:44 pm    Post subject: Reply with quote

added: !stop, !lottery commands, setup commands for ops or everyone (configured in script)
fixed: some logic in the script

Update on request.

Code:
# Author: tomekk
# e-mail:  tomekk/@/tomekk/./org
# home page: http://tomekk.org/
#
# Version 0.2
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

# lottery setup (stop/start/prize) only for channel ops?
# 1 - only ops
# 0 - everyone
set lottery_setup_for_ops 1

bind pub - !start start_proc
bind pub - !stop stop_proc
bind pub - !prize prize_proc
bind pub - !lottery lottery_proc
bind pub - !reg reg_proc
bind pub - !regs regs_proc

proc set_defaults {} {
   global game_status game_prize reg_status max_players player_list started_by

   set game_status 0
   set game_prize ""
   set reg_status 0
   set max_players 0
   set player_list [list]
   set started_by ""
}

set_defaults

proc start_proc { nick uhost hand chan arg } {
   global max_players game_status started_by lottery_setup_for_ops

   if {$lottery_setup_for_ops == 1} {
      if {[isop $nick $chan] == 0} {
         putquick "PRIVMSG $chan :Sorry, @ needed."
         return
      }
   }

   if {$game_status == 0} {
      set players_num [lindex [split $arg] 0]

      if {[regexp {^([0-9]+)$} $players_num]} {
         set max_players $players_num
         set game_status 1
         set started_by "$nick <$uhost>"
      }
   } else {
      putquick "PRIVMSG $chan :Lottery already started by: $started_by"
   }
}

proc stop_proc { nick uhost hand chan arg } {
   global game_status lottery_setup_for_ops

   if {$lottery_setup_for_ops == 1} {
      if {[isop $nick $chan] == 0} {
         putquick "PRIVMSG $chan :Sorry, @ needed."
         return
      }
   }

   if {$game_status == 1} {
      putquick "PRIVMSG $chan :Lottery wiped."

      set_defaults
   } else {
      putquick "PRIVMSG $chan :Lottery not started."
   }
}

proc prize_proc { nick uhost hand chan arg } {
   global game_status reg_status max_players game_prize lottery_setup_for_ops

   if {$lottery_setup_for_ops == 1} {
      if {[isop $nick $chan] == 0} {
         putquick "PRIVMSG $chan :Sorry, @ needed."
         return
      }
   }

   if {$game_prize == ""} {
      if {$game_status == 1} {
         if {$arg != ""} {
            set game_prize $arg
            set reg_status 1

            putquick "PRIVMSG $chan :Lottery starting! Max users: $max_players (prize: $game_prize)"
         }
      } else {
         putquick "PRIVMSG $chan :Lottery not started."
      }
   } else {
      putquick "PRIVMSG $chan :Prize already set: $game_prize"
   }
}

proc lottery_proc { nick uhost hand chan arg } {
   global game_status game_prize max_players started_by

   if {$game_status == 1} {
      if {$game_prize != ""} {
         putquick "PRIVMSG $chan :Lottery started by: $started_by, max players: $max_players, prize: $game_prize"
      } else {
         putquick "PRIVMSG $chan :Lottery started by: $started_by, max players: $max_players, prize: *not set*"
      }
   } else {
      putquick "PRIVMSG $chan :Lottery not started."
   }
}

proc reg_proc { nick uhost hand chan arg } {
   global reg_status player_list max_players game_status game_prize

   if {$reg_status == 1} {
      set player_exists 0

      foreach new_player $player_list {
         set gimme_host [lindex [split $new_player ";"] 1]
         if {$gimme_host == $uhost} {
            set player_exists 1
            break
         }
      }

      if {$player_exists == 0} {
         lappend player_list "$nick;$uhost"

         if {[llength $player_list] == $max_players} {
            set lottery_winner [expr {int(rand() * $max_players)}]

            set the_winner_is [lindex [split [lindex $player_list $lottery_winner] ";"] 0]

            putquick "PRIVMSG $chan :Ok we have a winner ! $the_winner_is"

            set_defaults   
         }
      }
   } else {
      putquick "PRIVMSG $chan :Prize not set, can't register - sorry."
   }
}

proc regs_proc { nick uhost hand chan arg } {
   global reg_status max_players game_prize player_list

   if {$reg_status == 1} {
      set current_in [llength $player_list]

      set rdy_player_list [list]

      foreach lt_player $player_list {
         if {$lt_player != ""} {
            set need_only_nick [lindex [split $lt_player ";"] 0]
            lappend rdy_player_list $need_only_nick
         }
      }

      if {$rdy_player_list == ""} {
         set rdy_player_list "-"
      } {
         set rdy_player_list [join $rdy_player_list ", "]
      }

      if {$current_in > 0} {
         putquick "PRIVMSG $chan :Regs atm $current_in/$max_players: $rdy_player_list (prize: $game_prize)"
      } else {
         putquick "PRIVMSG $chan :No regs atm."
      }
   } else {
      putquick "PRIVMSG $chan :Prize not set, so no regs stats."
   }
}

putlog "lottery.tcl ver 0.2 by tomekk loaded"

_________________
feel free to correct my english Smile
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber