mIRC Homepage
Posted By: ricky_knuckles hash table greet system - 17/01/05 05:38 AM
im trying to make a greeting system based on something i saw done with ini's but im going to use a hash table
what i want is for someone to join the bot msgs the chan type !greet <your greeting here> and i will greet you with that every time you join
this is done by nick by the way since i didnt want to bother with the mess of doing it by id
----------------------------code------------------------------------
#greet on
on *:start:{ { hmake greet 10 }
if ($isfile(greets.hsh)) {
hload greet greets.hsh
}
else {
hadd greet ReIgN kombanwa minasan.
hadd greet snipe i am but a little hamster.
hadd greet time i don't have any "time" for irc.
hadd greet sango-chan fjeer my boomerang.
hadd greet str|fe "the str|fe in my life translates as a bend."
hsave -o greet greets.hsh
}
}
on *:exit:{ { hsave -o greet greets.hsh
hfree greet
}
}
on *:join:#:{
if ($nick != $me) { var %greeting = $hget(greet, $nick)
msg $chan %greeting
}
}
on *:text:!greet *:{
hdel greet $nick
hadd greet $nick $$2-
}
on *:join:#:{
msg $chan !greet <your greeting here> and i will greet you with that every time you join.
}
#greet end
-----------------------------------------code----------------------------
now my problem it doesnt work
any thoughts on why
edit any switches for a verbose version of hash commands
so i can maybe zero in on what isnt working confused
Posted By: SladeKraven Re: hash table greet system - 17/01/05 07:24 AM
Code:
on *:start: {    
  if ($exists(greet.hsh)) {      
    hmake greet 100    
    hload -oi greet greet.hsh  
  }  
  else { 
    hmake greet 100
    hadd greet ReIgN kombanwa minasan. 
    hadd greet snipe i am but a little hamster. 
    hadd greet time i don't have any "time" for irc. 
    hadd greet sango-chan fjeer my boomerang. 
    hadd greet str|fe "the str|fe in my life translates as a bend." 
    hsave -oi greet greet.hsh 
  }
}

on *:exit: { 
  hsave -oi greet greet.hsh 
  hfree greet 
}

on !*:join:#: {
  if ($hfind(greet, $nick)) {
    msg $chan $hget(greet, $nick) 
  }
  else { 
    msg $chan !greet &lt;your greeting here&gt; and i will greet you with that every time you join.
  }
}

on *:text:!greet*:#: { 
  hadd greet $nick $2-
}
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 07:31 AM
i especially like the way you explained nothing
how about answering my question there buddy
-i treats file as ini
no hdel
so it doesnt delete their old entry before adding a new one
frown
dude
Posted By: SladeKraven Re: hash table greet system - 17/01/05 07:41 AM
Code:
on *:start: {    
  if ($exists(greet.hsh)) {      
    hmake greet 100    
    hload -oi greet greet.hsh  
  }  
  else { 
    hmake greet 100
    hadd greet ReIgN kombanwa minasan. 
    hadd greet snipe i am but a little hamster. 
    hadd greet time i don't have any "time" for irc. 
    hadd greet sango-chan fjeer my boomerang. 
    hadd greet str|fe "the str|fe in my life translates as a bend." 
    hsave -oi greet greet.hsh 
  }
}

on *:exit: { 
  hsave -oi greet greet.hsh 
  hfree greet 
}

on !*:join:#: {
  if ($hfind(greet, $nick)) {
    msg $chan $hget(greet, $nick) 
  }
  else { 
    msg $chan !greet &lt;your greeting here&gt; and i will greet you with that every time you join.
  }
}

on *:text:!greet *[color:red]:#:[/color] { 
  hadd greet $nick $2-
}


You missed the target. Off hand I don't know exactly what was wrong with it as I didn't load it in but it should work now, I tried it before I posted. Sorry for not explaining. smile
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 07:47 AM
heres my issue
if i wanted to use a ini
ida made a ini
i want to use a hash table
so what does -i
accomplish in that code
im cool with and can follow the rest of it
Posted By: SladeKraven Re: hash table greet system - 17/01/05 07:49 AM
Yes and that is a hash table, and it works...
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 07:52 AM
son of a gun if it wasnt that one missing #
i put that in and fired it up and it works perfect
/me kisses slade in a purely platonic fashion
Posted By: SladeKraven Re: hash table greet system - 17/01/05 07:55 AM
You're welcome lol.. grin
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 08:12 AM
its tempermental though i added
below
hadd greet $nick $$2-
var %greeting = $hget(greet, $nick)
msg $chan $nick $+ 's greeting was set to: $+ %greeting
and it just quit firing
the hadd works but the onjoin doesnt
sigh
lots of buggies to get out
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 08:17 AM
just a addition for anyone who might need it the verbose switch is -s just like for variables
Posted By: SladeKraven Re: hash table greet system - 17/01/05 08:23 AM
[08:22] <Test1> !greet Testing...
[08:22] <Andy> Test1's greeting was set to: Testing...
[08:22] * Test1 has left #teens
[08:22] * Test1 has joined #teens
[08:22] <Andy> Test1: Testing...

Code:
on *:start: {    
  if ($exists(greet.hsh)) {      
    hmake greet 100    
    hload -o greet greet.hsh  
  }  
  else { 
    hmake greet 100
    hadd greet ReIgN kombanwa minasan. 
    hadd greet snipe i am but a little hamster. 
    hadd greet time i don't have any "time" for irc. 
    hadd greet sango-chan fjeer my boomerang. 
    hadd greet str|fe "the str|fe in my life translates as a bend." 
    hsave -o greet greet.hsh 
  }
}

