mIRC Home    About    Download    Register    News    Help

Print Thread
#171619 26/02/07 06:56 PM
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
Could someone make this snippet? If user types !locate de_cpl_mill the bot will show Download de_cpl_mill : http://link

And it can search for more than 1 matches if there is a map de_cpl_mill_wow it will show 2 matches like this -

Download de_cpl_mill : http://link
Download de_cpl_mill : http://link

Would be great if you can make that you dont have to type full name just a part.. so if the map name is cs_imabatman you can type just !locate batman and it will show Download cs_imabatman : http://link - if there is more maps with batman like cs_batmaniam it will show that map too. The map names and map links will be in a .txt

Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
If either your list of maps is quite long, or it is accessed frequently, you *really* need to go with a hash table.
Even if neither is true, it wouldn't be a bad idea, as your list will likely grow.

I am writing code that would search your text file as you'd like, but it is my first attempt at using goto
and I want to test it.

If you opt for hash table, I will work on that, altho it is likely one of my many betters here will beat me to it. smile



LonDart
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Depending on the specific layout of the text file, spermis may be able to load their text file directly into a hash table, as the general format that a hash table saves in, when using the /hsave command, is standard text (exception being if the -i switch is used, then the format matches that of an ini file)

If the map name is first and none of the map names contain spaces, then the file can be loaded into a hash table directly using the /hload command (after the table is made using /hmake)

Here's my suggestion for a hash table code

Code:
on *:text:!locate*:*:{
  if !$2 { .notice $nick Usage: !locate <map_name> }
  else {
    var %a = 1, %b = $hfind(Maps,$+(*,$2,*),0,w)
    while %a <= %b {
      .msg $iif($chan,$chan,$nick) $hfind(Maps,$+(*,$2,*),%a,w) $hget($v1)
      inc %a
    }
  }
}
on *:start:{
  if !$hget(Maps) { .hmake Maps 100 }
  if $exists(Maps.txt) { .hload Maps Maps.txt }
}
on *:exit:{
  .hsave -o Maps Maps.txt
}
on *:disconnect:{
  .hsave -o Maps Maps.txt
}
on *:text:!addmap*:*:{
  if !$2 || !$3 {    .notice $nick Usage: !addmap <map_name> <map link>  }
  else {    .hadd -m Maps $2 $3-  }
}
on *:text:!delmap*:*:{
  if !$2 {    .notice $nick Usage: !delmap <map_name>  }
  else {    .hdel Maps $2  }
}

The above code presumes that the text file is called Maps.txt, the file is located in the mIRC installation directory, and it matches the format I specified earlier.
If any of those requirements are not met, then I do not guarantee that the code will work.

I also included commands to allow maps to be added or deleted from the hash table, however I didn't restrict access to those commands, so you should be careful when letting people know about them. All commands are coded to work from either a channel or from a pm/query window.


Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
Beautiful, RusselB.

While I was very proud of myself for getting a $read-based code to work, after coding the 3 anti-abuse checks
that immediately came to mind, I thought "This is nuts. Just make a hash table."



LonDart
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
It works.. But i cant add . when i type !addmap de_nuke http://link then close mirc so it saves and go back when i type !locate de_nuke it just shows de_nuke without link

Last edited by spermis; 27/02/07 11:41 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I don't have time to test it right now, but it looks fine to me for the /hadd line.

A couple of points on RusselB's code, tho...

if !$2 || !$3 { }

Because you need $3, you can just do:

if (!$3) { }

[with or without the parentheses]

Also, I would strongly recommend that all scripts that use hash tables /hsave as soon as the table is changed, or on a short timer (1-5 minutes) if it's changed frequently. Doing that instead of on DISCONNECT or on EXIT will prevent lost data in the case of a crash.

And, because hash table commands don't have output (except in the case of errors), there's no need to silence the commands. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
-=18:19:54=- <&...> !addmap viiblin http://link
-=18:20:01=- <&...> !locate viiblin
-=18:20:01=- <K...> viiblin..
so it means it doesnt work..
atleast how to make that only @ can type !addmap and !delmap,

EDIT:
Oh i i got one idea.. I think it will be better if there wont be !addmap or !delmap and txt files but a web page and then when you type !locate de_cpl_mill it will search in a page.. but i need that it searches in this page - http://kz.gamerx.lv/v2/index.php?site=files&cat=1 the maps and says not the link like http://kz.gamerx.lv/v2/download.php?fileID=44 but http://kz.gamerx.lv/v2/index.php?site=files&file=44 ( The one opens when you click on map name )..

Last edited by spermis; 27/02/07 08:36 PM.
Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
!addmap is an on TEXT event. It won't work if it is typed in the mIRC that has the script loaded.
In that case, the !locate wouldn't work for you either.

If !locate works for you, just change the line Riasmus mentioned

So, making the commands available to ops only, you'd have:
Code:
on *:text:!addmap*:*:{
  if ( $nick isop $chan ) {
    if !$3 { .notice $nick Usage: !addmap <map_name> <map link> }
    else { .hadd -m Maps $2 $3- }
  }
}
on *:text:!delmap*:*:{
  if ( $nick isop $chan ) {
    if !$2 { .notice $nick Usage: !delmap <map_name> }
    else { .hdel Maps $2 }
  }
}

As for your new idea, it is possible, but way beyond me.


LonDart
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Considering the fact that this isn't a request site, if the op (original poster) wants the changes made as mentioned in his last post, he's going to have to do more work himself, starting with learning on how to use sockets.

Joined: Feb 2007
Posts: 91
S
spermis Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2007
Posts: 91
i understand why it dont works.. because when i type !addmap map link it adds in the file with 2 lines.. how to fix that?

Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
If you mean that when you look at Maps.txt in a text viewer, you see the map name on one line and
the link on the next line, that is just how hash tables save as text. It is not a problem.

Granted it's not terribly human-friendly, but the hash table isn't confused by it.
It will get confused/corrupted if you try to 'fix' it and put the links back on the same line as the map name.


LonDart

Link Copied to Clipboard