Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Sign in to follow this  
Foxkit

Equipment Bonding System

Question

I was looking for suggestions on how to do a weapon bonding system and how to get the equipment screen to read said system. I've been trying to do some things with arrays but it hasn't been going very smoothly. I wouldn't mind doing this through events either. Though I would prefer scripts as I have more experience with them.

 

- In The Light

DizzyFoxkit(Foxkit)

Share this post


Link to post
Share on other sites

13 answers to this question

Recommended Posts

  • 0

The way the classes do It isn't restrictive/creative enough for what I want. Though if no one can suggest anything I'll stick with that.

Share this post


Link to post
Share on other sites
  • 0

Well, I think the difficulty is with the way rpg maker xp handles the inventory/equipment. It uses static references by id to all item/armor/weapon/etc. objects. This system would require dynamic inventory items.

 

The way I see it, there would be 2 ways to go about this:

 

1. Rewrite the inventory system to use dynamic objects

 

2. Create dynamic objects referred to by static ids

 

Personally, I think 2 would be cleanest and easiest to implement.

So the idea would be, add a reserved section to the $data_armors/$data_weapons arrays for dynamic equipment objects, save/load this dynamic set on save/load, and when a item becomes bonded, add it to this set and refer to that id.

 

Anyways, what I would do is:

 

First, I would set the reserve section.

So, after the $data_armors and $data_weapons are loaded i would add:

# The max size for armor/weapon is 999
# Setting the reserved section to 1000+ is the safest approach
$data_armors[1000] = nil
$data_weapons[1000] = nil

 

Next, I would add an element in the database called "bonding" or something. This element can be used as a flag to represent equipment that bonds once equipped.

 

Next, I would add a new attribute to the RPG::Armor and RPG::Weapon classes:

module RPG
 class Weapon
   attr_accessor :bonded_actor_id
 end
 class Armor
   attr_accessor :bonded_actor_id
 end
end

 

Next, I would probably modify the equip method in the Equip Scene to do something like this:

# If C button was pressed
if Input.trigger?(Input::C)
 # Play equip SE
 $game_system.se_play($data_system.equip_se)
 # Get currently selected data on the item window
 item = @item_window.item

 # Check if equipment bonds
 if item.is_a?(RPG::Weapon) && item.element_set.include?(bonding_element_id)
   $game_party.lose_weapon(item.id)
   bond_weapon(item)
   $game_party.gain_weapon(item.id)
 elsif item.is_a?(RPG::Armor) && item.guard_element_set.include?(bonding_element_id)
   $game_party.lose_armor(item.id)
   bond_weapon(item)
   $game_party.gain_armor(item.id)
 end

 @actor.equip(@right_window.index, item == nil ? 0 : item.id)  

 # ETC... rest of the code
end

def bond_armor(item)
 # Duplicate Object
 item = item.dup
 # Set the id to the last armor index + 1 
 item.id = $data_armors.size
 # Bond the item
 item.bonded_actor_id = @actor.id
 # Change the name if you want
 item.name = @actor.name + "'s " + item.name
 $data_armors[item.id] = item
end

def bond_weapon(item)    
 # Duplicate Object
 item = item.dup
 # Set the id to the last weapon index + 1 
 item.id = $data_weapons.size
 # Bond the item
 item.bonded_actor_id = @actor.id
 # Change the name if you want
 item.name = @actor.name + "'s " + item.name
 $data_weapons[item.id] = item
end

 

You will also need to modify your Window_EquipItem class (or equivalent) so it does not add other actor's bonded equipment to the list

 

if $game_party.weapon_number(i) > 0 && weapon_set.include?(i) &&   
 ($data_weapons[i].bonded_actor_id == nil || $data_weapons[i].bonded_actor_id == @actor.id)

 

and

 

if $game_party.armor_number(i) > 0 && armor_set.include?(i) && 
 ($data_armors[i].bonded_actor_id == nil || $data_armors[i].bonded_actor_id == @actor.id)

 

then all you need to do is add some code to the save and load functions in rmxp

save

bonded_weapons = $data_weapons[1001...$data_weapons.size]
bonded_armors = $data_armors[1001...$data_weapons.size]
Marshal.dump(bonded_weapons, file)
Marshal.dumb(bonded_armors, file)