on *:exit: { 
  hsave -o greet greet.hsh 
  hfree greet 
}

on !*:join:#: {
  if ($hfind(greet, $nick)) {
    msg $chan $nick $+ : $hget(greet, $nick) 
  }
  else { 
    msg $chan !greet &lt;your greeting here&gt; and i will greet you with that every time you join.
  }
}

on *:text:!greet*:#: { 
  hadd greet $nick $2-
  var %greeting = $hget(greet,$nick)
  msg $chan $nick $+ 's greeting was set to: %greeting
}
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 08:43 AM
not working for me
Posted By: FiberOPtics Re: hash table greet system - 17/01/05 11:39 AM
FO takes out his markers and gets busy:

Red means what has to be removed
Blue means what should be added

Code:
#greet on
on *:start:{[color:red] {[/color] hmake greet 10 [color:red]} [/color] 
  if ($isfile(greets.hsh)) {
    hload greet greets.hsh
  }
  else {
    hadd greet ReIgN kombanwa minasan.
    hadd greet snipe i am but a little hamster.
    hadd greet time i don't have any "time" for irc.
    hadd greet sango-chan fjeer my boomerang.
    hadd greet str|fe "the str|fe in my life translates as a bend."  
    hsave -o greet greets.hsh
  }
}
 [color:red]  [/color] 
on *:exit:{
 [color:blue] if ($hget(greet)) { [/color] 
  hsave -o greet greets.hsh 
  hfree greet
 [color:blue]}  [/color] 
}
 [color:red]  [/color] 
on *:text:!greet *:[color:blue]#:[/color] {
 [color:red] hdel greet $nick[/color]
  [color:blue]if ($hget(greet)) { [/color]
    hadd greet $nick [color:blue]$[/color]$2- 
    msg $chan $nick $+ 's greeting was set to: $2-
[color:blue]  }  [/color] 
}
 [color:red]   
[color:blue]on !*:join:#:{
  if ($hget(greet)) {
    if ($hget(greet,$nick) != $null) { msg $chan $v1 }
    else { msg $chan !greet &lt;your greeting here&gt; and i will greet you with that every time you join. }
  }
}
 [/color] 
on *:join:#:{
  if ($nick != $me) { var %greeting = $hget(greet, $nick) 
    msg $chan %greeting
  }
}
 [color:red]  [/color] 
on *:join:#:{
  msg $chan !greet &lt;your greeting here&gt; and i will greet you with that every time you join.
}
[/color]#greet end


  • You can't have two on join events in the same remote, only the first one will trigger (this remarks does not consider usage of ^ as event prefix, as it's not something to worry about now). Do you remember you had that post with your on text things, it's the same principle, but on join is even easier, since there's no matchtext. In the case of events which have matchtext, you can have multiple of them in one remote, as long as you organize em in a way, that incoming text gets grabbed by the right event.
  • The exclamation mark ! in the on join event, makes sure that this event is not triggered if you are the joining nick. That makes the if $nick == $me check obsolete. I've added an if check to make sure that a person actually has a greeting before trying to send it. If a person has no greeting, $hget(greet,$nick) would return a $null, and you would get an error trying to msg a $null (=nothing) to a channel.
  • The $v1 is the same as the old $ifmatch, meaning it is filled with the value of the v1 parameter of the last if condition that was parsed.

    Example: if ($me != FO) { echo -a Left parameter of the if: $v1 -- Right param of the if: $v2 }
  • No need to delete the $nick from the hash table with hdel first, as items in a hash table are unique, so if you add an item that is already in there, it is overwritten.
  • I've added a couple of if checks for: if ($hget(greet)) { do things }, to make sure that the hash table is actually loaded. Even though you load it in the on start event, if something happens (you or a script of yours frees all has tables, or just this one) you would get errors. This is one of those things that is very important in scripting, and granted, that I sometimes don't spend enough time at when posting snippets on the board. You should try to take as many things as possible in consideration, as there are always going to be unpredicted events, making your code generate errors. The only thing we can do is make it as waterproof as possible.
  • You will notice in this line: hadd greet $nick $$2- the double $. This means that the event/alias will stop if that parameter isn't provided. In other words, if a person types !greet with no msg, the code will stop.
  • I've put brackets around each if check, which I normally don't do. I put them there, because they are good practice to put em, and only people who really know what they are doing should omit them.
  • Your usage of braces is greatly improving, just some minor things there, that don't make the code malfunction, but are simply obsolete.

Cya later
Posted By: FiberOPtics Re: hash table greet system - 17/01/05 02:37 PM
Overlooked that in the matchtext of !greet the wildcard is included with a space between !greet and the wildcard, so the double $ isn't necessary here, though it's good to know anyway.
Posted By: ricky_knuckles Re: hash table greet system - 17/01/05 10:18 PM
my malfunction were resulting from conflicts with other things in my script
i eventually settled on a halfway between me and slade's
version
and putt it in a fresh bot umm
i think at one point i split it up and grouped it with everything else like the on start with my onstarts etc
it worked then but i decided maintenance would be rough
i guess ill share the end result which works mind you
-----------------------------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
-------------------------------code-----------------------------------
note if anyone else wants to do this i suggest takin optics code
wink wink*
thanks again guys grin
Posted By: Bossen Re: hash table greet system - 09/10/05 08:11 PM
Hi!
i dont get the !greet to work!
what must i do?
i use Mirc!

1: i type ALT+shif+R to get up the REMOTE to edit a Script.

Now i need help!

pliz help me! frown
© mIRC Discussion Forums