This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Lottery

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Lottery

Post by garfwen »

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 ? :P

Ty.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Code: Select all

# 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 ;)

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

script is working in "memory", after restart u need to start lottery again etc.. :)
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

its working :P

thanks !!! :D
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

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

Update on request.

Code: Select all

# 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"
User avatar
aslpls
Halfop
Posts: 47
Joined: Mon May 02, 2016 9:41 am

Post by aslpls »

!start not working .. its not showing in the channel
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Don't double-post, don't do thread-necrophilia
User avatar
aslpls
Halfop
Posts: 47
Joined: Mon May 02, 2016 9:41 am

Post by aslpls »

DasBrain wrote:The documentation for the script is essentially:
#well just read the script, you'll understand :p
sorry my bad..
see here what i mean..

Code: Select all

https://pasteboard.co/JZrJCsh.jpg
already set for everyone..

Code: Select all

https://pasteboard.co/JZrK1ov.jpg
nothing to show in the channel..

one more thing, if the bot join multiple channels.. it will enable the game to all channels.

please help, i don't know how to do scripts, i only test and use it.. im using eggdrop1.6.21

thanks in advance.
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

The script lacks an error message.
The command is !start <nb players>
User avatar
aslpls
Halfop
Posts: 47
Joined: Mon May 02, 2016 9:41 am

Post by aslpls »

i tried that option already.. but still no luck..
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Replace the actual start_proc:

Code: Select all

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"
   }
}
with this one:

Code: Select all

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
      }
   }
   putserv "PRIVMSG $chan :ok, tryin' to start"
   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 {
         putserv "PRIVMSG $chan :Syntax is !start <nb players>"
      }
   } else {
      putquick "PRIVMSG $chan :Lottery already started by: $started_by"
   }
}
User avatar
aslpls
Halfop
Posts: 47
Joined: Mon May 02, 2016 9:41 am

Post by aslpls »

thank you CrazyCat for the reply.. i have added the code as you posted.

see below;

Code: Select all

# 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 0

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 "0"
   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
      }
   }
   putserv "PRIVMSG $chan :ok, tryin' to start"
   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 {
         putserv "PRIVMSG $chan :Syntax is !start <nb players>"
      }
   } 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"

but then, this script need to be modified after all.

Code: Select all

<@JohnDoe> !start
<@Janebot> ok, tryin' to start
<@Janebot> Syntax is !start <nb players>
<@JohnDoe> !start 10
<@Janebot> ok, tryin' to start
<@JohnDoe> !lottery
<@Janebot> Lottery started by: JohnDoe <jd@[censored].happens>, max players: 10, prize: 1000000
Another...

Code: Select all

<@JohnDoe> !start 4
<@Janebot> ok, tryin' to start
<@testers> !prize 1000000000
<@Janebot> Prize already set: 1000000
<@testers> !regs
<@Janebot> Prize not set, so no regs stats.
<@testers> !reg
<@Janebot> Prize not set, so no regs stats.


Thank you for the help CrazyCat..
Post Reply