Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   can someone tell me how to do this? (https://forums.graalonline.com/forums/showthread.php?t=79590)

Frankie 05-02-2008 02:17 AM

can someone tell me how to do this?
 
okay:

we have a database that stores all bank accounts and the money in them.
I want to make something so I can loop through the flags in the database and get all ones that are greater than a certain amount.

for example

if I said /npc checkbanks 500000
it would tell me all the accounts in the database that had 500,000 or more.

tig did it for us a while ago so I know it's possible. I just don't know how to approach this.

I can do the obvious:
for (pl: allplayers)
{
echo(pl SPC "has" SPC DB_Bank.("acc_" @ pl)[0]);
}

but that would only give me the ones that are online. I need to see offline ones too.

Chompy 05-02-2008 02:33 AM

PHP Code:

function onCreated() {
  
with(findnpc("DB_Bank")) {
    for(
temp.pl getstringkeys("this.acc_")) {
      
temp.makevar("this.acc_" pl);

      echo(
"Player "pl @" has "a[0] @" money!");
    }
  }


This should echo all the players and what they have in rc (Those who have a this.acc_<account> variable in the database)

Now, how can we use this to find for example, those who have more then 50,000?

PHP Code:

function onCreated() {
  
temp.check 50000// What to check for
  
temp.0;

  
with(findnpc("DB_Bank")) {
    for(
temp.pl this.getstringkeys("this.acc_")) {
      
temp.makevar("this.acc_"pl);
      if (
a[0] >= check) {
        
p.add(pl);
      }
    }
  }
  
/*
    All the players who have 50,000 or more would be listed in the
    array 'p'
  */


Hope this helps :)

PS: I made these scripts on the go, so I don't know if they work properly or not

cbk1994 05-02-2008 02:46 AM

Quote:

Originally Posted by Chompy (Post 1388550)
PHP Code:

function onCreated() {
  
with(findnpc("DB_Bank")) {
    for(
temp.pl this.getstringkeys("this.acc_")) {
      
temp.makevar("this.acc_" pl);

      echo(
"Player "pl @" has "a[0] @" money!");
    }
  }


This should echo all the players and what they have in rc (Those who have a this.acc_<account> variable in the database)

Now, how can we use this to find for example, those who have more then 50,000?

PHP Code:

function onCreated() {
  
temp.check 50000// What to check for
  
temp.0;

  
with(findnpc("DB_Bank")) {
    for(
temp.pl this.getstringkeys("this.acc_")) {
      
temp.makevar("this.acc_"pl);
      if (
a[0] >= check) {
        
p.add(pl);
      }
    }
  }
  
/*
    All the players who have 50,000 or more would be listed in the
    array 'p'
  */


Hope this helps :)

PS: I made these scripts on the go, so I don't know if they work properly or not

Those look like how I'd do it, though what's the difference between getstringkeys() and getdynamicvarnames()?

DustyPorViva 05-02-2008 03:15 AM

getstringkeys() will get the variables that start with whatever parameter you provide. getdynamicvarnames() simply gets a list of all dynamic variables.

cbk1994 05-02-2008 03:16 AM

Quote:

Originally Posted by DustyPorViva (Post 1388579)
getstringkeys() will get the variables that start with whatever parameter you provide. getdynamicvarnames() simply gets a list of all dynamic variables.

Oh, okay. I would have gone like this:

PHP Code:

temp.blah.getdynamicvarnames();
for ( 
temp.foo temp.)
{
  if ( 
temp.foo.starts"LOL" ) )
  {
    
//whatev
  
}



Chompy 05-02-2008 03:33 AM

Quote:

Originally Posted by cbkbud (Post 1388583)
Oh, okay. I would have gone like this:

PHP Code:

temp.blah.getdynamicvarnames();
for ( 
temp.foo temp.)
{
  if ( 
temp.foo.starts"LOL" ) )
  {
    
//whatev
  
}



A loop using getstringkeys() will run less then using getdynamicvarnames() since you specify the prefix to look for, instead of checking every member of getdynamicvarnames() if they start with the prefix :p

Tigairius 05-02-2008 04:15 AM

I have a question, why was it deleted in the first place, Frankie? o_o

cbk1994 05-02-2008 04:20 AM

Quote:

Originally Posted by Tigairius (Post 1388594)
I have a question, why was it deleted in the first place, Frankie? o_o

It wasn't; this is just a drill ;)

Just like when we were outside for 5 hours at school today for a bomb threat, and they were like "LOL IT WAS JUST DRILL .. DONT MIND HAZMAT, BOMB SQUAD, FIRE TRUCKS ETC"

zokemon 05-02-2008 06:55 AM

this.blah.foo.bar

getstringkeys("this.blah") would give you "foo.bar" while this.blah.getdynamicvarnames() would give you just "foo".

Chompy 05-02-2008 07:19 AM

Quote:

Originally Posted by zokemon (Post 1388611)
this.blah.foo.bar

getstringkeys("this.blah") would give you "foo.bar" while this.blah.getdynamicvarnames() would give you just "foo".

Actually, getstringkeys("this.blah") would give you "" and doing getstringkeys("this.blah.") would give you "foo" ;o

zokemon 05-02-2008 09:06 AM

Quote:

Originally Posted by Chompy (Post 1388613)
Actually, getstringkeys("this.blah") would give you "" and doing getstringkeys("this.blah.") would give you "foo" ;o

Ehh? getstringkeys gives you the var names starting with the parameter, at least last I checked I'm pretty sure it did. I may be going off what I read on these forums though; I often get what I've done my self and what I read mixed up :P.

Chompy 05-02-2008 09:30 AM

Quote:

Originally Posted by zokemon (Post 1388622)
Ehh? getstringkeys gives you the var names starting with the parameter, at least last I checked I'm pretty sure it did. I may be going off what I read on these forums though; I often get what I've done my self and what I read mixed up :P.

I tested it before I posted that post, so I dunno :o

[email protected] 05-02-2008 07:06 PM

didn't i do this for era like three years ago?
anyway, here's a better script probably. change the loop at the bottom and it'll give you the top richest players etc

PHP Code:

function onCreated() {
  for (
temp.igetstringkeys("this.acc_")) 
    
temp.accs.add({ithis.("acc_" i)[0]});
    
  for (
iaccs) {
    
temp.e.add(i[0]);
    
temp.e[temp.c].sortvalue i[1];
    
temp.c++;
  }
  
e.sortbyvalue("sortvalue""float"false);
  
  echo(
"Richest 5 Players:");
  for (
05i++) 
    echo(
e[i] @ ":-" SPC this.("acc_" e[i])[0]);



Frankie 05-08-2008 01:35 AM

thank you.
"sidney" yours works well. :D

[email protected] 05-15-2008 08:15 PM

it's not a problem he he :):):)


All times are GMT +2. The time now is 08:15 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.