Jump to content

Recommended Posts

instanceitems11.jpg?w=640

 

This script introduces the concept of “instance itemsâ€. In order to understand what an instance item is, you need to first understand what a “template item†is.

 

All of your database items, weapons, and armors are called “template itemsâ€.

That is, they serve as templates for in-game items.

 

An instance item is simply an instance of a template. For example, you design weapon ID 1 in your database and call it a “Short Swordâ€. This is a template of a Short Sword; everytime you receive a Short Sword in-game, you receive a unique “instance†of this template. Two Short Swords in your inventory are treated as two individual entities that have nothing to do with each other besides both being based on the Short Sword template.

 

It is important to note that this script simply provides instance item functionality. Additional add-ons are required to provide various features such as equip levels, equip affixes, and so on.

 

Get it at Hime Works!

Edited by Tsukihime

Share this post


Link to post
Share on other sites
The script crashes when you create a new weapon, newly added to weapon database file. The instance script doesn't seems to be able to handle newly created items.

 

Also, it basically duplicate one item into two. One is the original, one is the instance item. I think you should add a method to remove the original item and keep the instance item.

 

Thanks!!

Share this post


Link to post
Share on other sites

when i create for example a chest, with one sword inside, and I opened it, the game give me two swords xD

But after that, I think this script is better than the script by Formar, because the compatibility with other scripts is better

Edited by ShidoLionheart

Share this post


Link to post
Share on other sites

I will not provide compatibility with fomar's individual equips, because this script is supposed to provide that functionality.

 

The script crashes when you create a new weapon, newly added to weapon database file. The instance script doesn't seems to be able to handle newly created items.

You will have to explain what it means to "create a new weapon".

 

Also, it basically duplicate one item into two. One is the original, one is the instance item. I think you should add a method to remove the original item and keep the instance item.

This is what the script does: suppose you receive a hand ax.

 

1. It increases your hand ax template count by 1

2. It creates a hand ax instance, and increases that count by 1.

 

This is used for counting purposes. If you ask "how many hand axes do I have?" I just need to look up the template count and tell you how many hand ax instances you have.

 

Your inventory will only contain instances. There are likely compatibility issues if you are seeing both the template hand ax as well as the instance hand ax.

 

when i create for example a chest, with one sword inside, and I opened it, the game give me two swords xD

But after that, I think this script is better than the script by Formar, because the compatibility with other scripts is better

I am unable to duplicate the problem.

 

I have a chest that gives me one hand ax.

My inventory is initially empty.

When I open the chest and check my inventory, I have one hand ax.

 

Check if this occurs in a new project, and whether it is a compatibility issue.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Understood.

The Popup script "popups" two sword, but in the inventory there is only one. So it's a compatibility issue, sorry ^^

The popup script is functionally correctly. It's because I actually add two items to the inventory, except one of them is used internally and is never seen by the player.

 

For example, you have the following items in your inventory

 

Hand Ax lv 1
Hand Ax lv 2
Hand Ax lv 3
How many hand axes do you have? You have 3? Or do you have 1? Or zero?

 

A compatibility patch will be required for the popup script to distinguish between instances and templates.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

I don't get why for your instance item script: 

line 500 and 501:

            th_instance_items_gain_item(new_item, 1, include_equip)
            th_instance_items_gain_item(item_template, 1, include_equip)
 
Why keeping a copy of template item when instance item is already created? Since the new instance item already have the attribute of the template item. Wouldn't it be better to just to remove the template item from even showing up?

Share this post


Link to post
Share on other sites
Thinking about it, it's possible it's a compatibility thing with the following event commands.

::Control Variables::Game Data

::Conditional Branch(Page 2)

::Conditional Branch(Page 4)

::Change Equipment

Item/Weapon/Armor

 

+ Possibly a few methods within the scripts as well.

 

To make sure they detect the correct items since the instance items are given brand new id's.  Another way of doing it would be to use an array or hash to keep track of item counts, and modify the methods within the script... tho that itself might cause different compatibility problems.

 

Thinking about that, I decided to test something.  It seems the change equipment event command can cause nilClass crashes depending on how you make a script.  The command equipped me with the template,  and then it crashed when my equip leveling script referenced an equip's exp(since I set it at template creation instead of pre-loading.  I can work around the crash, but it shouldn't have given me a template in the first place.

 

Edit: The method to modify would be this one to fix the event command.

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Change Equipment (Specify with ID)
  #     slot_id:  Equipment slot ID
  #     item_id:  Weapons/armor ID
  #--------------------------------------------------------------------------
  def change_equip_by_id(slot_id, item_id)
    if equip_slots[slot_id] == 0
      change_equip(slot_id, $data_weapons[item_id])
    else
      change_equip(slot_id, $data_armors[item_id])
    end
  end
