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 

Writing a manual points tracking script - need some guidance

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
hideflomein
Voice


Joined: 31 Jul 2014
Posts: 2

PostPosted: Thu Jul 31, 2014 9:20 am    Post subject: Writing a manual points tracking script - need some guidance Reply with quote

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:

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


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Thu Jul 31, 2014 10:39 am    Post subject: Reply with quote

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:
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:
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
.
Back to top
View user's profile Send private message Visit poster's website
hideflomein
Voice


Joined: 31 Jul 2014
Posts: 2

PostPosted: Thu Jul 31, 2014 10:46 am    Post subject: Reply with quote

Awesome! Thanks - I've never used Tcl before, so a lot of the syntax is very new to me.
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Thu Jul 31, 2014 5:24 pm    Post subject: Reply with quote

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

Code:

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
.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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