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.

Writing a manual points tracking script - need some guidance

Help for those learning Tcl or writing their own scripts.
Post Reply
h
hideflomein
Voice
Posts: 2
Joined: Thu Jul 31, 2014 9:12 am

Writing a manual points tracking script - need some guidance

Post by hideflomein »

So I'm writing a script for a points tracking system for my eggdrop. The idea is that an op can /msg the bot with the command "points <user> <value>" where <value> is optional (if left blank, it defaults to 100). The bot then stores the score in the user's whois field under "points".

Code: Select all

set our_chan "<channel>"

bind msg o points addpoints

proc addpoints {nick text} {
	global our_chan

	if {[string tolower $chan] != $our_chan} {
		return 0
	}
	
	set whom [lindex $text 0]
	if {$whom != $nick} {
	
		set inputparse [lrange $text first last]
		if {[inputparse first] == [inputparse last]} {
			set points 100
		} else {
			set points [lindex $text 1]
		}
		
		putserv "PRIVMSG $chan :$nick gives $points to $whom."
	
	} else {
		putserv "PRIVMSG $nick: You can't award yourself points. Don't be a schmuck."
	}
}

	

I think I'm on the right track, but I'm not sure if I have everything I need.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

First off, any proc called by a /msg bind MUST be called with the correct number of arguments...
Eggdrop Documents wrote:bind msg <flags> <command> <proc>
procname <nick> <user@host> <handle> <text>
Your addpoints proc must have exactly 4 arguments like...

Code: Select all

proc addpoints {nick host hand text} {
Notice that a /msg bind doesn't provide a channel to the called proc.
So your very first if statement fails with unknown var $chan...

Code: Select all

if {[string tolower $chan] != $our_chan} {
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
h
hideflomein
Voice
Posts: 2
Joined: Thu Jul 31, 2014 9:12 am

Post by hideflomein »

Awesome! Thanks - I've never used Tcl before, so a lot of the syntax is very new to me.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I might start out that script a little more like this...

Code: Select all

set our_chan "<channel>"  ;## <- MUST set a channel!##

bind msg o points addpoints 

proc addpoints {nick host hand text} {
   global our_chan 

   lassign [split [string trim $text]] whom points

   if {$whom eq ""} {
      puthelp "PRIVMSG $nick :Use: \002/msg $::botnick <handle> \[points\]\002" 
      return 0 
   }

   if {![validuser $whom]} {
      puthelp "PRIVMSG $nick :\002$whom\002 is not a valid handle!" 
      return 0 
   }

   if {[string match -nocase $whom $hand]} {
      puthelp "PRIVMSG $nick :You can't award yourself points. Don't be a schmuck." 
      return 0 
   }

   if {![string is digit -strict $points]} {  set points 100  }
       
   puthelp "PRIVMSG $our_chan :$nick gives $points to $whom." 


   # now you can check if they already have any points
   # and do the math for their new total points
   # and save the new total points to the user file


   return 0
} 

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply