Selchar

Equipment Durability

52 posts in this topic

Equipment Durability Ver. 1.06
Selchar

Introduction
This script allows for giving weapons and armor durability, and either destroying or just unequiping them when that durability reaches 0.

Features
- Adds Weapon durabilty, reduced with each successful attack/skill
- Adds Armor durabilty, reduced when hit  by chance of your choice.
- Can destroy or just unequip at 0 durability for selling/repairing.

Screenshot

Durability_zpsd54b88f0.png


How to Use
Place the script below ▼ Materials, below Tsukihime's Instance Items, but above ▼ Main Process. Use the provided notetags to designate which weapons use durability feature.

Script
>Required<
Weapon Durability
Armor Durability
 
Repair Equip Scene
 
Weapon Durability Armthrift Rate

FAQ
Q: What are the terms of use?
A: My terms are, anything goes, while the terms for Tsukihime's scripts can be found here

Credit and Thanks
- Selchar
- Tsukihime for the Instance Items Base

Updates
1/7/14: Added notetag to transform 0 durability equip into something else when destroy_broken_weapon is false.
1/8/14: Moved some methods, small change to weapon break message.
1/11/14: Improved Flexibility of code, added <skill durability mod x: y> notetag, adjusted price based on durability
1/12/14: Fixed durability prices when leveling weapon.
1/16/14: Compatibility with new Instance Items, Add Armor Durability, add Repair Equip Scene Edited by Selchar
PK8 and Jóshua Sardinha like this

Share this post


Link to post
Share on other sites

https://github.com/Hime-Works/Requests/issues/83

This request can possibly be filled using this script by modifying the way durability is processed and making it more abstract.

The current functionality supported are as follows (there are more, but these are the ones relevant to my suggestion)

1: weapons can have durability

2: weapons can have their own durability costs (undocumented)

Suggestions

Add support for skills to have their own durability costs.

I don't have any thoughts on whether the weapon durability cost and skill durability costs should be combined or not.

The script in its current state basically processes everything related to durability in a single method, which does not allow me to easily add in additional logic.

Personally, I would make it extremely abstract so that each method only has a single responsibility like this, but it may be unnecessary.

  def process_weapon_durability(item)    return unless can_process_durability?(item)    weapons.each do |wep|      process_weapon_durability(wep, item)    end  end  # I like doing this, because you can't really  # modify the loop up there to add in some extra  # logic before or after certain lines. This is just  # an extra piece of abstraction that allows me to insert  # custom logic before or after it  def process_weapon_durability(weapon, item)    return unless weapon  # I might move this condition into its own method    update_weapon_durability(weapon, item)    # maybe more stuff  end   # Now, this does not really provide much value in terms of flexibility  def update_weapon_durability(weapon, item)    reduce_weapon_durability(weapon, item)    # maybe more stuff  end  # only math related to durability reduction should happen here  def reduce_weapon_durability(weapon, item)    weapon.durability -= get_durability_cost(weapon, item)  end  # only durability calculation should happen here  def get_durability_cost(weapon, item)    weapon.durability_cost  end
Edited by Tsukihime

Share this post


Link to post
Share on other sites

I'll consider the changes, I was going to get started on updating to durability for all equips, but perhaps that should be given it's own script in favor of overall flexibility, and just improve this one to be more easily extended?

Edit: Not necessary for a separate script because of the <use durability> tag, so I guess I'll be changing this to equipment durability.

Edit: On second thought, going through his request, it's probably for the best to keep them seperate, the armor durability he wants sounds like it would be used at the same time as weapon durability.

I believe skills already have durability costs, it's default to 1 for all skills, which would explain why it decreases even when you guard. I should also do something about renaming conflicts with other scripts that may alter the names, like my equip leveling script, and any affix system that could be implemented. I already updated my equip leveling base with an attempt to pre-empt affix name changes, tho of course it's untested and may change later on.

 

Edit: Reread the link you provided, I'll think on how to extend durability reduction, the current implementation is rather basic.

 

UPDATE:

Removed Selchar Module, there is only the TH_Instance module and what's inside that.
Changed method make_max_durability to Repair
Extended process_weapon_durability(item) with the following methods.
Added can_process_weapon_durability(weapon, skill)
Added process_individual_weapon_durability(weapon, skill)
Added weapon_durability_cost(weapon, skill)
Added <skill durability mod x: y> notetag for weapons to modify skill durability costs.
Added Default_Durability_Cost constant, 
Added Price Changes according to durability vs max durability
 
Made modifications to how the name and durability suffix are handled(now compatiable with equip leveling base)
 
Only bugs known related to durability price and leveling up equips, everything else should work.  Kind of rushed that part will look into it.
Edited by Selchar

Share this post


Link to post
Share on other sites

It would be awesome if you can make the durability for equipment dynamic.

LIke: If a weapon didn't have <use durability>. It can be later added with <use durability> so it would be using durability. If that weapon's <use durability> is later remove, then durability would be removed as well.

 

I think making it this dynamic would be extremely useful; also the reset can make developers make repair function for the item. :)

