mIRC Homepage
Posted By: ricky_knuckles hashgreet update - 19/01/05 07:57 PM
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
Posted By: DaveC Re: hashgreet update - 19/01/05 10:02 PM
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.
Posted By: ricky_knuckles Re: hashgreet update - 19/01/05 10:56 PM
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
Posted By: SladeKraven Re: hashgreet update - 19/01/05 11:03 PM
$isfile returns $true if the specified file exists.
Posted By: ricky_knuckles Re: hashgreet update - 19/01/05 11:29 PM
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
Posted By: ricky_knuckles Re: hashgreet update - 19/01/05 11:33 PM
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
 
Posted By: SladeKraven Re: hashgreet update - 19/01/05 11:46 PM
if ($isfile(file)) { is the equivalent of checking whether its $true.
if (!$isfile(file)) { is the equivalent of checking whether its $false. smile
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 12:00 AM
thats what i thought
so why would you use the longer version?
im sure theres some benefit im not seeing

anyways,
thanks slade
Posted By: DaveC Re: hashgreet update - 20/01/05 12:06 AM
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
}
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 12:38 AM
couldnt you do the same thing witha variable
?
still dont get it
thanks for trying to explain
Posted By: DaveC Re: hashgreet update - 20/01/05 12:48 AM
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
Posted By: tidy_trax Re: hashgreet update - 20/01/05 12:57 AM
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.
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 01:45 AM
thanks for the clarity
i changed it
anything else before i resubmit
Posted By: tidy_trax Re: hashgreet update - 20/01/05 02:18 AM
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"
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 02:26 AM
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
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 02:36 AM
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"
?
Posted By: DaveC Re: hashgreet update - 20/01/05 02:51 AM
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
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 02:54 AM
well hell the time is already spent i may as well just keep it in mind for next time
Posted By: ricky_knuckles Re: hashgreet update - 20/01/05 04:28 AM
i didnt name names but i did extend a big thanks to mirc.com
© mIRC Discussion Forums