mIRC Home    About    Download    Register    News    Help

Print Thread
#97744 16/09/04 07:21 AM
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
I want when I request all items from a hash table with this script

Code:
alias hdump {
  if ($1 == $null) {
    var %cnt = $hget(0)
  }
  else {
    var %cnt = $hget($1,0).item
  }

  var %i = 1

  linesep

  while (%i <= %cnt) {
    if ($1 != $null) {
      var %item = $hget($1, %i).item
      var %data = $hget($1, %i).data
    }
    else {
      var %item = $hget(%i)
    }

    if (!%data) {
      echo -a %item
    }
    else {
      echo -a %item -> %data
    }
    inc %i
  }

  if (%cnt == 0) { echo -a no entries }
}


When I do hdump 'myhashtable' all Items + data gets shown like this:

Road_kill -> 53 500000
pian -> 55 112322300000
Tjirp -> 53 12300000

Then I want my script to check ALL items and data, if the 2nd data (12300000 at tjirp etc. etc.) is lower then another data inserted (eg. /hdump myhash 22300000) or could i just use an if-then-else eg. /hdump myhash 22300000, if (data2 <= $3) {

So that something like this comes out:

Tjirp is level 53 and has 12300000 defense, Road_kil is level 53 and has 500000 defense.

(note that pian isnt mentioned since he has 112322300000 defense which is higher then 22300000)

I hope you can help. thanks in forward



---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

Usage:

/mystats <table> will list the contents of the specified table
/mystats <category> <number> will list the items that have a value from the specified category, lower than the specified number.

Example:

Hash Table: stats
Item + data:

John 20 1000
Jane 35 800
Jake 80 2000
Janis 44 560
...

There are 2 categories, in our example the first column next to the nicks, and the second column.

/mystats stats 1 50 -> will list the nicks with a value lower than 50 based on category 1
/mystats stats 2 1000 -> will list the nicks with a value lower than 1000 based on category 2

etc.

Code:

 alias mystats {
  if $1 == $null { echo -a * You must specify a hash table. | return }
  if !$hget($1) { echo -a * This hash table doesn't exist. | return }
  if $2 == $null {
    echo -a Listing contents of hash table $1:
    var %a = 1
    while $hget($1,%a).item { echo -a $v1 -&gt; $hget($1,%a).data | inc %a }
  }
  else {
    if !$3 { echo -a * You must specify a number to compare. | return }
    if $2 !isnum 1- $+ $numtok($hget($1,1).data,32) {
      echo -a * You must specify a category between $v2
      return
    }
    window -h @@
    var %a = 1, %b = $calc($2 + 1), %c
    while $hget($1,%a).item { aline @@ $v1 $hget($1,%a).data | inc %a }
    filter -wwtc %b 32 @@ @@ *
    echo -a Listing players - Category: $2 - Lower than: $3
    %a = 1
    while $gettok($line(@@,%a),%b,32) &lt;= $3 { echo -a $line(@@,%a) | inc %a | inc %c }
    if !%c { echo -a No players found. }
    window -c @@   
  }
} 

Hope you find this somewhat useful,

Greets

Last edited by FiberOPtics; 16/09/04 11:01 AM.

Gone.
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
yes it helps a lot with getting the things but just 1 thing remains,

lets say I got hash file called "Dthash"

there are 5 people in:

Road_kill 53 500
Tjirp 51 600
Pianistu 59 800
CrazyGamer 43 200
Empress 55 300

When I do /mystats dthash 2 550 it returns:

Listing players - Category: 2 - Lower than: 550
CrazyGamer 43 200
empress 55 300
Road_kill 53 500

I been looking trough the code and since im not that good at it I cant find what I need to change to send it to someone with the text: Crazygamer is level 43 with Defense 200.

--

In the dialog im writing someone puts his offense + level. I want to store that in a hash file by On *:TEXT:*:?:{ if ($1 == 0555427347) { Msg $nick Added $nick with these stats: Offense $2, level $3, defense $4, etc, etc. | /hadd Dthash2 $8 $3 $4 (the $ wont be correct didnt look em up but it will store Irc nick given in dialog, Defense and level)

then when someone types !Getfarm I wanne do a checkup like this

if ($nick isin Dthash2){ //mylink dthash2 $hget($nick)+data (how:P?) msg $nick Available farms: //mylink dthash 2 $2(s2 being offense showed by the first mylink)
else { msg $nick Error: You havent registered or using a wrong nickname, register by downloading Tjirps script @ blablabla or change nick to giving Irc nick in the script }

So it checks up the $nick if its registered yes or no, then checks up nicks offense and compares it to defense from other players and then shows the players with a lower defense then his offense

I hope you get what I mean.

After I know that I just need to know one more thing but that I gonne try and figure out myself, cause you might think i am but i am not asking for whole scripts here, i did try to do it all myself


---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi eendje,

I see you are trying to make a game script. Now, it's not that I don't want to help you, but to make a script like that requires some basic/medium-advanced mIRC scripting skills. If you don't know how to check if a certain item is in a hash table, or how to output hash table data, then it's best to learn about hash tables first smile

In the mystats alias that I gave you, I used /echo as an example, expecting you to modify it to your needs...

I'm afraid I will end up writing your whole bot so I'll just give you some pointers:

/help custom identifiers
/help hash tables
/help token identifiers
/help while loops
/help custom windows
/help

Also, you could check out the tutorial section from mircscripts for more information.

Perhaps someone else here on this msgboard will be of further assistance.

Good luck with your bot,

Greets


Gone.
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
I knew that would be coming, For need certain knowledge about mirc, I do. Its just that this is the first time im working with hashtables and there are no real good use examples I can find anywere.


---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Try this one: link

Greets


Gone.
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
hmm, now I made small script to check whether the nick is in a hashtable (to verify he registered)

Code:
on *:TEXT:!getfarm:#:{ if ($hget(DarkHash, $address($nick,1)) == $address($nick,1)) {
    msg $chan You exist 
  }
  Else { 
    msg $chan You dont exist

  }
}




I tried it but it doesnt work, what is wrong? (it returns You exist always even if $nick doesnt exist)

Last edited by eendje; 16/09/04 01:42 PM.

---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

Code:
  
on *:TEXT:!getfarm:#somechannel:{ 
  if ($hget(DarkHash, $nick)) { msg $chan You exist }
  else { msg $chan You dont exist } 
}

Btw you had one too many closing braces }
The problem was that you compared the data of the hash table item "$nick" to the "$nick", which will of course not match, because a nickname is not the same as it's scores.

$hget(darkhash,itemname) --> will check if a certain item has data in the hash table

Suppose an entry in the hash table is:

eendje 50 1000

The item is: eendje
The data is: 50 1000

$hget(darkhash,eendje) will return the data, or: 50 1000
If a person is registered, then it means he has data, if he's not then he doesn't have data. So "$hget(darkhash,$nick)" will return scores if the person is in the hash table. Otherwise it won't return anything.

Hash tables can be visualized like this:

item1 data
item2 data
item3 data
...

An item in a hash table cannot contain spaces. The data can be whatever, even $null.

You can find more explanation in the link I gave you.

A custom identifier for your bot to know whether a person is registered could be:

alias registered return $iif($hget(darkhash,$$1),$true,$false)

Then use: if $registered($nick) { msg $chan You are registered }

Greets

EDIT: You've changed your code in the mean time, so this reply was for your first code not using $address

Last edited by FiberOPtics; 16/09/04 01:53 PM.

Gone.
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
ok nvm, got that solved now:)

