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 

Problem with textfiles
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun May 07, 2006 7:04 am    Post subject: Reply with quote

Now I have a last question. Is this possible: If someone in the channel writes "!medals" my bot looks for his name in the textfile and says for example:"$nick has 2 MVP Medal(s) and 1 MostKills Medal(s)". If the bot could not find the name in the textfile it should say: "$nick has no medals yet."
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sun May 07, 2006 7:37 am    Post subject: Reply with quote

you can creat a modified copy of the above script. [lindex $line 1] and [lindex $line 2] will contain the counter of the medals and if lsearch returns -1, there is no record of medals of him.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun May 07, 2006 7:55 am    Post subject: Reply with quote

Code:
set medalsfile "scripts/medals.txt"

bind pub - !medals medals:get
proc medals:get {nick uhost hand chan arg} {
  set fd [open $::medalsfile r+]
      while {![eof $fd]} {
         lappend list [gets $fd]
      }
  if {[set le [lsearch -glob $list "$nick *"]] != -1} {
       set line [lindex $list $le]
       set mvp [lindex $line 1]
       set kills [lindex $line 2]
     putquick "PRIVMSG $chan :$nick has $mvp MVP Medal(s) and $kills MostKills Medal(s)."   
  } else {
       putquick "PRIVMSG $chan :$nick has no medals yet."
   }
}

I made that script. It works. I hope its a "proper syntax". Wink
Thanks again for your work De Kus.
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sun May 07, 2006 10:19 am    Post subject: Reply with quote

well, I would have used a 'return 1' at the end, used puthelp instead of putquick and changed the r+ to r, since we nolonger need to open the file in read and write modus Very Happy, but its exactly that what I thought you should make Smile.

only 1 note: you forgot to close the file Smile.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun May 07, 2006 10:56 am    Post subject: Reply with quote

Does it make any difference where I put in the close command? So this should be right?
Code:
set medalsfile "scripts/medals.txt"

bind pub - !medals medals:get
proc medals:get {nick uhost hand chan arg} {
  set fd [open $::medalsfile r+]
      while {![eof $fd]} {
         lappend list [gets $fd]
      }
  if {[set le [lsearch -glob $list "$nick *"]] != -1} {
       set line [lindex $list $le]
       set mvp [lindex $line 1]
       set kills [lindex $line 2]
     putquick "PRIVMSG $chan :$nick has $mvp MVP Medal(s) and $kills MostKills Medal(s)."   
  } else {
       putquick "PRIVMSG $chan :$nick has no medals yet."
   }
   close $fd
}
Back to top
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Tue May 16, 2006 9:37 am    Post subject: Reply with quote

The bot seems to have problems with this nick: {{As}masterblast{GEN}}
It does not make an own line for each time, but it makes a new line everytime for this nick, when it has MVP or MostKills.
Does anyone know why?
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue May 16, 2006 4:25 pm    Post subject: Reply with quote

does the nick stand in the text file exactly like that, or are the {} excaped with \?
Maybe lsearch doenst find it, because of the sublist. You could try to use
Code:
lappend list "$name $mvp $kills"
instead for a pure string.
You must remove escape characters from the current textfile, of course.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Mon May 22, 2006 3:16 pm    Post subject: Reply with quote

Yes in the textfile, there is exactly that nick. When I type "!medals {{As}masterblast{GEN}}" lsearch find this nick. But when I want to store this nick a new line is made everytime. What do you mean with
Code:
lappend list "$name $mvp $kills"
Instead of what do I have to use this?
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue May 23, 2006 4:37 am    Post subject: Reply with quote

Start using your brain man, there is only line that uses similar vars with lappend. But strange that he finds the nick and creates a new entry anyway... thats irrationel Very Happy.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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