Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Learning: "How to store items" (https://forums.graalonline.com/forums/showthread.php?t=134258607)

Black_knights55 04-01-2010 02:03 PM

Learning: "How to store items"
 
Hey,
I was trying to script some "materials" for a crafting system and I have no idea how I could "store" them in the player. Do I have to use clientr. or should I use something else since I would like to have lots of differents "materials" ? I want them to store the "type" (minerals, ingots, logs, etc), the "name" (iron, silver' gold, etc), the "images.png" of the material and the quantity.

Is there a way to put all that in a single clientr. and how can I access the quantity or any other variable with another script? Or is there something else better than clientr. ? Or maybe just a better suggestion how to do it?

Thank you!

Liberated 04-01-2010 02:38 PM

Most people use weapons joined to classes and the Mudlib route, i've never used this myself tho, so im not sure how it works.

fowlplay4 04-01-2010 04:06 PM

At the most basic level you could use something like this:

clientr.item.(@itemname) = {type, quantity};

or..

clientr.item.(@type).(@itemname) = quantity;

For easier implementation you'll want to make a class called itemfunctions and join it to the player when they login using a line like this:

player.join("itemfunctions");

Then in your itemfunctions class you could have public functions like addItem, takeItem, hasItem that you could use in your actual code, on the serverside to call those functions you would simply use:

player.addItem("Rocks", 999);

Of course the actual parameters would be different depending on the system but that's the basic gist of it.

Black_knights55 04-02-2010 11:38 PM

Will the use of many clientr.tag create some kind of lag or is it ok to use lots of them?
And if I use this example:
clientr.item.(@itemname) = {type, quantity};

How do I change only the quantity? I'm not sure how that way works at all.

And, can I just create a weapon, lets say a "mining bag" and then just create some this.iron_ore=quantity, this.silver_ore, etc? And if it's possible, I would be able to find those variables with findweapon("mining bag").iron_ore or something like that, right?

fowlplay4 04-03-2010 12:06 AM

Well Zodiac currently uses that kind of system to hold items, nor do we impose any kind of bag limit.

You can add to the quantity like this:

clientr.item.(@itemname)[1] += addQuantity;

Also your Mining bag idea won't work properly on the server-side and will be incredibly insecure on the client-side.

Black_knights55 04-03-2010 04:25 AM

So, if I understand everything. If I want to add an item I would do something like this:

clientr.item.ore.iron += 1

Type = Ore
Itemname = Iron

So it's as simple as that? I was sure it would be more complicated lol. Thanks for your help!

firefighter 04-04-2010 01:29 PM

We on Zenox are storing the items in a SQLite database;)

PHP Code:

public function IncPlayerItemCount(placcitemcount) {
  if (
ItemExists(item)) {
    
temp.ct int(count);
    if (
temp.ct 0) {
      
CreatePlayerItemIfNotExists(placcitem);
      
temp.req GetSQL("UPDATE ItemDB_PlayerItems SET count=count+"@temp.ct@" WHERE player=(SELECT ID FROM Players WHERE Account='"@SQLEscape(placc)@"') AND item=(SELECT ID FROM ItemDB_Items WHERE name='"@SQLEscape(item)@"')",false);
      if (
temp.req!=null && temp.req.error=="")
        return 
true;
      else {
        echo(
"ItemDB: Inc item count '"@item@"' of player "@placc@" failed - SQL query error");
        return 
false;
      }
    } else {
      echo(
"ItemDB: Inc item count '"@item@"' of player "@placc@" failed - count smaller than 0 or 0");
      return 
false;
    }
  } else {
    echo(
"ItemDB: Inc item count '"@item@"' of player "@placc@" failed - item doesnt exist");
    return 
false;
  }




All times are GMT +2. The time now is 10:43 PM.

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