Code: Select all
# Commands:
#
# !points
#
# !savepoints
#
# !clearpoints
#
#
# !points : plays the game as described in request
# !savepoints: saves nicks and respective points (use before killing bot)
# !clearpoints: erases points (only for +n users)
#
# If you use .restart to restart the bot, points will be saved.
#
# The range of points awarded is -10 to 10 .
#
#set the path and filename of the file that will hold the nicks and their respective points
set pointsfile "scripts/random_points_game.txt"
bind pub - "!points" randpoints
bind pub - "!savepoints" savepoints
bind pub n "!clearpoints" clearpoints
bind evnt - prerestart writepointsfile
if {[file exists $pointsfile]} {
set fp [open $pointsfile r]
set data [split [read -nonewline $fp] \n]
foreach i $data {
set name [lindex [split $i] 0]
set pointsvalue [lindex [split $i] 1]
set points($name) $pointsvalue
}
close $fp
}
proc randpoints {nick uhost handle chan text} {
global botnick points
set randnum [rand 21]
if {$randnum == 0 } {
if {![info exists points($nick)]} {
set points($nick) 0
}
putserv "privmsg $chan :$botnick gives $randnum points to $nick, you've now $points($nick)."
return
}
if {$randnum < 11 } {
if {[info exists points($nick)]} {
set points($nick) [expr $points($nick) + $randnum ]
} else {
set points($nick) $randnum
}
putserv "privmsg $chan :$botnick gives $randnum points to $nick, you've now $points($nick)."
return
}
if {$randnum >= 11} {
if {[info exists points($nick)]} {
set points($nick) [expr $points($nick) + $randnum - 21 ]
} else {
set points($nick) [expr $randnum -21 ]
}
putserv "privmsg $chan :$botnick gives [expr $randnum - 21 ] points to $nick, you've now $points($nick)."
return
}
}
proc savepoints {nick uhost handle chan text} {
global points pointsfile
set fp [open $pointsfile w]
foreach {name pointsvalue} [array get points] {
puts $fp "$name $pointsvalue"
}
close $fp
return 0
}
proc clearpoints {nick uhost handle chan text} {
global points pointsfile
set fp [open $pointsfile w]
close $fp
unset points
putserv "privmsg $chan :All points cleared"
}
proc writepointsfile {prerestart} {
global points pointsfile
set fp [open $pointsfile w]
foreach {name pointsvalue} [array get points] {
puts $fp "$name $pointsvalue"
}
close $fp
return 0
}
putlog "http://forum.egghelp.org/viewtopic.php?p=95644#95644"
Good to know!Anahel wrote:thanks willyw, it's working great,
I'd have to think about that a while.but is it possible to add timer to script? so you can use trigger only once per day (and if someone use trigger before bot i'll send notice with remaining time).
(I'm doing this off the top of my head, and it is not tested)and how to decrease number of given/taken points (3 will be enough for my channel)
Code: Select all
set randnum [rand 21]
Code: Select all
set randnum [rand 7]
Code: Select all
if {$randnum < 11 } {
Code: Select all
if {$randnum < 4 } {
Code: Select all
if {$randnum >= 11} {
Code: Select all
if {$randnum >= 4} {
Code: Select all
$randnum - 21
Code: Select all
$randnum - 7
Again, I'd have to think about that a while.and last thing, if someone use trigger first time bot will only give points or give nothing, and it'd be great if 0 would be minimum points you have (so there won't be negative points)