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.
Old posts that have not been replied to for several years.
J
Johnny_was
Post
by Johnny_was » Tue Feb 12, 2002 9:31 am
Add extra words where "slaps" is to make it act on more than just the word "slaps"?
Here's the script:
set aslapr {
"who the f*ck are you slapping?!"
"you slap me, I kick you!"
"Rule #1. Don't slap the bots!"
"you cheeky sod!"
"How dare you?!"
}
proc pub_antislap { nick uhost hand dest keyword text } {
global botnick
global aslapr
if {[string index $dest 0] != "#"} { return 0 }
if {[lindex $text 0] == "slaps"} {
if {[lindex $text 1] == $botnick} {
putserv "kick $dest $nick :[lindex $aslapr [rand [llength $aslapr]]]"
# putchan "#blahblah" "[lindex $ranantislap [rand [llength $ranantislap]]]";
}
}
}
Can I just add another line like:
if {[lindex $text 0] == "punches"}
under the slaps one and form a list with other similar words?
Thanks for any help or advice.
CrazyCat
Revered One
Posts: 1306 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Tue Feb 12, 2002 9:40 am
the simplest way:
set act [lindex $text 0]
if {{$act == "slaps"}||{$act == "slurp}} {
this is ok if you have just 2 or 3 words...
else, you can set an array of words and search for matches:
# word list
set $slap {"slaps" "slurps" "bla" "....}
# procedure
set act [lindex $text 0]
foreach i [string $slap] {
if {[string match *$i* [string $act]]} {
set temp 1
}
}
if {$$temp == 1} {
your proc
}
this method works well when you have a lot of words, but it's slower
<font size=-1>[ This Message was edited by: CrazyCat on 2002-02-12 06:41 ]</font>
Petersen
Owner
Posts: 685 Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK
Post
by Petersen » Tue Feb 12, 2002 11:19 am
not using list functions on strings would be a good idea too
Souperman
Halfop
Posts: 69 Joined: Sat Feb 02, 2002 8:00 pm
Location: Cape Town, South Africa
Contact:
Post
by Souperman » Tue Feb 12, 2002 5:40 pm
On 2002-02-12 08:19, Petersen wrote:
not using list functions on strings would be a good idea too
Explaining what you mean would also not be such a bad idea. Remember what it's like to be a newbie... you were once one, I guarantee it.
Read
http://www.soft.net.uk/staffs/eggdrop/characters.html for some useful tips.
Petersen
Owner
Posts: 685 Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK
Post
by Petersen » Tue Feb 12, 2002 6:35 pm
no, cos i read the manual and learned the difference between a list and a string. first thing you should ever do when learning a new programming language is learn the different data types/structures and how they relate to each other.
J
Johnny_was
Post
by Johnny_was » Wed Feb 13, 2002 9:48 am
it's okay I managed to suss it out.
I did a little light reading and came up with this solution:
if { ([lindex $text 0] == "slaps") | ([lindex $text 0] == "punches") } {
I can now add as many ([lindex $text 0 == "whatevers") as I like and it works perfectly.
Petersen
Owner
Posts: 685 Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK
Post
by Petersen » Wed Feb 13, 2002 10:41 am
you're still using list functions on strings, and | should be ||
if { ([lindex [split $text] 0] == "slaps") || ([lindex [split $text] 0] == "punches") } {
would be technically correct. however, the more that line expands, the more inefficient the multiple lindex and splits become.
a much better way to do it would be
set word [lindex [split $text] 0]
if {($word == "slaps") || ($word == "punches")} {
also, you might want to use a string tolower too to make the match case insensitive.