| View previous topic :: View next topic |
| Author |
Message |
hideflomein Voice
Joined: 31 Jul 2014 Posts: 2
|
Posted: Thu Jul 31, 2014 9:20 am Post subject: Writing a manual points tracking script - need some guidance |
|
|
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 |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Thu Jul 31, 2014 10:39 am Post subject: |
|
|
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 |
|
 |
hideflomein Voice
Joined: 31 Jul 2014 Posts: 2
|
Posted: Thu Jul 31, 2014 10:46 am Post subject: |
|
|
| Awesome! Thanks - I've never used Tcl before, so a lot of the syntax is very new to me. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Thu Jul 31, 2014 5:24 pm Post subject: |
|
|
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 |
|
 |
|