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.

game script - gathering points

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
Anahel
Halfop
Posts: 48
Joined: Fri Jul 03, 2009 6:18 pm
Location: Dom!

game script - gathering points

Post by Anahel »

I'm looking for a game script which would give users points (or something like that) on command, like:

me: !points
bot gives 2 points to <me>, you've now 2 points.

or radomly take away them, or give nothing.

i searched both forums and tcl archive and couldn't find something like that, maybe someone have similar script, or know how to do it without much effort (i've [censored] tcl skills and have no idea how to do script such as this one).
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Re: game script - gathering points

Post by willyw »

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"
With a couple brief tests, it worked for me.

Hopefully others will comment, or post other methods. I'm curious to learn if my way of doing it is ok.

Good luck with it.
:)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You should add at least a 'bind evnt' for prerehash and prerestart to save that list.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Anahel
Halfop
Posts: 48
Joined: Fri Jul 03, 2009 6:18 pm
Location: Dom!

Post by Anahel »

thanks willyw, it's working great, 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). and how to decrease number of given/taken points (3 will be enough for my channel)

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)
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote:You should add at least a 'bind evnt' for prerehash
I thought about it, but since values are not lost with a rehash, I didn't.
and prerestart to save that list.
?
Perhaps you overlooked it? ... or I'm not understanding you?
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Anahel wrote:thanks willyw, it's working great,
Good to know!
:)
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'd have to think about that a while.
Maybe somebody else here would like to modify it.... or, feel free to modify it yourself. If you make a try at it, usually somebody around here can advise you on it.
and how to decrease number of given/taken points (3 will be enough for my channel)
(I'm doing this off the top of my head, and it is not tested)
Find:

Code: Select all

set randnum [rand 21] 
and change to:

Code: Select all

set randnum [rand 7] 
Find:

Code: Select all

if {$randnum < 11 } { 
and change to:

Code: Select all

if {$randnum < 4 } { 
Find:

Code: Select all

if {$randnum >= 11} { 
and change to:

Code: Select all

if {$randnum >= 4} { 
Find:

Code: Select all

$randnum - 21
in three places, and change to:

Code: Select all

$randnum - 7
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)
Again, I'd have to think about that a while.
Post Reply