Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-07-2010, 06:49 PM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Kind of rusty. =/

Okay, so I haven't scripted in a bit, trying to get back into the groove somewhat, so I've decided to pick back up on some old scripting projects, but alas! I have run into problems, of course. So, I have a question about a issue at hand, and I also have a question in regards to something I want to do in the future.

Okay so, first thing: (Nevermind I figured this part out, but help with the second question would be appreciated.)

And secondly: I was wondering, how exactly would I go about checking through ALL the flags in a DB and see if they match to a specific sent array? Eg:

DBNpc - Test_Stats: Holds flags - this.test_1 = {1, 2, 3}; and this.test_2 = {3, 4, 5};

Now, say in a weapon NPC I have a weapon creating arrays: this.check_1 = {2, 3, 4}; and this.check_2 = {3, 4, 5}; and I want to send them both to the Test_Stats NPC to check if they match up to any flags that are stored within that DB. (Of course when actually made this flag list will be much more extensive.) How exactly would I go about checking all of those flags and seeing if they match up, so that I could than return whether they match up or not?
Reply With Quote
  #2  
Old 12-07-2010, 07:20 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
hmm you could do something like

(inside test_stats)

HTML Code:
public function onCheckArray(arr) {
  for (temp.i: getstringkeys("this.")) {
    if ((@ this.(@ temp.i)) == (@ temp.arr)) return true;
  }
  return false;
}
then again- what're you trying to do though? (what kind of system)
__________________
Reply With Quote
  #3  
Old 12-07-2010, 07:30 PM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
I basically want to create an Alchemy system with a bunch of different formulas for items. Like: this.weapon_1 = "Iron, quantity", "Stock, quantity", etc" would be in the DB, along with a bunch of others. Than in a weapon NPC I would be creating the array based on what items the player is trying to put together, and when they try to create something it would run a check through the DB to see if it matches any formula in the DB.
Reply With Quote
  #4  
Old 12-07-2010, 07:49 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
ah hmm you don't wanna do a quantity/stock in a flag to cross reference =p

If I were you, I would make a script which would automatically generate a bunch of items from a list of vars, and then have the ID different to each one
something similar to this:

http://forums.graalonline.com/forums...ad.php?t=78506

As an example, I would name an item something like

Pirates_Flare_Blade_of_Darkness
Rogues_Spider_Fang_of_Nature

