mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 3 1 2 3
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
I saw "And you can go ahead and write an example of the code..." which just made me stop reading any further back, and hence the comment. Perhaps I misread - or maybe it was too easy to misinterpret what was meant...apologies if that is the case.


Sais
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
An understandable misunderstanding. The keyword, from what you quoted, in this case is "example". He's basically saying that while a full code would be nice, an example (aka pseudocode) would be acceptable (or possibly better), since that way he can learn.

Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Yeah that's probably the best idea. I'll use the On:dialog event to trigger by clicking in the icon box area like it would on the address book. Take your time with that code, theres no rush.

Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Done yet Russel? I kindof thought it would be done by now. ^^ Just wanted to make sure you knew I was still here. :P I need to script more...

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
LOL...Sorry, too many projects overlapping, I honestly forgot all about this, and since you said you wanted to write it yourself, I didn't put it on my list of projects to complete. However, I will do so now, and will post as soon as I get it done (based on the rate I'm currently going through that list, about another week or two)...By all means give it a shot yourself while waiting.

Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Yeah. Good thing I posted then. I've started on hash tables, finally. I could get the hang of it if I could just tell it to return at least something on every error message. This isn't exactly FOR the dialog, but the dialog will be able to pull from the same script. Revise as much as you like:
Code:
ON *:TEXT:+wolf*:#: { 
  if ( $2 != $null ) { 
    var %name = $2
    /hmake %name 10
    hadd -m %name Charname %name
    hadd %name Pack --
    hadd %name Rank --
    hadd %name Hist --
    hadd %name Desc --
    hadd %name Health 10
    hadd %name Hunger 10
    hadd %name Exp 0
    /msg $chan $2 added to directory.
  }
  elseif ( $2 == $null ) {
    /msg $chan Insufficient parameters: Please specify a nick to add.
  }
  else { /say $2 is already listed in the archive! }
}
On *:TEXT:-wolf*:#: {
  if ( $2 != $null ) {
    /hfree $2 
    /msg $chan $2 has been erased from the directory.
  }
  elseif ( $2 == $null ) {
    /msg $chan Insufficient parameters: Please specify a nick to wipe.
  }
}

;------------------------Bio
On *:TEXT:.bio*:#: {
  if ( $2 != $null ) { /msg $chan $hget( [ $$2 ], Hist ) }
  elseif ( $2 == $null ) { 
  } 
  /msg $chan $hget( [ $nick ], Hist ) 
}
else { /msg $chan I don't have a bio set for that wolf. }
}
On *:TEXT:+bio*:#: {
if ( $3 != $null ) { /hadd $nick $$3 | /msg $chan Your character's history has been set. Type .bio to view it. }
if ( $3 == $null ) { /msg $chan Insufficient parameters: Type in your bio!! }
}

;------------------------Description
On *:TEXT:.desc*:#: {
if ( $2 != $null ) { /msg $chan $hget( [ $$2 ], Desc ) }
elseif ( $2 == $null ) {
}
/msg $chan $hget( [ $nick ], Desc ) 
}
else { /msg $chan I don't have a description set for that wolf. }
}
On *:TEXT:+desc*:#: {
if ( $3 != $null ) { /hadd $nick Desc $$3 | /msg $chan Your character's description has been set. Type .desc to view it. }
if ( $3 == $null ) { /msg $chan Insufficient parameters: Type in your description!! }
}

;------------------------Greet


;------------------------Pack

;------------------------Rank


When you try to add something that is already there, I don't know how to make it check to see if its already there and return something like "Blah is already in the directory!!"

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Im not totally sure what you are looking for.

