mIRC Home    About    Download    Register    News    Help

Print Thread
#49581 15/09/03 06:31 AM
Joined: Aug 2003
Posts: 136
M
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 136
I have an on text to read from a file and set a variable, basically so I cant get flooded out, It isnt workin gtho. Help would be appreciated. Also, I saw a script somewhere, where I could add each line read into a variable, and make it so the lines that have been read wouldnt be read again.
Code:
on !*:text:!fact:#usa: {
  if (%fact == 0)  {
    msg #usa $read(C:\mIRC\facts.txt)    
    set %fact 1   
    .timer 1 30 set %fact 0 
  }
}  

#49582 15/09/03 08:09 AM
Joined: Jan 2003
Posts: 149
J
Vogon poet
Offline
Vogon poet
J
Joined: Jan 2003
Posts: 149
so u want smth like this?

quickedit...
Code:
on !*:text:!fact:#usa: {
  if (%fact == 0)  {
    :s
    set %cfact $read(C:\mIRC\facts.txt)
    if (%cfact == %lfact) { goto s }
    set %lfact %cfact
    msg #usa %cfact
    set %fact 1
    .timer 1 30 set %fact 0
  }
}

#49583 15/09/03 09:35 AM
Joined: Mar 2003
Posts: 1,256
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,256
what I would do is

a] load the whole text file into a hashtable or a window
b] when you msg the channel, delete the line in question from table or window
c] if the table/window is empty, reload.

#49584 15/09/03 11:59 PM
Joined: Aug 2003
Posts: 136
M
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 136
Thank you thats what I wanted.
--------
Reply to Locutus:
I never seem to be able to get hash tables to work right so I try to avoid them lol.


Thanks for all the help!

#49585 16/09/03 12:03 AM
Joined: Aug 2003
Posts: 136
M
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 136
I really would like to do the has table way, its just I never can load it up write

#49586 16/09/03 04:13 AM
Joined: Mar 2003
Posts: 1,256
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,256
problem is (far as I know) you can't filter or loadbuf it, so the window-version has my preference. I assume the new /fopen makes it faster than before to dump an entire file into a hashtable one at a time, but honestly, unless you use huge amounts of data (hundreds of lines of text), loading them into the table one at a time won't make a big problem.

#49587 17/09/03 02:13 AM
Joined: Aug 2003
Posts: 136
M
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 136
Well its over 2000 lines, I kinda got it now, I have it add the line if the fact said into the variable Then when it tries a new fact it reads through the variable and see's if that line has been read yet, Im afraid tho once it reads through after a couple hundred times the variabel is gonna get huge and slow.

#49588 20/09/03 07:51 AM
I
Iori
Iori
I
Using a hash table..:)
Code:
on *:text:!fact:#usa:{
  [color:green]; Check if %facts variable exists; return if it does[/color]
  if %fact { return }
  [color:green]; Check if table exists and has data in it[/color]
  [color:green]; If not create/populate the table[/color]
  if !$hget(facts,0).item {
    [color:green]; Filter any possible blank lines out of file[/color]
    [color:green]; (You can remove this if it is unneeded)[/color]
    filter -cff facts.txt facts.txt *?*
    [color:green]; If no facts are available, return[/color]
    [color:blue]; If you remove the "/filter ..." line from above, remove this next one also.[/color]
    if !$filtered { return }
    [color:green]; Make the table if needs be[/color]
    if !$hget(facts) { .hmake facts 50 }
    [color:green]; Load the data into table[/color]
    hload -n facts facts.txt
  }
  [color:green]; grab a fact; msg it to channel[/color]
  var %a = $hfind(facts,*,1,w)
  msg #usa $hget(facts,%a)
  [color:green]; Delete this item from table[/color]
  hdel facts %a
  [color:green]; Create %facts for 30 seconds (flood prevention).[/color]
  inc -u30 %fact
}
"/hload -n" lets you use an ordinary text file, ""You can use -n to load or save files as data only, with no items. When loading with -n each line of data is assigned an N item value, starting at N = 1""

Edited: added the blue line

Last edited by Iori; 20/09/03 08:01 AM.

Link Copied to Clipboard