RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Item Instances Base

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Item Instances Base
Version: 1.0
Author: modern algebra
Date: August 7, 2011

Version History


  • <Version 1.0> 2011.08.07 - Original Release

Description


This is a scripting tool that changes the way items are handled in the game to allow for item instances. This means that items specially marked will be uniquely saved every time you collect them.

This script was designed since scripts which require items to be saved as instances, even if they were conceptually simple (like durability), were impractical to make since they required a heavy overhaul of the entire item system. The only other scripts I know about that have tried tend to be very bulky and usually incompatible with every other item-based script out there. This script was therefore designed to (a) change the way marked items were saved so as to be more dynamic and saved as instances; (b) be compatible or easily made compatible with most other scripts that deal with items; and (c) be easy to create addons which make use of the framework to create functional changes to items, weapons, and armors.

This script makes little functional difference aside from changing how marked items are stacked in the menu and allows you to change the specific stats of items if you add them through the Change Item/Weapon/Armor event commands by using a comment. However, it provides a necessary structure for other scripts, such as a weapon durability or charges script, where the stats necessarily must vary between items of the same type.

While I made this script to provide a base for a series of scripts I will make, any scripter is welcome to use this as a base for their own scripts.

Features

  • Allows you to mark some items to be saved individually, thus allowing you to modify their stats without changing the stats of every other instance of the item
  • Highly compatible by retaining much of the same basic structure as default. Where there will still be some incompatibilities, it is designed to be easy to make a compatibility patch for
  • Unlike other similar scripts, separating the base from the scripts that utilize it allows users to only grab the scripts they want to use and not have it come in a huge bundle

Screenshots


Though the same item, they are saved individually. The stats are different in this
case because I am using the Random Stat Variance for Items script.

Instructions

This script must be placed above Main and BELOW every regular custom script that might deal with items, even if they do so only incidentally.

However, it must be ABOVE any scripts that directly utilize this framework (see the "Derivative Scripts" list).

See the Header for more detailed instructions on utilization.

Guidelines

If you are a scripter and want to use this as a base for a script, you should familiarize yourself with it fully. However, here are a few little (non-exhaustive) guidelines/tips:
  • To check if a particular item creates instances, you can use the code: item.instance_based?
  • If you are adding a notebox code, you can add the RegExp to the RPG::BaseItem::MA_INSTANCE_CHECKS constant and it will interpret any item with that code as instance based and treat it accordingly. Otherwise, you would need to manually alias the instance_based? method or else require  the use of the generic \Instance code.
  • You can get the ID of the base item from an instance item by asking for the item_id attribute, while the id attribute will return the unique index of the instance item. If you ever need the id method to return the base's item ID instead of its unique ID, then you turn the get_item_id attribute to true and it will. This is useful especially for aliasing.
  • If you want instance items to be destroyed when they are lost (which you should do if the player will never have a chance to recover them), you can set $game_party.ii_destroy_lost_instances to true.
  • To create a new instance without going through the gain_item method, you use the code data.create_instance (base_item), where data is either $data_items, $data_weapons, or $data_armors and base_item is an RPG::Item/Weapon/Armor object. To destroy an instance, you use data.destroy_instance (index) where data is the same and index is the item's unique ID.
  • You can retrieve all the existing instance items with a base ID by the code: data.items_with_id (x) where x is the ID in question. For instance, if you want to get all instances of the long sword (ID 2), you'd ask for $data_weapons.items_with_id (2). Note that it will return ALL instance items with that ID and not only those held by the party. For instance, it will also give you them even if they are currently equipped.
  • $data_items, $data_weapons, & $data_armors are all still the arrays they used to be, only with the [] and []= methods altered for instance item support. As such, any array methods will work exactly as they used to - So, for instance, if you do $data_items.each {} then you will cycle through only the base items and not the instance items.
  • The code $game_party.newest_instance_items will return an array of all the latest items the party has received through the gain_item command.

Script


The script is too long. Get it at Pastebin

Derivative Scripts

The following is a list of scripts (existing and planned) that use this script as a base:

Credit


  • modern algebra

Support


Please post in this topic if you encounter any compatibility issues at all - I would love to know about them and fix them for you.

Known Compatibility Issues

This script must be placed above Main and below EVERY custom script that deals with items, weapons, or armors, even if they do so in a merely incidental way.

Though I tried to make this script highly compatible, I am extremely fallible and it will still be incompatible with some scripts. If you find such an incompatibility, alert me to it and I will quickly correct it.