Share this post


Link to post
Share on other sites

So yea! The newer version of the script crashes level base script. Because of item name incompatibility

Edited by harvard1932

Share this post


Link to post
Share on other sites

There shouldn't be any problems if you have the latest version of both scripts, let met check again in a clean project... Yes, make sure you have the current version of BOTH Durability and Equip Leveling Base.

Edit: I don't see a point in adding durability use sometime after you've acquired a weapon, as for reparing, that is already internally supported. It just needs a scene that allows you to select a piece of equipment and call the repair method, which I'll do after I've made an armor durability version of the script. Oh, I'll have to do a minor update to the repair method to make sure it calls the name update method.

Edited by Selchar

Share this post


Link to post
Share on other sites

Adding durability use sometime after you've acquired a weapon can be used for "broken weapon" function. Like during crafting there is a chance of getting a broken weapon with durability expiration rather than permanent.

Also the de-durability function allows player to make a durability weapon to become permanent, which is a useful function.

Share this post


Link to post
Share on other sites

Couldn't you just make 2 copies of the same weapon, one with durability and one without, and have a way of replacing one with the other depending on circumstances? To have a chance of having durability or not doesn't sound like something I should have in the main script, it can be done as an add-on but I'm not sure if it's worth it or not.

Example: You mentioned crafting, you can have the craft script give you the non-durability version on success, or durability version on fail. You can also use crafting to take the durability version and "upgrade" it to the non-durability version. Of course it depends on the crafting script you're using.

Edited by Selchar

Share this post


Link to post
Share on other sites

There isn't a way to replace equipment around like that... And it isn't efficient to have 2 copies of everything

Share this post


Link to post
Share on other sites

As I said it depends on the crafting script you're using. A crafting script takes the components, or ingredients, and replaces them with the result. So it would work perfectly if said crafting script gives you an item based on success or fail. If I add in the ability to randomize the chance of whether or not durability is used, as well as a method to remove it, then I or someone will also have to design a new scene JUST to call the method to remove that durability requirement.

It's possible, but I don't think it is something I'll do myself.

Share this post


Link to post
Share on other sites

Actually it is much easier.... Because right now if I were to add <use durability> to an item after it is already created. It wouldn't have durability on it.

I just want it so item will get durability on it when I later add <use durability> on the item. 

I think the part to remove the durability can be ignored. 

Share this post


Link to post
Share on other sites

Add

class RPG::Weapon  attr_accessor :use_durabilityend
after that, you just need a way to access the particular weapon and call the necessary methods. For example this works as a scriptcall for whatever is in actor 1's first equip slot.

a = $game_actors[1].equips[0]

a.use_durability = true

a.repair

I won't be making a scene to automate and/or expand it tho.

Edit: You're free to make a request for someone else to make an add-on to this to do what you want exactly.

Edited by Selchar

Share this post


Link to post
Share on other sites

Did an update of all of my scripts related to Tsukihime's Instance Items for compatibility and other stuff.  See signature for recommended script order if you use multiple scripts for it.

 

Also added Armor Durability.  Durability for armor will reduce when you are hit by chance, and you can tag armor with elemental modifiers to manipulate that chance.

 

Added Durability Equip Repair Scene to go with it all.

Share this post


Link to post
Share on other sites

Is there a possibility  to damage my weapon/armor or destroy it in an event? It's like this, I wanted an appraise and it failed so It will reduce the durability and can even break the item. .

Share this post


Link to post
Share on other sites

Sounds like you would want a custom scene to select and carry out the appraisal processes, or do you mean appraise a currently equipped equipment?  What would happen on a success?  How much durability would the equipment lose on failure?  A static number or random? Chance of success?  I'm not saying I'll put it together but that is information needed for anyone to tell you if it can be done now, and if so how, or if something custom made needs to be made, either from scratch or using my repair scene as a base to simplify the process.

 

Edit: Let's throw in appraisal price on the list of things needed to know.

Edited by Selchar

Share this post


Link to post
Share on other sites

Yes, I would like the current equipment to be used as appraisal, let's say I will use the default durability then it will have item-affixes, so I'll make random variable , if the variable is correct there will be +1 , then if it was the wrong variable. . the equipment will lose durability or it will break.

 

 

 

 

 

 

 

Thank you very much :D

 

 

Okay, last request. . . how can I reduce durability my game party leader's equipped weapon/armor? I'll use it in a scene where there was an epic war then the leader's armor and weapon got damaged. . that's all thanks for all the help

Edited by adokenz

Share this post


Link to post
Share on other sites

