mIRC Home    About    Download    Register    News    Help

Print Thread
#108472 19/01/05 07:57 PM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
im looking to make improvements upon that hash table greet that i had one here in the other post
the main thing that i am looking to do( yes it could use more checks to avoid errors and possibly some echos) is to get it to work by addy rather than nick
Code:
#greet on 
on *:start: { 
if ($exists(greet.hsh)) { 
hmake -s greet 100 
hload -so greet greet.hsh 
} 
else { 
hmake -s greet 100 
hsave -so greet greet.hsh 
} 
} 
on *:exit: { 
hsave -so greet greet.hsh 
hfree -s greet 
} 
on !*:join:#: { 
if ($hfind(greet, $nick)) { 
msg $chan $nick $+ : $hget(greet, $nick) 
} 
else { 
msg $chan !greet <your greeting here> and i will greet you with that every time you join. 
} 
} 
on *:text:!greet *:#: { 
hadd -s greet $nick $2- 
var %greeting = $hget(greet,$nick) 
msg $chan $nick $+ 's greeting was set to: %greeting 
} 
#greet end 

 

i would like to at least try and tackle this myself
so any suggestions on how to approach it would be appreciated as opposed to code


The Kodokan will move you, one way or another.
#108473 19/01/05 10:02 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I know you asked for ideas but i feel this idea is hard to show without code, I often do this to ensure my code runs smoother with out having to make checks for things like the hash table existing and being loaded etc etc
Simply instead of refrencing the hash table by name you create a identifier alias that returns the hashtable name, if also creates it and loads it up if it doesnt exist., this allows you to, if u had such reason to , replace the saved version, and /hfree the table, the next time any script refrences it, the table is created and loaded from disk again.

I also moved the /hsave straight after the /hadd, IMO this is better, even if more disk intensive although im doing them all the time recording stuff of very active channels and hsaving the table and i dont notice any delay likely windows is just caching it up.

Code:
#greet on 
alias -l greet {
  if (!$hget(greet)) {
    hmake -s greet 100
    if ($isfile(greet.hsh) == $true) hload -s greet greet.hsh }
  return greet
}
on !*:join:#channelnamehere: { 
  if ($hfind($greet, $nick)) { msg $chan $nick $+ : $hget($greet, $nick) } 
  else { msg $chan !greet <your greeting here> and i will greet you with that every time you join. } 
} 
on *:text:!greet *:#channelnamehere: {
  hadd -s $greet $nick $2- 
  hsave -so $greet greet.hsh 
  var %greeting = $hget($greet,$nick) 
  msg $chan $nick $+ 's greeting was set to: %greeting 
} 
#greet end 


I also did the code so to show how you can reduce the code using $greet (if not the actual amount of code that gets run)

PS: i used $greet at all points but truth be told, you only need it on the first refrence to the hashtable in any script section, after that you can just use GREET if you liked, but i think thats haphazard unless you know the code wont ever get altered.

I wouldnt use $site or $address kinda my personal beleieve that people change em alot.

#108474 19/01/05 10:56 PM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
i can follow it fine with the exception of $greet
i also dont know why you have == $true with the $isfile
probably because ive never run accorss the whole identifier alias thing

Last edited by ricky_knuckles; 19/01/05 10:59 PM.

The Kodokan will move you, one way or another.
#108475 19/01/05 11:03 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
$isfile returns $true if the specified file exists.

#108476 19/01/05 11:29 PM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
the hash tutorial i used had it and it didnt have == $true
just
if ($isfile(whatever.hsh)) {
sorry if im being whiney again im just trying to understand


The Kodokan will move you, one way or another.
#108477 19/01/05 11:33 PM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
managed to get it to work on address rather than name i went ahead and used address 0
and tossed in a variable su 10 on the hadd in case someone tries to exploit that: have a gander.
Code:
 
#greet on
on *:start: {    
  if ($exists(greet.hsh)) {      
    hmake -s greet 100    
    hload -so greet greet.hsh  
  }  
  else { 
    hmake -s greet 100
    hsave -so greet greet.hsh 
  }
}
on *:exit: { 
  hsave -so greet greet.hsh 
  hfree -s greet 
}
on !@*:join:#: {
  if ($hfind(greet, $address($nick, 0))) {
    msg $chan $nick $+ : $hget(greet, $address($nick, 0)) 
  }
  else { 
    msg $chan !greet <your greeting here> and i will greet you with that every time you join.
  }
}
on @*:text:!greet *:#: { 
  if (%aa != on) {  
    hadd -s greet $address($nick, 0) $2-
    hsave -so greet greet.hsh
    var %greeting = $hget(greet, $address($nick, 0))
    msg $chan $nick $+ 's greeting was set to: %greeting
    set -su10 %aa on
  }
}
#greet end
 

Last edited by ricky_knuckles; 19/01/05 11:41 PM.

