Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Kind of rusty. =/ (https://forums.graalonline.com/forums/showthread.php?t=134261259)

Sage_Shadowbane 12-07-2010 06:49 PM

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.) :asleep:

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? :noob:

xAndrewx 12-07-2010 07:20 PM

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)

Sage_Shadowbane 12-07-2010 07:30 PM

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.

xAndrewx 12-07-2010 07:49 PM

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.

Sage_Shadowbane 12-07-2010 07:55 PM

Quote:

Originally Posted by xAndrewx (Post 1615303)
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. x_x

xAndrewx 12-07-2010 07:56 PM

Quote:

Originally Posted by Sage_Shadowbane (Post 1615305)
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. x_x

Are you checking the players quantity with the Database? o-o

Sage_Shadowbane 12-07-2010 08:03 PM

Quote:

Originally Posted by xAndrewx (Post 1615306)
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. :confused:

xAndrewx 12-07-2010 08:09 PM

hmm why the quantity in the DB? bad move =[

Sage_Shadowbane 12-07-2010 08:11 PM

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. :confused:

Cubical 12-07-2010 08:20 PM

Quote:

Originally Posted by Sage_Shadowbane (Post 1615310)
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. :confused:

Which a scripter could do.

Sage_Shadowbane 12-07-2010 08:21 PM

Quote:

Originally Posted by Cubical (Post 1615311)
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.

DeCeaseD 12-11-2010 01:20 AM

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.

xAndrewx 12-11-2010 02:05 AM

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;
}


fowlplay4 12-11-2010 03:00 AM

Quote:

Originally Posted by xAndrewx (Post 1615770)
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:

PHP 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];



xAndrewx 12-11-2010 03:54 AM

hmm how so @ my script


All times are GMT +2. The time now is 06:22 AM.

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