Demo


I will eventually make a demo and will update it every time I make a new script that uses it. For now, since it makes no significant functional difference, there is no demo.

Author's Notes


This is a scripting utility I designed mostly for myself as I plan to make a series of scripts that require items to be saved as instances, such as item durability, poisoning and socketing weapons, unidentified artifacts, etc...

I experimented a little with this script, and I invite comments from other scripters on how I could improve it, particularly with an eye to anticipated incompatibilities.
« Last Edit: August 15, 2011, 06:53:27 PM by modern algebra »

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
I almost posted a script idea for this about weapons being able to have attribute ranges that were set at the creation of the weapon, but it seems you already made it.

Aside from that, this is a pretty good idea and should help in the creation of a lot of scripts.

I'll use it with a personal project to report any bugs or suggestions.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Wow, this is amazing MA! I can think of so many ways to implement this (although you stole most of my ideas already >:() Needless to say, this is a great script and good luck with you scripting series endeavours!

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Thanks! I'm glad you guys like it. I look forward to hearing any feedback you might have TDS.

Also, @cozzie, the only ones I've started working on so far are Durability and Unidentified Artifacts - you are welcome to work on any others. I will be rewriting my evidence script as a Dialog though, which will allow it to be called and an item picked without interrupting the scene processing. It will be helpful for the ones where you apply something to an item, so you might want to wait to do those, but I would love to see other scripters work with this script and tell me how I could improve it and make it more accessible.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Hmm.. This is probably a dumb question because I haven't played around with this as much as I should have, but how can I convert an RPG::Item to a Game_Item? Or can I get the RPG::Item from the Game_Item?




*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
You can create it with the code:

Code: [Select]
$data_items.create_instance (item)

where item is an RPG::Item.

From a Game_Item instance, you can retrieve the RPG::Item it was derived from with the code:

Code: [Select]
item.base_item
where item is a Game_Item. Alternatively, you could retrieve it with:

Code: [Select]
$data_items[item.item_id]
where item is either a Game_Item or an RPG::Item (though if it were an RPG::Item, it would be pointless since you already have it).

*
Rep: +0/-0Level 49
RMRK Junior
I know this is necro, but have there been any updates to this script?

I put this script into an empty project by itself and get an expecting } error at line 566

 nil_ary = self.instance_methods.select { |method| !method.include?  ("=") && self.instance_methods.include? ("#{method}=") }


nevermind.  I was looking at the wrong date.  I thought this was a year newer lol
even more necro than I thought.  must be an xp script an an ace noob trying to use it.

pay no attention to the man behind the /facepalm
« Last Edit: January 21, 2013, 05:35:47 AM by jargonchipmunk »

**
Rep: +0/-0Level 83
 :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog: :sdog:

so i decided to revive this topic in hopes of getting people to talk about this again. it seems that this script was so powerful that whatever i want with my item/weapon/armor now is possible. stuff like assigning a single slot for my 100+ variation of potions seems very smart as it would have taken alot of slot for my database thus making the game load a tinny bit slower. modern A dude, your really the best scripter ever. even in RRR, or rpgmakervx.net your the bomb. and now that i have returned in the rpg maker vx scene i might as well be active now.

EDIT
I forgot to add this yesterday and i was gonna keep this alive anyways so i just want to know how do i recreate the same instance so it stacks with its kind. see i tried to power-up the KGC Compose Item script so it uses Item Instance in a way that when the player creates a potion and his/her skill is only at novice, his potion will only heal 20 HP. but at Apprentice level, with the same ingredients, it will heal 100 HP. it works how i want it but every time i make the same thing, it doesnt stack with its kind. this will cause ALOT of the same item in the players inventory to stay and just clutter up the inventory menu which isnt a good sign of good programming. [*cough*]EA[*cough*]... so how do i stack the same instance?

EDIT EDIT:
well crap. as a programmer there is nothing more annoying than hitting a bump. a bump called a bug. yeah~~~~~. so i was happily using this and Omega Equipment Customization Script OECS. seems like they hate each other. could be because OECS clones equipment as well. bummer though. with my minimalistic skills and lack of perception on how OECS is made i cant fix it but im doing this edit so as to say "Let it be known" thing.
« Last Edit: July 31, 2015, 03:39:10 PM by fatapi_shadramon »

**
Rep: +0/-0Level 83
Just gonna bump this post so it remains relevant. this scripts need more love.