end

Edited by Selchar

Share this post


Link to post
Share on other sites

 

You can assume all equips that you work with are instance items.

 

Anything that goes into the inventory will be converted into an instance item.

Anything comes out is guaranteed to be an instance item.

 

This invariant must hold in order for my design to work properly.

 

If you ever get a template item, assume it is a bug (or a compatibility issue).

 

I don't get why for your instance item script: 

line 500 and 501:

            th_instance_items_gain_item(new_item, 1, include_equip)

            th_instance_items_gain_item(item_template, 1, include_equip)

 

Why keeping a copy of template item when instance item is already created? Since the new instance item already have the attribute of the template item. Wouldn't it be better to just to remove the template item from even showing up?

Template items should not show up. When you ask for a list of weapons or armors, it will be pulled from the instance weapons list and instance armors list.

 

If you're seeing templates, then it is likely a compatibility issue.

 

Thinking about that, I decided to test something. It seems the change equipment event command can cause nilClass crashes depending on how you make a script. The command equipped me with the template, and then it crashed when my equip leveling script referenced an equip's exp(since I set it at template creation instead of pre-loading. I can work around the crash, but it shouldn't have given me a template in the first place.

 

The method to modify would be this one to fix the event command.

Hmm, just noticed the issue. It was working before though, as I explicitly mentioned that in the documentation. Will look into why it's not giving the first instance.

 

EDIT: I deleted the modified change_equip method for some reason. It was passing the checks from trade_item_with_party since that properly converted templates to instances, but it was still a template being equipped to the actor.

 

I have updated the script to address this issue.

 

alias :th_instance_items_change_equip :change_equip
  def change_equip(slot_id, item)
    if item && $game_party.has_item?(item) && item.is_template?
      new_item = $game_party.find_instance_item(item)
    end
    th_instance_items_change_equip(slot_id, new_item)
  end
  
  alias :th_instance_items_trade_item_with_party :trade_item_with_party
  def trade_item_with_party(new_item, old_item)
    if new_item && $game_party.has_item?(new_item) && new_item.is_template?
      new_item = $game_party.find_instance_item(new_item)
    end
    th_instance_items_trade_item_with_party(new_item, old_item)
  end
At this point, I need to consider whether that trade_item check is actually necessary. Edited by Tsukihime

Share this post


Link to post
Share on other sites

Just discovered why you removed it before, for some reason it breaks the normal equipping.  So I guess it's a choice between not having that event command, or not being able to equip anything period... well, I can't figure out a solution, but I'll keep looking.

 

Edit: Spoke too soon, this seems to work perfectly unless I missed something.

alias :th_instance_items_change_equip :change_equip
def change_equip(slot_id, item)
  new_item = item
  if item && $game_party.has_item?(item) && item.is_template?
    new_item = $game_party.find_instance_item(item)
  end
  th_instance_items_change_equip(slot_id, new_item)
end
Edited by Selchar

Share this post


Link to post
Share on other sites

Latest version changes the way template counts are stored.

 

Rather than explicitly gaining an item (which could have all sorts of additional logic attached to it), I moved the counting into my own instance item gaining/losing methods.

 

The popup script should not incorrectly report extra items now.

Share this post


Link to post
Share on other sites

Is it possible for you to add script cooperation with Yanfly Engine Ace - Ace Equip Engine?

 

It seems that Ace equip engine would break if you reload the game using a save file. And equipment using custom slots would no longer be equippable. But if you don't save the game and load the game, it would be all fine and working.

Maybe perhaps instance items script didn't fully write everything into current savefile?

 

EDIT.

Actually nvm. I fixed it.

Edited by harvard1932

Share this post


Link to post
Share on other sites

I think the save file you're trying to use was made before you added Yanfly's Ace Equip Engine.  It works just fine if you start a new game after adding the scripts mentioned and save, then load.

Share this post


Link to post
Share on other sites

I think the save file you're trying to use was made before you added Yanfly's Ace Equip Engine.  It works just fine if you start a new game after adding the scripts mentioned and save, then load.

For some reason it wasn't the case. But anyways, it is fixed now.

Share this post


Link to post
Share on other sites

When I tried to use the instance item in a conditional branch: in inventory , include equipments it does not recognize it. Any help??

Edited by blacks888

Share this post


Link to post
Share on other sites

Oops. . Sorry  :P  , What I used was Conditional Branch: Actor [ Eric] is [bandana] equipped .  . .it supposed to change the actor graphic but it doesn't.

Share this post


Link to post
Share on other sites
Hello.

Great script, great help in my project.

But there was a problem when changing gear.

If you click "Remove All", the inventory duplicates appear clothes.

For example, I put on a suit, then took it off, and they are now in the inventory appeared two.

I apologize for my English, I'm from Russia.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×