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 04-01-2010, 02:03 PM
Black_knights55 Black_knights55 is offline
Registered User
Join Date: Jan 2008
Posts: 24
Black_knights55 is on a distinguished road
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!
Reply With Quote
  #2  
Old 04-01-2010, 02:38 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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.
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #3  
Old 04-01-2010, 04:06 PM
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
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.
__________________
Quote:
Reply With Quote
  #4  
Old 04-02-2010, 11:38 PM
Black_knights55 Black_knights55 is offline
Registered User
Join Date: Jan 2008
Posts: 24
Black_knights55 is on a distinguished road
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?
Reply With Quote
  #5  
Old 04-03-2010, 12:06 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
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.
__________________
Quote:
Reply With Quote
  #6  
Old 04-03-2010, 04:25 AM
Black_knights55 Black_knights55 is offline
Registered User
Join Date: Jan 2008
Posts: 24
Black_knights55 is on a distinguished road
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!
Reply With Quote
  #7  
Old 04-04-2010, 01:29 PM
firefighter firefighter is offline
Registered User
Join Date: Jan 2009
Location: Germany
Posts: 70
firefighter is on a distinguished road
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;
  }

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 12:09 PM.


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