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.

Need a Pro's view on this

Old posts that have not been replied to for several years.
Locked
D
Darkj
Halfop
Posts: 86
Joined: Sun Jul 06, 2003 9:58 pm

Need a Pro's view on this

Post by Darkj »

Code: Select all

proc list_bots { nick user hand chan arg } {
   global botsbot1 botsbot2 botsbot3 botsbot4 botsbot5 botsbot6 botsbot7 botsbot8 botsbot9 botsbot10 mainchanbots mainchannation
   global nationbot1 nationbot2
   global dbotsbot1 dbotsbot2 dbotsbot3 dbotsbot4 dbotsbot5 dbotsbot6 dbotsbot7 dbotsbot8 dbotsbot9 dbotsbot10
   global dnationbot1 dnationbot2
   if {$chan == $mainchanbots} {
   set fs [open $botsbot1 r]
     gets $fs line
     set locatebot1 [lindex $line 0]
     set locatechar1 [lindex $line 1]
     set location1 [lindex $line 2]
     set action1 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot2 r]
     gets $fs line
     set locatebot2 [lindex $line 0]
     set locatechar2 [lindex $line 1]
     set location2 [lindex $line 2]
     set action2 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot3 r]
     gets $fs line
     set locatebot3 [lindex $line 0]
     set locatechar3 [lindex $line 1]
     set location3 [lindex $line 2]
     set action3 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot4 r]
     gets $fs line
     set locatebot4 [lindex $line 0]
     set locatechar4 [lindex $line 1]
     set location4 [lindex $line 2]
     set action4 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot5 r]
     gets $fs line
     set locatebot5 [lindex $line 0]
     set locatechar5 [lindex $line 1]
     set location5 [lindex $line 2]
     set action5 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot6 r]
     gets $fs line
     set locatebot6 [lindex $line 0]
     set locatechar6 [lindex $line 1]
     set location6 [lindex $line 2]
     set action6 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot7 r]
     gets $fs line
     set locatebot7 [lindex $line 0]
     set locatechar7 [lindex $line 1] 
     set location7 [lindex $line 2]
     set action7 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot8 r]
     gets $fs line
     set locatebot8 [lindex $line 0]
     set locatechar8 [lindex $line 1] 
     set location8 [lindex $line 2]
     set action8 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot9 r]
     gets $fs line
     set locatebot9 [lindex $line 0]
     set locatechar9 [lindex $line 1] 
     set location9 [lindex $line 2]
     set action9 [lrange $line 3 end]
   close $fs
   set fs [open $botsbot10 r]
     gets $fs line
     set locatebot10 [lindex $line 0]
     set locatechar10 [lindex $line 1] 
     set location10 [lindex $line 2]
     set action10 [lrange $line 3 end]
   close $fs
   putquick "PRIVMSG $chan :\002Format\:\002 \(\0032CharName\003\) \0034Location\003 \(\0036Action of the bot\003\)"
   putquick "PRIVMSG $chan :\002$dbotsbot1\:\002 \(\0032$locatechar1\003\) \0034$location1\003 \(\0036$action1\003\)  \002$dbotsbot2\:\002 \(\0032$locatechar2\003\) \0034$location2\003 \(\0036$action2\003\)"
   putquick "PRIVMSG $chan :\002$dbotsbot3\:\002 \(\0032$locatechar3\003\) \0034$location3\003 \(\0036$action3\003\)  \002$dbotsbot4\:\002 \(\0032$locatechar4\003\) \0034$location4\003 \(\0036$action4\003\)"
   putquick "PRIVMSG $chan :\002$dbotsbot5\:\002 \(\0032$locatechar5\003\) \0034$location5\003 \(\0036$action5\003\)  \002$dbotsbot6\:\002 \(\0032$locatechar6\003\) \0034$location6\003 \(\0036$action6\003\)"
   putquick "PRIVMSG $chan :\002$dbotsbot7\:\002 \(\0032$locatechar7\003\) \0034$location7\003 \(\0036$action7\003\)  \002$dbotsbot8\:\002 \(\0032$locatechar8\003\) \0034$location8\003 \(\0036$action8\003\)"
   putquick "PRIVMSG $chan :\002$dbotsbot9\:\002 \(\0032$locatechar9\003\) \0034$location9\003 \(\0036$action9\003\)  \002$dbotsbot10\:\002 \(\0032$locatechar10\003\) \0034$location10\003 \(\0036$action10\003\)"
   return 0
  }
   if {$chan == $mainchannation} {
   set fs [open $nationbot1 r]
     gets $fs line
     set locatebot1 [lindex $line 0]
     set locatechar1 [lindex $line 1]
     set location1 [lindex $line 2]
     set action1 [lrange $line 3 end]
   close $fs
   set fs [open $nationbot2 r]
     gets $fs line
     set locatebot2 [lindex $line 0]
     set locatechar2 [lindex $line 1]
     set location2 [lindex $line 2]
     set action2 [lrange $line 3 end]
   close $fs
   putquick "PRIVMSG $chan :\002Format\:\002 \(\0032CharName\003\) \0034Location\003 \(\0036Action of the bot\003\)"
   putquick "PRIVMSG $chan :\002$dnationbot1\:\002 \(\0032$locatechar1\003\) \0034$location1\003 \(\0036$action1\003\)  \002$dnationbot2\:\002 \(\0032$locatechar2\003\) \0034$location2\003 \(\0036$action2\003\)"
   return 0
  }
  return 0
}
Ok, basically, I know there is a way to clean this up. for example, when the bot files are opened, I want it to read it to a list, then on this part:

Code: Select all

   putquick "PRIVMSG $chan :\002Format\:\002 \(\0032CharName\003\) \0034Location\003 \(\0036Action of the bot\003\)"
   putquick "PRIVMSG $chan :\002$dnationbot1\:\002 \(\0032$locatechar1\003\) \0034$location1\003 \(\0036$action1\003\)  \002$dnationbot2\:\002 \(\0032$locatechar2\003\) \0034$location2\003 \(\0036$action2\003\)"
I want to output the data from the list with a color scheme, if anyone can help me out or gets what I am asking, I could use the help, thanks. This code allows for two channels.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Do you need the data to be stored in different files? If so: use an array to store the names and a foreach loop to read them. If not: store everything (for one channel) in one file and just read / output the lines. This way you'll only have one instance of code doing this work. (and only one place to alter if you screw up/decide to change something :))
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

omg....just one little question..


why don't you code DYNAMICLY ?

search userfile for each user with b flag, then check the bots name and use it as new var...would be less work and easyer to extend
D
Darkj
Halfop
Posts: 86
Joined: Sun Jul 06, 2003 9:58 pm

Post by Darkj »

Thats why I'm looking here for help, I'm not exactly sure how the dynamic code would work, I haven't worked much with arrays and lists.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Ok to start off with, why don't you make it all use 1 file. That will simplify it a lot and naturally lead into using a nicer loop. It looks like each file you have only has 1 line in it. So, just get rid of the open/close stuff and read multiple lines instead of 1.

Code: Select all

set fp [open botdata r]
gets $fp line
set locatebot1 blah blah
...
gets $fp line
set locatebot2 blah blah
...
gets $fp line
set locatebot3 ...
...
close $fp
Get the idea?

Now once you do that, you will only have 1 file you have to read from and things will already be simpler. The next step would be to use a loop to read the files, but that will come later.
Locked