load

bonded_weapons = Marshal.load(file)
bonded_armors = Marshal.load(file)
$data_weapons[1000...1000+bonded_weapons.size] = bonded_weapons
$data_armors[1000...1000+bonded_armors.size] = bonded_armors

 

And that should be all that's necessary.

Share this post


Link to post
Share on other sites
  • 0

kell, that is kinda how my weapon system works. alter the array, and save/load the array, and all variables added therein.

Share this post


Link to post
Share on other sites
  • 0

kell, that is kinda how my weapon system works. alter the array, and save/load the array, and all variables added therein.

 

ZOMFG LIZZIE WHERE YOU BEEN :o (or have I just been missing?)

 

HOW YOU'VE BEEN

 

[ontopic]

:) I was wondering what your approach to dynamic equipment was. I am sure there are still MANY more ways to doing this, but IMO this way seems to be the easiest/cleanest approach, as you can build this right over the existing scripts, so you don't have to go in and mess with anything.

[/ontopic]

Share this post


Link to post
Share on other sites
  • 0

Yeah, the only difference is i set it so there is a counter in Game_Party, and it just controls the array, so i don't have to add to it manually in the script. Essentially, I set it so when equipment is added using add_weapon, it separates them all into separate weapons rather than grouping them. i just set a loop for however many is added, increase the variable by 1 in the loop each time it goes through, and assigns the piece of equipment a new ID equal to 999 + variable. Works great, actually.

Share this post


Link to post
Share on other sites
  • 0

Thanks for the suggestions Kell, only one question though

First, I would set the reserve section.

So, after the $data_armors and $data_weapons are loaded i would add:

# The max size for armor/weapon is 999
# Setting the reserved section to 1000+ is the safest approach
$data_armors[1000] = nil
$data_weapons[1000] = nil

 

 

By loading $data_armors and $data_weapons, are you refering to where in Scene_Title it loads all the data for the game?

Share this post


Link to post
Share on other sites
  • 0

yes, exactly. So, something like this:

$data_armors = load_data("Data/Armors.rxdata")
$data_armors[1000] = nil
$data_weapons = load_data("Data/Weapons.rxdata")
$data_weapons[1000] = nil

setting the 1000th element to nil, is mostly just to set the array#size to 1001 so when you add new weapons/armors or load them when the player selects continue, they are added/loaded to the correct section.

Share this post


Link to post
Share on other sites
  • 0

OK, I lied, One more question, what is the Module for?

Next, I would add a new attribute to the RPG::Armor and RPG::Weapon classes:

module RPG
 class Weapon
   attr_accessor :bonded_actor_id
 end
 class Armor
   attr_accessor :bonded_actor_id
 end
end

 

also, I get a syntax error pointed at line 45 of the Scene_Equip script: http://pastebin.com/YfVb8k2w

Edited by Foxkit

Share this post


Link to post
Share on other sites
  • 0

Here's the fix.

 

http://pastebin.com/RsNr4E7W

 

You were missing a closing parenthesis, and had a double if statement ( "if if" ).

 

As for the attr_accessors in the RPG module, they allow instance variables to be accessed from outside the class. For example, say we had this code:

 

class Person

 def initialize(name)
   @name = name
 end
end

person = Person.new('Jim Bob')

print person.name # This will throw an error, since @name is private

 

Now, if we add an attr_reader, like so...

 

class Person

 attr_reader :name

 def initialize(name)
   @name = name
 end
end

person = Person.new('Jim Bob')

print person.name  # Works just fine

person.name = 'Billy-Bob' # Throws an error

 

The reason it throws an error is that we only used a "attr_reader", which allows reading, but not changing the value.

If we added "attr_accessor :name", we can safely read and write to the "@name" variable.

 

There is also attr_writer, but it is rarely used. It allows for changing values, but not reading them. You will most often see attr_reader and attr_accessor.

Share this post


Link to post
Share on other sites
  • 0

@ForeverZer0

Thanks, for both the explanation and the fix, I had already found the double if after I posted the pastebin, though it looks like I broke the closing parenthesis myself. Now its just a matter of figuring out the other bugs in the rest of the scripts.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...