So you're going to try and event it through script calls, got it, unless you'd like a scene to select a currently equipped equipment(don't know how to do that at this time.  So if eventing... I'll give you a scriptcall that you can modify to suit your purposes

class Game_Interpreter  def appraise_equip(actor_id, slot=0, chance=0.5)    equip = $game_actors[actor_id].equips[slot]    if rand <= chance      #What happens with a success goes here.      #set_suffix(equip, 62) #Sets a suffix to your equip, from Tsukihime's Affixes      return true    else      #What happens with failure goes here      equip.durability -= rand(10)+1 #(loose between 1 and 10 durability      if equip.durability < 0        equip.durability = 0        equip.break_by_durability($game_actors[actor_id])      end      return false    end  endend

Place the above code below my durability script(s), possibly under any other instance related scripts. With it you'd make your event to select which actor based on id, maybe choose which equipment slot. Then call the scriptcall with...
 

a = $game_variables[7] #Whatever variable you set the actor id to.s = $game_variables[8] #Whatever variable you set the slot id to if applicableif appraise_equip(a, s)  $game_switches[5] = true #Switch you use for eventing after this scriptcall for dialogue/etc...else  $game_switches[5] = false#Switch you use for eventing after this scriptcall for dialogue/etc...end

The scriptcall can be just appraise_equip(a) if you only choose actor id, appraise_equip(a, s) for actor id and slot id, or event appraise_equip(a, s, c) to include the chance of success(defaulted to 50% in the snippet I gave, written as 0.1 for 10%, 0.5 for 50%, etc...).  Also that switch in the scriptcall is optional, but I figure easier to give success/fail text that way.  Hope that's close enough to what you wanted.

 

Remember to look the scriptcall over and give it the correct settings for your project, since I don't know "exactly" what you want or how you're going to use it.

Edited by Selchar

Share this post


Link to post
Share on other sites

Hello, Selchar! Your script is very useful to me, I'm just having an issue with a detail. In the game, I'm setting a float number as "Default_Durability_Cost", and when the script draws some weapons current durability, after it is decreased, the number get lots of decimals. I know that it is a usual computer issue, but, if I'm not mistaken, the number of decimals can be defined. Can that be done in your script?

Thank you!

Share this post


Link to post
Share on other sites

I didn't forsee people using decimals when the default setup was obviously based on integers, but it's possible to do. In the customization area a little below Default_Durability_Cost, you should see

Dur_Suf = ' (%s/%s)'

Change that to

Dur_Suf = ' (%.2f/%s)'

As for durability costs made through the <skill durability mod x: y> notetag, it currently assumes integers, I thought the fix for that would be simple, but it looks like I assumed wrong so if you need that to be decimal based as well, I'll have to have a look to see if I can remedy that for you.

Share this post


Link to post
Share on other sites

I'm looking for decimals because I don't want too big numbers to be drawn (and I would need that since I have skills with effects applied more than 20 times by a turn, a weapon would be destroyed in a single battle). So if that was possible, it would be much helpful. If it's not, however, things are still fine. I can apply a low number as Default_Durability_Cost, I guess.

Share this post


Link to post
Share on other sites

Turns out it was as simple as I initially thought, I just didn't take everything into consideration. The following will allow both the skill durability cost mod and the actual skill costs to be decimals. I haven't had any issues so far. If you need anything else changed to floats let me know, the only thing left I can think of atm would be max durability.

class RPG::Weapon  def skill_durability_mod(skill_id)    if @skill_durability_mod.nil?      @skill_durability_mod = []      $data_skills.each do |i|        next unless i        if @note =~ /<skill[-_ ]?durability[-_ ]?mod[-_ ]?#{i.id.to_s}:\s*(.*)\s*>/i          @skill_durability_mod[i.id] = $1.to_f        else          @skill_durability_mod[i.id] = 0.0        end      end    end    @skill_durability_mod[skill_id]  endendclass RPG::Skill  def weapon_durability_cost    @note =~ /<durability[-_ ]?cost:\s*(.*)\s*>/i ? @durability_cost = $1.to_f : @durability_cost = TH_Instance::Weapon::Default_Durability_Cost.to_f if @durability_cost.nil?    @durability_cost  endend

Share this post


Link to post
Share on other sites

Everything is great! To make the max durability a decimal would only show bigger settings, it's the opposite of what I'm wanting. Thank you very much, Selchar!

Share this post


Link to post
Share on other sites

Have you considered something like Fire Emblem Awakening's Armthrift skill where a passive skill or even an accessory can sometimes prevent equipment from losing durability?

Share this post


Link to post
Share on other sites

Awakening... haven't played that one.  Equipment that can add a chance to avoid reducing Weapon Durability can easily be done I think.  A passive skill that does the same?  It's possible(makes a note to look at how passive skills can be done)

 

Edit: And done, check the 1st post, or just click the following.

 

https://drive.google.com/file/d/0BywhvOtY4_H9X0E4WTBaaU1pVzA/edit?usp=sharing

Edited by Selchar

Share this post


Link to post
Share on other sites

So, I'm having issues with the script...

No, it works, durability works as it should, all items are counted as different entries in the inventory, but my issue is: the script keeps crashing the game I'm working on whenever I'm going to sell items with the Galv Shopping script.

 

Is there a patch I'm missing? Is it an compatibility issue? Is there an simple fix I haven't seen?

 

Edit: Also, every single time I use an item(like a potion or something) it crashes the game.

Edited by TwilightKnight1

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.