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 

game script - gathering points

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


Joined: 03 Jul 2009
Posts: 48
Location: Dom!

PostPosted: Wed Jan 12, 2011 6:20 pm    Post subject: game script - gathering points Reply with quote

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).
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Thu Jan 13, 2011 12:54 am    Post subject: Re: game script - gathering points Reply with quote

Code:

# 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.
Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Jan 13, 2011 2:01 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Anahel
Halfop


Joined: 03 Jul 2009
Posts: 48
Location: Dom!

PostPosted: Thu Jan 13, 2011 10:56 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Thu Jan 13, 2011 11:11 am    Post subject: Reply with quote

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.

Quote:

and prerestart to save that list.


?
Perhaps you overlooked it? ... or I'm not understanding you?
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Thu Jan 13, 2011 11:24 am    Post subject: Reply with quote

Anahel wrote:
thanks willyw, it's working great,


Good to know!
Smile

Quote:

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.

Quote:

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:

set randnum [rand 21]

and change to:
Code:

set randnum [rand 7]


Find:
Code:

if {$randnum < 11 } {

and change to:
Code:

if {$randnum < 4 } {


Find:
Code:

if {$randnum >= 11} {

and change to:
Code:

if {$randnum >= 4} {


Find:
Code:

$randnum - 21

in three places, and change to:
Code:

$randnum - 7



Quote:

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.
Back to top
View user's profile Send private message
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