mIRC Home    About    Download    Register    News    Help

Print Thread
hash table greet system #108136 17/01/05 05:38 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
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

Last edited by ricky_knuckles; 17/01/05 05:39 AM.

The Kodokan will move you, one way or another.
Re: hash table greet system #108137 17/01/05 07:24 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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-
}

Last edited by SladeKraven; 17/01/05 07:37 AM.
Re: hash table greet system #108138 17/01/05 07:31 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
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

Last edited by ricky_knuckles; 17/01/05 07:37 AM.

The Kodokan will move you, one way or another.
Re: hash table greet system #108139 17/01/05 07:41 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

Re: hash table greet system #108140 17/01/05 07:47 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
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


The Kodokan will move you, one way or another.
Re: hash table greet system #108141 17/01/05 07:49 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Yes and that is a hash table, and it works...

Re: hash table greet system #108142 17/01/05 07:52 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
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


The Kodokan will move you, one way or another.
Re: hash table greet system #108143 17/01/05 07:55 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
You're welcome lol.. grin

Re: hash table greet system #108144 17/01/05 08:12 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
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


The Kodokan will move you, one way or another.
Re: hash table greet system #108145 17/01/05 08:17 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
just a addition for anyone who might need it the verbose switch is -s just like for variables


The Kodokan will move you, one way or another.
Re: hash table greet system #108146 17/01/05 08:23 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
[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
}

Re: hash table greet system #108147 17/01/05 08:43 AM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
not working for me


The Kodokan will move you, one way or another.
Re: hash table greet system #108148 17/01/05 11:39 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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

Last edited by FiberOPtics; 17/01/05 12:27 PM.
Re: hash table greet system #108149 17/01/05 02:37 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Re: hash table greet system #108150 17/01/05 10:18 PM
Joined: Nov 2004
Posts: 332
R
ricky_knuckles Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
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

Last edited by ricky_knuckles; 17/01/05 10:23 PM.

The Kodokan will move you, one way or another.
Re: hash table greet system #108151 09/10/05 08:11 PM
Joined: Oct 2005
Posts: 7
B
Bossen Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
B
Joined: Oct 2005
Posts: 7
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

Last edited by Bossen; 09/10/05 08:11 PM.