script im using now:
Code:
on *:TEXT:!getfarm:#:{ if ($hget(Darkhash,$address($nick,1)) != $null) {
  msg $chan You exist 
}
Else { 
  msg $chan You dont exist
}
}


Again thanks for your help:D


---
signatures own
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
now its almost done (yay finnaly) just one thing remains, how to use your script to actual reply it to someone,

lets say someone says "!getfarm" I check he is registered, then

on *:TEXT:!getfarm:#:{
if ($hget(Darkhash,$address($nick,1)) != $null) {
window -h @@
var %a = 1, %b = $calc($2 + 1), %c
while $hget(DarkFarms,%a).item { aline @@ $v1 $hget(DarkFarms,%a).data | inc %a }
filter -wwtc %b 32 @@ @@ *
%a = 1
while $gettok($line(@@,%a),%b,32) <= $gettok($hget(Darkhash,$address($nick,1)), 2, 32)
{ msg $nick $line(@@,%a) | inc %a | inc %c }
if !%c { echo -a Im sorry, no farms found for you. }
window -c @@
}


else {
msg $nick You dont exist, Please register by downloading Tjirps farm script
}
}

this was all I could make of it. please tell me if im right or wrong and if im wrong what to correct


---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

Code:

on *:TEXT:!getfarm:#:{
  if $hget(darkhash,$nick) { showfarms $nick }
  else { msg $nick You dont exist, Please register by downloading Tjirps farm script }
}
 [color:red]  [/color] 
