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.

Help with one of my script..

Help for those learning Tcl or writing their own scripts.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That looks alot better :)

Personally, I'd find an equation such as win/(win+loss) more intuitive, but since ultralord requested win/loss, your approach to avoid division by zero is reasonable. Could probably skip setting win to 1, as win is the nominator, not the denominator. Though in either case, the end result would be the same.

One final advice though, once you've read the files, do take the time to close them in order to save system resources, and avoid locking the files for future score-updates.
NML_375
g
game_over
Voice
Posts: 29
Joined: Thu Apr 26, 2007 7:22 am

Post by game_over »

nml375 wrote:That looks alot better :)

Personally, I'd find an equation such as win/(win+loss) more intuitive, but since ultralord requested win/loss, your approach to avoid division by zero is reasonable. Could probably skip setting win to 1, as win is the nominator, not the denominator. Though in either case, the end result would be the same.

One final advice though, once you've read the files, do take the time to close them in order to save system resources, and avoid locking the files for future score-updates.
for me only when open .... "w" (write) is necessity to close files. When you use open whit "r" (read only) a think command open file read content and close file immediately. For test if we use file with read $file w and don't close and flush it we never open the file whit new stuff if we use open r we don't have to :). On my bot read is in one proc and others call him :).
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Nope, the file handle is still left open. Some systems do allow the same file to be opened by multiple handles given certain conditions. Tcl, however, will not reuse the same file handle, but instead horde system resources... In the long run, you'll use up your process' quota of file handlers, and your eggdrop will be completely unable to open any further files...

read will read all the data from the current filepointer up until the end, assuming the file has been accessed in a blocking mode and no numChars argument has been supplied. In other cases, the amount of data read may vary depending on current conditions. However, in none of those cases will read try to close the file descriptor.

In the end, Always close your file handles when you've stopped using them.
NML_375
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

many many thanks for that!!!!!! but when i run it.. i goes to test it.. i make /hop and i saw tcl error on dcc chat

[14:42:43] <Botnick> [13:43] Tcl error [maching]: couldn't open "uL uL uL Ultralord Ultralord uL uL Ultralord Ultralord uL vlakas eleos mp00 mosxasisisi uL vlakas eleos mp00 mosxasisisi.txt": no such file or directory


the txt's file is on directory

/home/ultralord/www/dota/g_winstats.txt
/home/ultralord/www/dota/g_losestats.txt
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Replace the $g_winstats and $g_losestats with the actual path and filenames of the stats-files, and you should be able to open the files properly.
NML_375
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

i try like.. :

Code: Select all

set way1 "/home/ultralord/www/dota/g_winstats.txt"
set way2 "/home/ultralord/www/dota/g_losestats.txt"

bind join - * maching
proc maching {nick host hand chan} {   
   global g_losestats g_pickupchan g_winstats way1 way2
   if {$g_pickupchan != $chan} {return 0}
   set findwin 0
   set findlose 0
   set searchwin [split [read [open $way1 r]] "\n"]
   foreach newwin [lindex $searchwin 0] {
        if {$newwin == $nick} {incr findwin 1}                   
   }
    set searchlose [split [read [open $way2 r]] "\n"]
    foreach newlose [lindex $searchlose 0] {
        if {$newlose == $nick} {incr findlose 1}                 
    }
    if {$findwin == 0} {
           set findwin 1
         }
    if {$findlose == 0} {
           set findlose 1
         }
      
    if {[expr $findwin / $findlose] >= "5" } {
             putquick "PRIVMSG $g_pickupchan : \002\00304 $nick\003 You have coefficient\00303 [expr $findwin / $findlose] \003 I give you\00304 +"
          putquick "MODE $g_pickupchan +v $nick"
    }
}
but nothing happened no tcl errors but nothing.. like it doesnt work..
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The way this script is written, all string comparisons are case sensitive, including nicknames and channel names. So, should g_pickupchan be set to "#mychan", and you decide to join "#MyChan", this script will not react. Same if you use ultralord as you nick instead of UltraLord.

Of course, I assume you've double checked the actual scores, as this script will not perform any actions unless the win/loose ratio is above 5 (as requested)..
NML_375
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

i edit :

Code: Select all

set channels "#mychannel"

bind join - * maching
proc maching {nick host hand chan} {   
   global g_losestats g_pickupchan g_winstats way1 way2 channels
  if { $channels != $g_pickupchan } {return 0}
   set findwin 0
   set findlose 0
   set searchwin [split [read [open $way1 r]] "\n"]
   foreach newwin [lindex $searchwin 0] {
        if {$newwin == $nick} {incr findwin 1}                   
   }
    set searchlose [split [read [open $way2 r]] "\n"]
    foreach newlose [lindex $searchlose 0] {
        if {$newlose == $nick} {incr findlose 1}                 
    }
    if {$findwin == 0} {
           set findwin 1
         }
    if {$findlose == 0} {
           set findlose 1
         }
      
    if {[expr $findwin / $findlose] >= "5" } {
             putquick "PRIVMSG $g_pickupchan : \002\00304 $nick\003 You have coefficient\00303 [expr $findwin / $findlose] \003 I give you\00304 +"
          putquick "MODE $g_pickupchan +v $nick"
    }
}
but no response my nick is "Ultralord" on irc and on txt files.. :/
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

someone knows why the bot not response to script?? :/
User avatar
Nor7on
Op
Posts: 185
Joined: Sat Mar 03, 2007 8:05 am
Location: Spain - Barcelona
Contact:

Post by Nor7on »

put in partyline.

Code: Select all

.console +o
and look if it show some error message.
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

no errors nothing.. wtf... can someone try it to see if he had that problem?
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

IT WORKS MANY THNX!!!!!!!!!!!!!!!






:o :o :o :o :o :o :o
Post Reply