Then base your items around there. I would automatically have each item type defined =[
You can also make your own weapons, if you want personal items.
__________________
Reply With Quote
  #5  
Old 12-07-2010, 07:55 PM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Quote:
Originally Posted by xAndrewx View Post
ah hmm you don't wanna do a quantity/stock in a flag to cross reference =p

If I were you, I would make a script which would automatically generate a bunch of items from a list of vars, and then have the ID different to each one
something similar to this:

http://forums.graalonline.com/forums...ad.php?t=78506

As an example, I would name an item something like

Pirates_Flare_Blade_of_Darkness
Rogues_Spider_Fang_of_Nature

Then base your items around there. I would automatically have each item type defined =[
You can also make your own weapons, if you want personal items.
Why not? I've done a name/quantity check already with my inventory and it works perfectly fine. o.O And in regards to that thread, I dunno.. I'm not that advanced of a scripter, I can barely even understand Chompy's scripts. XD I wanna do it this way because it's probably the only way I'll understand it atm, and it's easiest for me to manage.
Reply With Quote
  #6  
Old 12-07-2010, 07:56 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Sage_Shadowbane View Post
Why not? I've done a name/quantity check already with my inventory and it works perfectly fine. o.O And in regards to that thread, I dunno.. I'm not that advanced of a scripter, I can barely even understand Chompy's scripts. XD I wanna do it this way because it's probably the only way I'll understand it atm, and it's easiest for me to manage.
Are you checking the players quantity with the Database? o-o
__________________
Reply With Quote
  #7  
Old 12-07-2010, 08:03 PM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Quote:
Originally Posted by xAndrewx View Post
Are you checking the players quantity with the Database? o-o
I'm checking for the name AND quantity, and through checking the name, I can also retrieve the stats of that item.
Reply With Quote
  #8  
Old 12-07-2010, 08:09 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
hmm why the quantity in the DB? bad move =[
__________________
Reply With Quote
  #9  
Old 12-07-2010, 08:11 PM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Why not? lol It's not like anyone can hack a DB and no staff will be able to give theirselves items unless I give them the access to alter the flags.
Reply With Quote
  #10  
Old 12-07-2010, 08:20 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by Sage_Shadowbane View Post
Why not? lol It's not like anyone can hack a DB and no staff will be able to give theirselves items unless I give them the access to alter the flags.
Which a scripter could do.
Reply With Quote
  #11  
Old 12-07-2010, 08:21 PM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Quote:
Originally Posted by Cubical View Post
Which a scripter could do.
Which is why I'm the only scripter + I don't mess with people I don't know or with people who are untrustworthy. -_- And either way, I'm just asking if anyone can help me on how to do what I was asking, not to be judged on how I'm scripting things. I'd rather that I make errors when scripting, that way I know better next time around.
Reply With Quote
  #12  
Old 12-11-2010, 01:20 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Okay so Drew, what you showed me worked, but now I've run into another issue with this. The function only returns when the array is an exact match to the flag in the DB. (Which it should) But is there a way I can make it so that it will return when the array is in any order? Eg:

this.array = {2, 3, 1}; //In Weapon
this.return_array = {1, 2, 3}; //In NPC

When I send this.array to the NPC, I would still like to return this.return_array, even though the numbers are off in sequence, they are still the same numbers.
Reply With Quote
  #13  
Old 12-11-2010, 02:05 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
I would really recommend a new system, you could do something like

HTML Code:
public function onCheckArray(arr) {
  for (temp.i: getstringkeys("this.")) {
    if ((@ this.(@ temp.i)) == (@ temp.arr)) return true;
    if (temp.arr.size() == this.(@ temp.i).size()) {
      temp.check = 0;
      for (temp.f: temp.arr) {
        if (temp.f in this.(@ temp.i)) temp.check++;
      }
      if (temp.check == temp.arr.size()) return true;
    } 
  }
  return false;
}
__________________
Reply With Quote
  #14  
Old 12-11-2010, 03:00 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
I would really recommend a new system, you could do something like

HTML Code:
public function onCheckArray(arr) {
  for (temp.i: getstringkeys("this.")) {
    if ((@ this.(@ temp.i)) == (@ temp.arr)) return true;
    if (temp.arr.size() == this.(@ temp.i).size()) {
      temp.check = 0;
      for (temp.f: temp.arr) {
        if (temp.f in this.(@ temp.i)) temp.check++;
      }
      if (temp.check == temp.arr.size()) return true;
    } 
  }
  return false;
}
That would require relying on a "hack" function retrieving like that could become problematic.

1. Store each recipe id in an array. (this.recipes = {})
2. Store recipe information in it's own variable. (this.recipe.(@id) = {"name", {"ingredient", 1, "other", 1}})
3. Cycle through each recipe and provided ingredients until a match is found.

Rough implementation:

Graal Script Code:
function getResult(ingredients) {
  
temp.found "";
  for (
temp.recipethis.recipes) {
    
temp.requires getRequirements(temp.recipe);
    for (
temp.0temp.ingredients.size() && ; temp.+= 2) {
      
temp.item ingredients[temp.i];
      
temp.qty ingredients[temp.i+1];
      
// Matching requirements
      
temp.ind temp.requires.index(temp.item);
      if (
temp.item in temp.requires && temp.qty >= temp.requires[temp.ind+1]) {
        
// Matching ingredient
      
}
    }
    if (
temp.found) break;
  }
  return 
temp.found;
}

function 
getResult(recipeid) {
  return 
this.recipe.(@recipeid)[0];
}

funciton getRequirements(recipeid) {
  return 
this.recipe.(@recipeid)[1];

__________________
Quote:
Reply With Quote
  #15  
Old 12-11-2010, 03:54 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
hmm how so @ my script
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:19 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.