Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Creating Stackable Items? (https://forums.graalonline.com/forums/showthread.php?t=134258399)

Cubical 03-15-2010 01:19 PM

Creating Stackable Items?
 
What would be the best way to create stackable items while still having different ID numbers on the items? I can't seem to figure out a way to do this, any ideas? Should I stack by name? I'm not really worried so much about weapons but things like lets say arrows, bullets, or whatever else that is stackable that you can't just put 1 in each inventory slot. I'm sure there is a way to do it, I'm just clueless on how. I haven't started scripting anything yet because I wanted to get all the details first so I don't get stuck half way through and have to start over. I'm currently just making something simple with no real purpose to learn from and expand on until I feel comfortable enough to do something for real. Any ideas on what the most efficient way would be to solve this?

Edit: Corrected some of my wording.

Cubical 03-15-2010 02:34 PM

I have thought about doing this, something like
NPC Code:

clientr.item_241234412414 = type,name,quanity, then whatever else;


241234412414 being the ID.

The only problem I see with doing it like that is if someone picks up more of an item they already have with a different ID how could I get it to stack?

DrakilorP2P 03-15-2010 02:54 PM

Why have a different ID for all items when you could just store type and quantity like normal people?

Cubical 03-15-2010 03:02 PM

Oh O figured having unique ID's prevented duping, I guess I could just check the quantity of the item before dropping and such. From what I have seen a lot of people use ID's for items. If they can just check to see the quantity why do servers make ID's for items?

DrakilorP2P 03-15-2010 03:18 PM

Quote:

Originally Posted by Cubical (Post 1562715)
Oh O figured having unique ID's prevented duping, I guess I could just check the quantity of the item before dropping and such. From what I have seen a lot of people use ID's for items. If they can just check to see the quantity why do servers make ID's for items?

I dunno, but Maloria did it to support custom weapons that you didn't have to create a new archetype for. It was very complicated and in the end the feature was never used.

Cubical 03-15-2010 03:30 PM

so doing something like clientr.item.itemname = itemtype, quantity would be fine?

edit: also is it better to load all the item information for an item on login or as the player needs it?

DrakilorP2P 03-15-2010 03:39 PM

Quote:

Originally Posted by Cubical (Post 1562719)
so doing something like clientr.item.itemname = itemtype, quantity would be fine?

Or possibly clientr.item.itemtype = quantity, but yeah.

Quote:

Originally Posted by Cubical (Post 1562719)
edit: also is it better to load all the item information for an item on login or as the player needs it?

If you're going to have lots of items it's better to grab them as needed, but if you only have a few right now it's easier to load on login.
Just make sure if you change it later that it won't break scripts that assume that all items are already loaded.

fowlplay4 03-15-2010 03:50 PM

On Zodiac V2, I use a variable in my arcs called stackable as well as stack size.

If it's stackable, look for an empty stack based on the archetype and add to it taking into account max stack size, and creating a new stack if necessary.

Cubical 03-15-2010 03:57 PM

@mallard: I'll probably just do it when needed if it's not really that big of a deal. Thanks for the help.


Quote:

Originally Posted by fowlplay4 (Post 1562722)
On Zodiac V2, I use a variable in my arcs called stackable as well as stack size.

If it's stackable, look for an empty stack based on the archetype and add to it taking into account max stack size, and creating a new stack if necessary.

That's a good idea.

fowlplay4 03-15-2010 04:00 PM

But it's kind of useless doing stacks if you don't implement a items held / bag restriction so that should be something else to consider before bothering with it.

Cubical 03-15-2010 04:06 PM

Well, it could also be used to limit the amount of 1 item you can have couldn't it? like say you can have a maximum of 20 potions or something you could set the max stack. Also I had planned implementing a maximum amount of items held.

fowlplay4 03-15-2010 04:37 PM

Yeah it could, so yeah you'll be fine :)

Cubical 03-15-2010 04:51 PM

Alright, thanks to both of you.

Cubical 03-15-2010 06:38 PM

Could someone tell me which one of these is right, or if both of them are wrong?

NPC Code:

("clientr.type." @ itemrealname)[2] + quanity;



NPC Code:

("clientr.type." @ itemrealname[2]) + quanity;


salesman 03-15-2010 06:59 PM

Quote:

Originally Posted by Cubical (Post 1562747)
Could someone tell me which one of these is right, or if both of them are wrong?

NPC Code:

("clientr.type." @ itemrealname)[2] + quanity;



NPC Code:

("clientr.type." @ itemrealname[2]) + quanity;


First of all, I wouldn't use type because it may be reserved. I'd use something like itemtype instead.

If the player you want to manipulate has focus you would do something like this:

PHP Code:

clientr.(@ itemtype).(@ itemrealname)[2] += quantity;
// assuming your setup is something like
// clientr.grenade.flashbang = {some_var, some_var, QUANTITY, etc}
// or clientr.gun.famas = {some_var, some_var, QUANTITY, etc}

//Remember:
temp.foo += 2
//is a shorter way of doing
temp.foo temp.foo 2

You should also be very careful when dealing with important things like items that all of your data is verified on the serverside. How are you getting "quantity"? Trust nothing from the client because it can always be changed if the person knows what they're doing.

edit:
Ideally it would probably be better to have the itemtype in the array, and have clientr.items.itemname = {itemtype, etc, etc};
That way, you can easily get all of the players items doing something like temp.items = clientr.items.getDynamicVarNames();

I have to go to class, hope this helped.

Cubical 03-15-2010 07:17 PM

Oh that was a typo, it was itemtype but i changed it to this clientr.item.(@ itemrealname) right after I posted because I thought of what you just mentioned. Also everything is currently serverside and everything is loading from an array.


All times are GMT +2. The time now is 05:19 PM.

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