Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-02-2008, 02:17 AM
Frankie Frankie is offline
xChugxLifex
Frankie's Avatar
Join Date: Feb 2008
Location: New York
Posts: 1,610
Frankie is a jewel in the roughFrankie is a jewel in the rough
Send a message via AIM to Frankie Send a message via MSN to Frankie
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.
__________________
*Sum41Freeeeek
*Frankie
Reply With Quote
  #2  
Old 05-02-2008, 02:33 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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
__________________

Last edited by Chompy; 05-02-2008 at 07:16 AM..
Reply With Quote
  #3  
Old 05-02-2008, 02:46 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Chompy View Post
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()?
__________________
Reply With Quote
  #4  
Old 05-02-2008, 03:15 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
getstringkeys() will get the variables that start with whatever parameter you provide. getdynamicvarnames() simply gets a list of all dynamic variables.
Reply With Quote
  #5  
Old 05-02-2008, 03:16 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DustyPorViva View Post
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
  
}

__________________
Reply With Quote
  #6  
Old 05-02-2008, 03:33 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
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
__________________
Reply With Quote
  #7  
Old 05-02-2008, 04:15 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
I have a question, why was it deleted in the first place, Frankie? o_o
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #8  
Old 05-02-2008, 04:20 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Tigairius View Post
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"
__________________
Reply With Quote
  #9  
Old 05-02-2008, 06:55 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
this.blah.foo.bar

getstringkeys("this.blah") would give you "foo.bar" while this.blah.getdynamicvarnames() would give you just "foo".
__________________
Do it with a DON!
Reply With Quote
  #10  
Old 05-02-2008, 07:19 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by zokemon View Post
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
__________________
Reply With Quote
  #11  
Old 05-02-2008, 09:06 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Chompy View Post
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.
__________________
Do it with a DON!
Reply With Quote
  #12  
Old 05-02-2008, 09:30 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by zokemon View Post
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
__________________
Reply With Quote
  #13  
Old 05-02-2008, 07:06 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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]);


Last edited by [email protected]; 05-02-2008 at 07:36 PM..
Reply With Quote
  #14  
Old 05-08-2008, 01:35 AM
Frankie Frankie is offline
xChugxLifex
Frankie's Avatar
Join Date: Feb 2008
Location: New York
Posts: 1,610
Frankie is a jewel in the roughFrankie is a jewel in the rough
Send a message via AIM to Frankie Send a message via MSN to Frankie
thank you.
"sidney" yours works well.
__________________
*Sum41Freeeeek
*Frankie
Reply With Quote
  #15  
Old 05-15-2008, 08:15 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
it's not a problem he he
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:36 AM.


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