The Kodokan will move you, one way or another.
#108478 19/01/05 11:46 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
if ($isfile(file)) { is the equivalent of checking whether its $true.
if (!$isfile(file)) { is the equivalent of checking whether its $false. smile

Last edited by SladeKraven; 19/01/05 11:48 PM.
#108479 20/01/05 12:00 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
thats what i thought
so why would you use the longer version?
im sure theres some benefit im not seeing

anyways,
thanks slade


The Kodokan will move you, one way or another.
#108480 20/01/05 12:06 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
i can follow it fine with the exception of $greet
i also dont know why you have == $true with the $isfile
probably because ive never run accorss the whole identifier alias thing


SladeKarvens correct i didnt need to check against $true, its just a habbit from from ofther languages where they dont have true false identifiers, its just something or null, so when it said replies with $true or $false i thought id check it was $true

an alias that works as an identifier is simple an alias that returns a value and the alias usied as $aliasname is replaced with that value, just like //echo hello $me is going to say Hello DaveC
example
alias BOB { return BILL }
//echo hello $BOB
hello BILL

Code:
alias -l greet {
  ; check if hashtable GREET exists
  if (!$hget(greet)) {
    ;
    ; table doesnt exist so create table GREET
    hmake -s greet 100
    ;
    ; check if file exists to laod table from
    if ($isfile(greet.hsh)) {
      ;
      ; file exists so load table from file
      hload -s greet greet.hsh
    }
  ;
  ; return the value "greet" as that is the hash tablename (also HAPPENS to be the alias name were in)
  return greet
}

#108481 20/01/05 12:38 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
couldnt you do the same thing witha variable
?
still dont get it
thanks for trying to explain


The Kodokan will move you, one way or another.
#108482 20/01/05 12:48 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
no u cant, a variable well not execute code everytime u request it.

The idea is $greet returns to the script that has it in the value in side speechmarks "greet", now someone might say, well whippy do what is so great about that?

Well it also MAKES the table if it doesnt exist, and LOADS the table if the file exists

try typing /hfree greet while the bots going and see what happens if you use greet as apposed to using $greet, if u used $greet, it just wont make a difference, the alias greet would make the hashtable again, and load it from disk

#108483 20/01/05 12:57 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Just FYI, you should use $isdir() for finding out if a directory exists, and $isfile() for finding out if a file exists, $exists() will be $true if the path is either a file or a directory, so your $exists(greet.hsh) would return true if greet.hsh was a directory.


New username: hixxy
#108484 20/01/05 01:45 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
thanks for the clarity
i changed it
anything else before i resubmit


The Kodokan will move you, one way or another.
#108485 20/01/05 02:18 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
If you're submitting it to a website for other people to download, then i'd use $scriptdir to save and load the .hsh file, that way the file will be saved in the directory the script is in, and not the mIRC directory.

If you do decide to use $scriptdir, then you'll need to surround the filepath in quotes, eg:

Code:
hsave -o greet " $+ $scriptdirgreet.hsh"


New username: hixxy
#108486 20/01/05 02:26 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
well im finished
Code:
 #greet on
on *:start: {    
  if ($isfile(greet.hsh)) {      
echo 5 -a Greet.hsh found.    
hmake greet 100    
echo 5 -a Table greet created.    
hload -o greet greet.hsh  
echo 5 -a Loaded entries from greet.hsh.  
}  
  else { 
    hmake greet 100
echo 5 -a Table greet created.     
 }
}
on *:exit: { 
  hsave -o greet " $+ $scriptdirgreet.hsh"  
  hfree greet 
}
on !@*:join:#: {
  if ($hfind(greet, $address($nick, 0))) {
echo 5 -a Entry found.    
msg $chan $nick $+ : $hget(greet, $address($nick, 0)) 
  }
  else { 
    msg $chan Type !greet <your greeting here> and i will greet you with that every time you join.
  }
}
on @*:text:!greet *:#: { 
  if ((%aa != on) && ($hget(greet))) {  
    hadd greet $address($nick, 0) $$2-
echo 5 -a Entry created for $nick $+ .    
hsave -o greet " $+ $scriptdirgreet.hsh" 
echo 5 -a Table greet saved to greet.hsh.    
var %greeting = $hget(greet, $address($nick, 0))
    msg $chan $nick $+ 's greeting was set to: %greeting
    set -su10 %aa on
  }
else { hmake greet 100
echo 5 -a Table greet created
hadd greet $address($nick, 0) $$2- 
echo 5 -a Entry created for $nick $+ .
}
}
#greet end

Last edited by ricky_knuckles; 20/01/05 04:28 AM.

The Kodokan will move you, one way or another.
#108487 20/01/05 02:36 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
thanks for the tip
Q: would any of the old hands upward find it objectionable for me to give you due credit when i submit
i.e. "i dont want my name attached to that garbage"
?


The Kodokan will move you, one way or another.
#108488 20/01/05 02:51 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
i.e. "i dont want my name attached to that garbage"


LMAO

Heres a tip, if your going to use $address($nick, 0), u might aswell save yourself some time and use $address its gonna be the same thing minus the *! on the front.

/help Remote Identifiers

#108489 20/01/05 02:54 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
well hell the time is already spent i may as well just keep it in mind for next time

Last edited by ricky_knuckles; 20/01/05 03:08 AM.

The Kodokan will move you, one way or another.
#108490 20/01/05 04:28 AM
Joined: Nov 2004
Posts: 332
R
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
i didnt name names but i did extend a big thanks to mirc.com


The Kodokan will move you, one way or another.

Link Copied to Clipboard