if ($hget(%name,Pack)) <pack is already entered.

Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Is there anything I can use to make the script return something if a hash table or item that I need isnt found? for example, ( if == hashdoesntexist ) { msg $chan Info not found!! } ( know this isnt a real if-then-else statement.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Here are multiple ways you can do it.

Code:
if (!$hget(Table,Item)) { do this }


Code:
if ($hget(Table,Item) == $null) { do this }


Code:
if ($hfind(Table,*Wildcarded item to find*,0,w) == 0) { do this }


Code:
if ($hfind(Table,*Wildcarded data to find*,0,w).data == 0) { do this }


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Thanks, that worked. I'm going to post my script again. I just got some of it working. The book is created, it adds a wolf at specified keyword. Like this:
[Nick]
Name=(character's name)
Hist=(character's history)
ect...

The Hash table info looks like that, right after it is saved. I've spent around two (gradual) months on this script. There is one huge problem, it seems.

Whenever I close it out, I lose all of my info in the hash tables. So I studied the help file a bt more and found that you have use hload and hsave. Though with hload you can't load it as described above, with a separate hash table for each character, you can only load items!! If I misread this, please let me know that it's not true because I sure as heck am not going to totally re-script two months' hard work unless I absolutely have to. If there is any way I can fix this without wiping the whole thing clean then please let me know.

If I did, I assume that I'd have to start using $hfind ALLOT. instead of the format above I'd use something like this:
[CharInfo]
nick.name=(character's name)
nick.hist=(character's history)
ect..

Then I'd have to use hfind to search for the name and piece of information.
Anyway's here is my script. Not much for 2 months.

Code:
ON 100:TEXT:+wolf*:#: { 
  if ( $2 != $null ) {
    if ($hget([ $2 ], status)) { msg $chan Error: $2 is already listed in the archive! }
    if ($hget([ $2 ], status) == $null ) {
      var %name = $2
      hmake %name 12
      hadd %name Status exists
      hadd %name Charname  
      hadd %name Greet      
      hadd %name Pack  
      hadd %name Rank  
      hadd %name Hist  
      hadd %name Desc  
      hadd %name Health 10
      hadd %name Hunger 10
      hadd %name Exp 0
      hadd %name Level
      msg $chan %name added to directory.
      halt
      :error
      msg $chan $2 is already listed in the directory!
    }
  }
  if ( $2 == $null ) { msg $chan Insufficient parameters: Please specify a nick to add. }
}
On 100:TEXT:-wolf*:#: {
  if ( $2 != $null ) { 
    if (!$hget([ $2 ], status)) { msg $chan Error: Wolf does not exist. } 
    if ($hget([ $2 ], status)) { hfree $2 | msg $chan $2 has been erased from the directory. }
  }
  elseif ( $2 == $null ) { msg $chan Insufficient parameters: Please specify a nick to wipe. }
}

;------------------------Bio
On *:TEXT:.bio*:#: {
  if ( $2 != $null ) { 
    if ($hget([ $$2 ], Hist )) { /msg $chan $hget( [ $$2 ], Hist ) }
    if (!$hget([ $$2 ], Hist )) { /msg $chan No biography found. }
  }
  elseif ( $2 == $null ) { 
    if ($hget( [ $nick ], Hist ) != $null ) { /msg $chan $hget( [ $nick ], Hist ) }
    if (!$hget( [ $nick ], Hist )) { /msg $chan No biography found. }
  }
  else { /msg $chan I don't have a bio set for that wolf. }
}
On *:TEXT:+bio*:#: {
  if ( $3 != $null ) { 
    if ($hget([ $2 ], status)) { hadd $2 Hist $$3- | msg $chan Your character's history has been set. Type .bio to view it. }
    if (!$hget([ $2 ], status)) { msg $chan Error: Wolf not found. }
  }
  if ( $3 == $null ) { 
    if ( $2 == $null ) { /msg $chan Insufficient parameters: Type your nick and then your character's description. ( +bio <nick> <history> ) }
    if ( $2 != $null ) { /msg $chan Insufficient parameters: Type in your character's History!! }
  }
}

;------------------------Description
On *:TEXT:.desc*:#: {
  if ( $2 != $null ) { 
    if ( $hget( [ $$2 ], Desc ) != $null ) { msg $chan $hget( [ $$2 ], Desc ) }
    if (!$hget( [ $$2 ], Desc )) && ($hget( [ $$2 ], status)) { /msg $chan I don't have a description set for that wolf. | /halt }
    if (!$hget([ $$2 ], status)) { msg $chan Error: Wolf not found. }
  }
  elseif ( $2 == $null ) {
    if ( $hget( [ $nick ], Desc ) != $null ) { msg $chan $hget( [ $nick ], Desc ) }
    if ( $hget( [ $nick ], Desc ) == $null ) { /msg $chan You have not set your character's description!! }
  }
}
On *:TEXT:+desc*:#: {
  if ( $3 != $null ) { 
    if ($hget([ $2 ], status)) { hadd $2 Desc $$3- | msg $chan Your character's description has been set. Type .desc to view it. }
    if (!$hget([ $2 ], status)) { msg $chan Error: Wolf not found. }
  }
  if ( $3 == $null ) { 
    if ( $2 == $null ) { /msg $chan Insufficient parameters: Type your nick and your character's description. ( +desc <nick> $&
      <description> ) Note: If it is too long it will cut. }
    if ( $2 != $null ) { /msg $chan Insufficient parameters: Type in your description!! }
  }
}
;-------------------------Name
On *:TEXT:+name*:[%channel.SB.OOC]: {
  if ( $3 != $null ) { 
    if ( [$hget([ $nick ], status)]) { hadd $nick $3-6 | msg $chan You set your character's name to $ }
    if ([!$hget([ $nick ], status)]) { msg $chan Error: Wolf not found. }  
  } 
  if ( $3 == $null ) {
    if ( $2 == $null ) { msg $chan Insufficient parameters: Type your nick and your character's (full) name. ( +greet <nick> <name> ) }
    if ( $2 != $null ) { msg $chan Insufficient parameters: Type in your character's full name. }
  }
}

;------------------------Greet
;[%channel.SB.OOC]
On *:TEXT:+greet*:#Moonhaven: {
  if ( $3 != $null ) { 
    if ( [$hget([$$2], status)] != $null ) { hadd $$2 Greet $$3- | msg $chan Your greet has been set. It will play each time you enter the main channel. }
    if ([!$hget([$$2], status)]) { msg $chan Error: Wolf not found. }  
  } 
  if ( $3 == $null ) {
    if ( $2 == $null ) { msg $chan Insufficient parameters: Type your nick and greeting. ( +greet <nick> <greeting> ) }
    if ( $2 != $null ) { msg $chan Insufficient parameters: Type in your greeting! }
    :error
    msg $chan Error: Wolf not found.
  }
}
;%channel.greeting
On 1:JOIN:#Moonhaven: { 
  if ([$hget([$nick], Greet) != $null ) { msg $chan [ $hget([ $nick ], Greet) ] }
}
;------------------------Pack
/*
On 100:TEXT:+pack*:#: {
  if ( $2-3 != $null ) && ( $hget( [ $$2 ], Pack ) != $null ) { tochan Pack changed from: $hget( [ $$2 ], Pack ) to $$3, | hadd $$2 Pack $$3 }
  elseif ( $2-3 == $null ) && ( $hget( [ $2 ], Pack ) == $null ) { tochan Pack set: $$3 | hadd $$2 Pack $$2 }
  elseif ( $2 == $null ) { tochan Insufficient parameters: please specify wolf and wolfpack. }
  elseif ( $3 == $null ) { tochan Insufficient parameters: Please specify a wolfpack. }
  elsif 
  :error
  tochan Wolf not found in directory, please add with +wolf.
}
*/
On 1000:TEXT:+pack*:#: {
  if ( $3 != $null ) { 
    if ( $hget([ $3 ], Status )) {
      if ( $hget([ $2 ], Pack )) { 
        hadd $2 Pack $3-4
      msg $chan $2's has been booted from the [ $hget([ $2 ], Pack ) ] Pack and put in the $3 Wolfpack, with default rank packmate. Type .info to view it. }
      if (!$hget([ $2 ], Pack )) { 
        hadd $2 Pack $3-4 
      msg $chan $2's has entered the $3 Wolfpack with default rank packmate. Type .info to view it. }
    }
    if (!$hget([ $2 ], Status)) { msg $chan Error: Wolf not found. | /halt }
    if (!$hget([ $3 ], Status)) { 
      var %pack = $3
      hmake %pack 15
      hadd %pack Status exists
      hadd %pack Alpha --
      hadd %pack Beta  
      hadd %pack Elder  
      hadd %pack Gaurdian  
      hadd %pack Gamma  
      hadd %pack Sentinal  
      hadd %pack Hunter/Scout  
      hadd %pack Packmate  
      hadd %pack Pup  
      hadd %pack Omega  
      hadd %pack Honoredguest  
      hadd %pack Assessment  
      hadd %pack Pledge  
      msg $chan A new pack has been created. The %pack Wolfpack.
    }
  }
  if ( $3 == $null ) { 
    if ( $2 == $null ) { /msg $chan Insufficient parameters: Type the nickname and the character's pack. ( +desc <nick> <pack name> ) }
    if ( $2 != $null ) { /msg $chan Insufficient parameters: Type in the pack name. }
  }
}

On *:TEXT:?pack*:#: { tochan +pack: Used for setting a wolf's pack. Format: ( +pack <wolf> <pack> ) }
;------------------------List Members
On *:TEXT:.list*:[%channel.SB.OOC]: {
  if ($2) {
    $hfind 
  }
}
;------------------------Rank
On 100:TEXT:+rank*:#: {
  if ( $3 != $null ) { 
    if ($hget([ $2 ], * )) { hadd $2 rank $$3- | msg $chan $2's rank has been set. Type .info to view it. }
    if (!$hget([ $2 ], * )) { msg $chan Error: Wolf not found. }
  }
  if ( $3 == $null ) { 
    if ( $2 == $null ) { /msg $chan Insufficient parameters: Type the nickname and the character's rank. ( +desc <nick> <rank> ) }
    if ( $2 != $null ) { /msg $chan Insufficient parameters: Type in the rank. ( Alpha : Beta : Elder : Gaurdian : Gamma : Sentinal : Hunter/Scout : Packmate : Pup : Omega ) }
  }
}
;
;------------------------Info
On *:TEXT:.Info:#: {

}
;Skylax Blacktail, Packmate of Sweetbreeze:(Hunger: 10) (Energy: 20) (Health: 10) (Rests: 0) (Exp: 32)
;------------------------Name



The script you said you'd work on would be very much appreciated but not required, Russel. Heh, I used to think this roleplay was stupid, now it opened me up to a new hobby. Thanks for your help guys. : D

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The method of saving your hash table information is to use the /hsave command (and /hload to load it up next time)

These are well documented in the help file, and noting that the format is similar to that of an ini file, I would like to recommend that you read up on those commands, as they have a -i switch, which makes the information stored compatable with the ini file format.

Sorry I didn't get back to you sooner on this, but I had some problems with my phone line, which affected my internet, as I use a DSL connection.

I'm glad to see that you put a lot of effort into this, and your posts have answered a few questions that I was going to post...now to incorporate that information with what I already had.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I don't have time to go through it all right now, but if you use /hsave, then use /hload, it will load it exactly as it was before.

Assuming you have data in a hash table called Table:

/hsave Table table.hsh
/hfree Table
/hmake Table 10
/hload Table table.hsh

... then you'll have the exact same table as you had originally.

As for hash tables, remember that it's formatted as ITEM = DATA. That means that you'd want to do like you suggested and do nick.name, nick.hist, etc. for your items, OR use multiple hash tables...

Table: Name
Item: Nick
Data: Nick's Name

Table: Hist
Item: Nick
Data: Nick's Hist

etc.

Having multiple tables will help to make using them much easier. And if you're just getting info on a specific person, you can use $hget instead of $hfind.

$hget(Name,nick)
$hget(Hist,nick)

Etc.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
....so you're saying that I can run my script, and when I use hsave to save all my stuff:

[Nick]
Desc = (chardesc)
Name = (charname)
[Nick2]
Desc2 = (chardesc2)
Name2 = (charname2)

...ect

I can then close the window, and when I open it again and use hload to load the exact same thing. Multiple tables? If I cant do it with just those commands, how can I make it so it does. I might need around 30 of these little group things, hash tables, and I REALLY don't want to alter the script I've made.



Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
To answer your question, YES. But!!
Thats how an ini file is saved. The way you have it layed out.

A hash table works with 3 pieces of information. The table name first. What you call the data you are saving and the data. Look at it as:

a hash table has slots to save data in. You name each slot what you want so you can pull up the information later. Say I save the time someone joins a room. I could name the table j#Channel. I would name the slot after the nickname who joined and make the data the time. So now I have a table named j $+ $chan and I can easily see what time $nick joined.

on *:join:#:/hadd j $+ $chan $nick $asctime(HH:nnoo)

Now if I want to retrieve the info I use $hget. $hget(j $+ $chan,$nick) would return the time $nick joined $chan.

So for your layout, you have two pieces of information per nickname. You don't want to create a new hash table for each name. They use up your RAM. Instead I personally would save your information under the nickname and seperate the two pieces of info by a space so you can use $gettok to retrieve it.

Table named TEST.
/hadd test $nick (chardesc) (charname)
This saves (chardesc) (charname) under the $nick line of the test hash table.
$hget(test,$nick) == (chardesc) (charname)
$gettok($hget(test,$nick),1,32) == (chardesc)
$gettok($hget(text,$nick),2,32) == (charname)

I h ope this helps you plan your hash table better. smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can save a hash table in an ini format, but that's really not necessary since you're working with it in mIRC and so it doesn't matter how it's saved. I would just save each table whenever you change the table and then load all tables when you start mIRC (on START).


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Cool. So I will have to re-script it, though not all of it...So how would easily be able to replace each piece of information? some of them are a few sentences long while others are only a few numbers. Whats the easiest way to be able to overwrite each piece of data:
(charname) (chardesc) ----> (charname) (chardesc2)
Would have to set the the number of words (parameters) for each peice? Geez, this is getting complicated. -_-

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
When you store the data for a hash table item, if the item already exists, then the data for that item is overwritten by the newest entry.
Eg: /hadd Table Name Description stores the description for the specified name in the Table
/hadd Table Name Description2 will overwrite the first Description with the second description
/hadd Table Name Description3 will overwrite the 2nd Description with the 3rd Description.

If any of the descriptions match the previous description, then you won't notice a change, although the information will have changed.

Note that Table and Name (in my above examples) are case-insensitive

Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Yes, I read all that in the help file, though I don't think thats what he means. I have some ideas for this, since I'm having trouble understanding some of the approaches you guys have mentioned.
Idea 1:
I re-script it so that It creates an item for each piece of information, prefixed with the nickname of that user. Then I use $hfind with a wildcard of some sort to find it and that's how I'll use it.
Idea 2:
I leave most of the script as it is, making a separate file for each user/nick because of the hash tables, I really don't know how I'd do this but it's more of a last resort. smirk
Idea 3:
I leave nearly all of the current script as it is, and follow Riamus's idea, saving the file after the file is modified. I think this would be the shortest once I figure it out.
Idea 4:
Modify it to have tokens, which I'll have to read about and understand first.

Hmm. I'm going to try the 3rd first, since I'm closest. I might have over 30 tables that could have as many as 15 items each. I appreciate all your help and advice. Thanks.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can have multiple tokens in a hash table's data if you want. I think that's what you're talking about in your previous example. Then, you'd just use $gettok or /tokenize to help you access the correct token.

As for your first idea, you shouldn't need $hfind unless you're searching the DATA for information and you don't know the nick. As long as you know the nick, you can easily use $hget to get the data and it's faster.

For the second idea, I would not suggest editing the files manually unless you're sure you are formatting them properly or else the /hload may fail and you could have problems.

For the third idea, it won't be a problem having multiple tables. I'm running almost 200 tables right now at all times. You just need to keep track of them. You *can* get it all into a single table, but that will require a little more work and you'd probably want to have your ITEM names include what would normally be the table name.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Ok ive started up on it again. Went to loading the script and scripting the load sequence since that one of the most important parts. I believe it's scripted fine,
Code:
on *:START:{
  if ($isfile($scriptdir $+ Stats.hsh) == $true) {
    hmake Beaststats
    hload Beaststats Stats.hsh
  }
}

but i get this error message...
* /hload: unable to open 'C:\Downloads\Zephyr\Bot\mIRC\Wolves.hsh'

I used to be able to fix that by changing the path so that there were no spaces, but i guess it doesn't work anymore?

Page 2 of 3 1 2 3

Link Copied to Clipboard