alias showfarms {
  .remove stats.tmp
  var %number = $gettok($hget(darkhash,$$1),2,32), %nick = $1
  var %a = 1
  while $hget(darkhash,%a).data {
    tokenize 32 $v1
    if $2 &lt; %number { write stats.tmp $hget(darkhash,%a).item is level $1 with Defense $2 }
    inc %a
  }
  filter -fftc 7 32 stats.tmp stats.tmp *
  if !$filtered { .msg %nick Im sorry, no farms found for you. }
  else { .play %nick stats.tmp 1500 }
}

That will do what you want it to do. There are some remarks:

[*] Using people's address to identify them is a bad idea these days, because most will probably have a dynamic address. That means their address will change often, which means the bot won't recognize them anymore. Therefore, I've used the actual nicknames as hash table items. You are of course to do as you please.

[*] After a while your user database will grow, and the ordinary "msg $nick" will be lagging for you and the receiver, and will eventually get you flooded off the server. Therefore I've changed the way of displaying from msging to use the command /play. It will play a text file to a user with a chosen delay. Right now I put the delay at 1500 ms. Change it at will.

[*] Right now I'm writing all the nicks with a score lower than the requester, by using the regular /write command. This works fine, until your userbase will become very big. Then /write will be slower, and can perhaps be replaced with file handling commands like /fwrite etc. This isn't really a problem, but a side-note.

[*] Scores are compared on their defense, like it was in the previous posts (2nd category).

Good luck with your bot,

Greets

Last edited by FiberOPtics; 16/09/04 10:53 PM.

Gone.
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
the script aint working, when I use it when someone types !getfarm it doesnt work, no reply or whatsoever, when I do /showfarm tjirp it says "* /filter: unable to open 'D:\THEMIRC\stats.tmp' (line 14, omg)"


---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Have you read the part where I said I changed the items in the hash table from addresses to nicks?

Also I have made the commands silenced (the messaging) so it's normal you don't see it. Add your clone, for example eendje-x to the hash table, and let him type !getfarm.

It worked when I tested it. I've just retested it, and it works fine.

In channel: <ckaONE> !getfarm
In pm: <FiberOPtics> You dont exist, Please register by downloading Tjirps farm script

Then after adding ckaONE to the hash table with stats 55 789

In channel: <ckaONE> !getfarm
In pm:
<FiberOPtics> item10 is level 21 with Defense 596
<FiberOPtics> item7 is level 63 with Defense 607
<FiberOPtics> item4 is level 23 with Defense 607
<FiberOPtics> item2 is level 40 with Defense 741
<FiberOPtics> Notreg is level 60 with Defense 750

Works fine here :P

Greets

Edit: by any chance, did you copy the code from your email or from the message board? Because, as you can see at the bottom of my former post, I have edited the code shortly after posting. Just in case you didn't know...

Last edited by FiberOPtics; 17/09/04 05:16 PM.

Gone.
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
ok got it sorted now, had to change 1 thing in another script and it works. I cant say anything else then : /me wubs you;P lol:) thanks a lot. I consider this thread for being closed, again thanks a lot


---
signatures own
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
You're welcome, have fun.


Gone.

Link Copied to Clipboard