Ammunition System & Add-on (Crafting System)

Unconnected42

Veteran
Veteran
Joined
Oct 24, 2015
Messages
110
Reaction score
36
First Language
French
Primarily Uses
Ammunition System - ver1.1.7


by Unconnected42


Latest updates


- 2016-12-11 : ver1.1.7 : fixed a bug that make the game crash in some menus when an actor had no weapon equipped.


- 2016-11-16 : ver1.1.6 : makes ammunition display for normal attack.


- 2016-11-15 : ver1.1.5 : fixes the incompatibility with Yanfly's Weapon Unleash.


- 2016-06-11 : ver1.1.4 : fixes the incompatibility with Yanfly's ItemCore ver. 1.24.


- 2016-02-17 : ver1.1.3 : (supposedly?) corrected a bug that causes crashes when enemy attacks for some persons.


- 2015-12-15 : ver1.1.2 : yet another bug correction.


- 2015-12-15 : ver1.1.1 : corrected a bug that caused zero cost equip ammunition to be unequippable.


- 2015-12-09 : ver1.1.0 : charged ammunition can now 'create' an 'empty' item when their charge number is reduced to zero. Also, charged ammunition will show their remaining charges in equip windows.


- 2015-11-29 : ver1.0.0 : added charged ammunition feature. Fixed a (generally silent) bug that could make skills availables even in case of unsufficient ammunition in some rare cases.


- 2015-11-26 : ver0.4.4 : fixed an issue that caused equip-type ammo to be equippable when it should not in some situations.


- 2015-11-24 : ver0.4.3b : fixed an issue that caused ammo not to be consumed in some situations when using older versions of Yanfly's ATB.


- 2015-11-21 : ver0.4.3 - the previous changes made actually break the ammo cost implementation when ammo are NOT independent items, causing the ammo to be simply unequipped... Corrected now.


- 2015-11-20 : ver0.4.2 - correction of the 'reload skills' feature so that indicating the correct equip slot for equip ammunition is no more necessary. Slight modification of how the cost of equip ammunition is managed internally, so that it works more logically when independent ammo with variance is used.


- 2015-11-15 : ver0.4.1 - corrected a bug causing a crash during battle when no weapon is equipped and the ammo amount is displayed next to attack command. Also corrected a bug that could make the displayed cost in attack command incorrect.


- 2015-11-15 :


* ver0.4.0: added compact cost display, game switch dependency, and weapon-type ammunition (for now, it is strongly recommended to use it only for weapons using themselves as ammo, such as throwing knives).


* added extension Crafting System.


Introduction


This script allow to define costs in terms of gold, items or equipments (that is, armors or weapons) for skills or weapons use.


It can be used for a variety of purposes : spells requiring special components in order to be cast, making items only usable by certain actors through the use of specific skills, having guns or bows needing bullets and arrows, throwing knives... 


Features


- the cost is added to any existing cost (MP, TP...)


- if the equipped weapon has a cost in items/equips, this cost will be applied each time the normal attack is used.


- if a skill/weapon has a cost for several items, each cost must be paid each time the skill/weapon is used.


- if a skill/weapon has a cost for several equipments, only the equipped ammunition will be consumed when the skill/weapon is used. Additionally in that case, if no ammunition is equipped, the skill/weapon cannot be used.


- skills can be used to change armour-type ammunition during battle.


- equip-type ammunition (armor/weapon) can possess charges (a number of limited uses), in which case the ammo charges are reduced at each use, instead of the ammo being consumed. When the charges number hits zero, the ammo is unequipped and 'disappears'.


Screenshots

Spoiler



ammunition_1.png


ammunition_2.png


ammunition_3.png


ammunition_4.png


ammunition_5.png


ammunition_6.png



How to Use, & Compatibility issues


My lazyness made me simply copy/paste the plug-in's help below :

Spoiler







============================================


Introduction


============================================


This plug-in will allow skills or weapons to require the consumption of 


ammunition, components, etc. in order to work. The cost is  paid each 


time the skill is used, together with MP/TP costs, or each time the 


normal attack is used in the case of weapons.


The ammunition can be either gold, items or equipments (armours, weapons), or 


a mix.


However, things work differently depending on what type of cost is considered.


- items : if several types of items are marked as required as ammunition 


  for a given skill/weapon, *ALL* of the corresponding prices must be 


  paid each time the skill/weapon is used. 


- equipment : the equipment needs to be equipped in order for the skill/weapon


  to work. If several types of equipments are marked as required as ammunition


  for a given skill/weapon, *ONLY* the cost of the one that is *CURRENTLY


  EQUIPPED* will be paid. That means a weapon/skill can be able to use 


  different interchangeable ammunition types.


- Gold cost is straightforward in how it functions.


You can also define skills which can change the type of ammunition 


equipped even during combat, in the case of armour-type ammunition.


Then, your hero can use an action to change his/her ammunition type !


============================================


Known Compatibility Issues


============================================


This plug-in should be placed under all plug-ins that you are using,


especially Yanfly's since it actually uses some of their features if


they are present.


Known exceptions to that rule : 


- Yanfly's Skill Cooldown


- Jay's Dual Techs. 


  -> Ammunition should be placed above these two plug-ins.


This might also be the case for other plug-ins whenever 


the modification of skill costs is concerned.


On the contrary, the following plug-ins MUST be placed above :


- Bobstah's BattleCommandList.


This plug-in in the present version should be fully compatible


with Yanfly's ItemCore Independent Items feature.


Therefore, ammunition of any kind can either be independent or


not (for the latter case, use a <Not Independent Item> notetag


in the ammunition notebox if you are using ItemCore and a max


number of items > 0).


============================================


Use


============================================


+ Declaring a weapon/skill to need ammunition


---------------------------------------------


Lines to put in either Weapon notebox or Skill notebox for defining costs :


  <Gold Cost: c>


  <Ammo i Item: c>  (for items ammo)


  <Ammo i Equip: c>  (for armors ammo)


  <Ammo i Weapon: c>  (for weapons ammo)


... where i is the ID of the ammunition item/armor and c is the cost 


required for one use.


Disclaimer concerning weapon-type ammunition: 


In its present state it is intended to be used for weapons that would be


their own ammo, like throwing knives, shurikens, etc.


In theory, however, it *should* be possible to use as ammo for a weapon 


a different weapon, provided both of them are equipped, but this possibility


has yet to be playtested...


+ Declaring a skill that serves for equipping ammo (during combat)


------------------------------------------------------------------


To create a skill that will change the type of ammunition equipped:


  <Ammo i Load>


... where i is the ID of the ammunition armor.


The following syntax is also authorized:


  <Ammo i Load: s>


...where s is the specific slot to be equipped.


This syntax is kept only for compatibility reasons, so that people


who defined their tags for older versions of the script that did


not support the simpler syntax are not forced to change.


If your actor(s) have for example the following equipment types:


    Weapon, Shield, Head, Body, Accessory, Ammunition


... then the slot number would be 6.


Note 1: this is meant to be used during battle, when equip menu is not 


accessible, if you want your actors to be able to switch ammunition.


Note 2: it is necessary to define one skill per type of ammunition.


Note 3: it is possible to use this tag for equipping any kind of armor, and 


not just ammunition.


Also, the Load feature currently does not work with weapon-type ammo.


+ Ammo equipment with charges


-----------------------------


For an armor- or weapon-type ammunition, you can allow each ammo item to


provide a given number of uses instead of being consumed after just one use.


Declare the following tag in the ammo equipment notebox:


  <Ammo Charges: n>


... where 'n' is the wished number of charges the item possesses.


This tag will only actually be used if you are using Yanfly's ItemCore and


the item is an independent item.


The equipped ammo item has a certain number of charges, and at each use, this


is this number that will be reduced, instead of the number of ammo items.


When the number of charges hits zero, the item is unequipped, without


being returned to inventory. No other item of same type will be equipped even


if available in inventory.


+ Determining skill's availability depending on a game switch


-------------------------------------------------------------


You can also now have skill availability depend on a game switch status, with


the following tag to put in a skill's notebox:


  <Game Switch: n>


If the game switch number 'n' is set at false, the skill cannot be used.


This might be useful, for example, if you are also using the crafting


extension of this plug-in and wish to make crafting available only


in certain places/situations.


============================================


Displaying Ammunition Amounts & Costs


============================================


A given ammunition type is almost always represented by its icon when it


is necessary (either to display a cost or a remaining amount).


Ammo costs for skills are indicated together with "normal" TP/MP costs.


There are several solutions for displaying the remaining ammunition amount


so that the player knows where he stands.


Most of them are turned on through the plug-in parameters.


- For weapons : 


  + The number of ammunition left can be displayed at the


    top of the screen when the actor command menu is active.


    This is the default option.


  + The number of ammunition left can be displayed in the 


    command window, just next to the "Attack" option.


    No icon in that case.


  + If you are using Yanfly's SkillCore plug-in, you can use the following


    notetag in the weapon note :


        <Swap Gauge n: AMMO>


    ...where n is the number of the gauge you want to replace.


    Instead of a normal HP/MP/TP gauge, you will then have the amount of


    ammunition left for the currently equipped weapon.


- For skills : 


  + The remaining amount for each ammunition type can be showed


    together with cost in the skill window.


  + It can also be displayed after the skill description, in the help


    window. This is the default option.


    In that case, you should keep the skill description within one unique


    line with no line-break at the end, or else the remaining ammo will 


    not be visible.


The text before ammunition left amounts can be customized with the following


  notetag in the skill notebox:


  <Ammo Left Text: xxx>


  ... with xxx being your custom text.


The name of the ammunition type can be displayed along with its icon with


the following notetag in the weapon/skill notebox:


  <Show Ammo Name>


Also, in the case of equipment ammunition, several types of


ammunition are possible but only one (the one equipped) will be displayed


in any skill/help/etc window (or gauge). When there is no more ammunition,


the system normally would not know which icon to use !


There is a default icon for that, but you can put the following notetag


in skill/weapon notebox to define which icon will be used :


  <No Ammo Icon: i>


  ... with i being the icon number. 


It is also possible to add details about the ammunition type currently 


equipped by adding the following notetag in the ammo notebox :


  <Ammo Window Desc: xxx>


Where 'xxx' is the description you want to give to your ammo.


This description will show up in the skill help window and the ammunition


window visible during actor command selection.


Please that if you deactivate the ammo window or the display of remaining


ammo amount with the corresponding plug-in parameters, you will of course 


not see any description of ammunition !



Plug-in code


Js file download


Add-on : Crafting System

Spoiler



A skill-based crafting system, requiring Ammunition System because it makes use


of its item costs mechanics. Must be placed *below* Ammunition System.


Features


- Allow skills to produce items.


- Crafting skills must be affected to specific skill types listed in one of the plug-in parameters.


- Display of crafting skills products and components' detailed costs and amounts.


How to use :



Spoiler



============================================


Introduction


============================================


This plug-in provides a skill-based crafting system.


============================================


Known Compatibility Issues


============================================


This plug-in is an extension of Ammunition System.


It will not work if Ammunition System is not installed, and


must be placed below it in the plug-in list.


If you are using Bobstah's BattleCommandList plug-in,


you will probably have to manually remove from your actors'battle command


lists the crafting skill types (see below).


============================================


Use


============================================


This plug-in functions by allowing skills to produce items of any kind.


The crafting skills (i.e., skills producing items) can consume items


according to the rules of Ammunition System, with some specific tweaks.


Note that crafting skills are not supposed to be used during battle.


For the crafting skills to work properly, they must be given special


skill types that are to be listed inside the plug-in parameter


'Crafting Skill Types'.


Example : create a skill type named 'Alchemy' with number 6 and


put '6' as the value for parameter 'Crafting Skill Types'. Then, give


the skill type Alchemy to some skills that you want to produce items.


Later, if for example you create another crafting skill type named


'Cooking' (number 7), put '6,7' as the value for parameter


'Crafting Skill Types'.


When a skill type is listed in the Crafting Skill Types, there are two


consequences:


- the skill type will not appear during battle (only if you don't use


any plug-ins altering the actor battle command list)


- when in main skill menu, when a crafting skill type is selected, the


normal item window will be replaced. Instead, you will have two windows:


the one at left will display the list of skills corresponding to the


selected skill type (all those skills should be crafting skills),


the one at right will display a list of products and components of


the currently selected skill. Current amounts of products/components


will also be displayed.


Here are the tags to put in crafting skills notebox for defining production :


<Make i Item: n>


<Make i Armor: n>


<Make i Weapon: n>


... where 'i' is the index of the desired item/armour/weapon and 'n' is the desired


amount.


As for the components, use the same tags as seen in Ammunition System.


However, there is a little difference regarding item consumption.


Weapon and armour-type items will be considered as normal items:


that is, they do not need to be equipped, only the items in inventory will


be accounted for to estimate the available amount (not the ones being equipped),


and all the listed equip-type ammo will be consumed, and not only the one


equipped.


It is possible to customize the texts introducing the products and components


in the craft information window with the following tag to put in the skill's


notebox:


<Craft Product Text: xxx>


<Craft Component Text: xxx>

Screenshots:


crafting_1.png


Download:


Js file download









Working Demo:


Download Demo !


(contains demonstration for plug-ins Ammunition System, Crafting extension and Change Equip On Battle) 


(this demo contains no other plug-ins than the three aforementioned, meaning there is no demonstration for the functionalities depending on external plug-ins - such as Yanfly's plug-ins. Maybe another demo showing special functionalities and interactions with other plug-ins will be released later !)


Credit and Thanks


- Unconnected42


You can freely use, edit, or do anything you want with this plug-in, commercially or not. Just give proper credit. :)
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
commercial use?
 

wrigty12

Veteran
Veteran
Joined
Jan 11, 2014
Messages
533
Reaction score
77
First Language
English
Primarily Uses
Can you also add the ability to use your money/currency as ammo?
 
Joined
Jun 16, 2014
Messages
4
Reaction score
1
First Language
English
Do you think you could upload the .js file and post it instead of dropping the code in a spoiler? I'm not sure the code copied properly from my copy and pasting it from the forum and I would love to try this put, it sounds like a very useful plugin. :)
 

Silent Darkness

Robomage
Veteran
Joined
Nov 28, 2013
Messages
2,284
Reaction score
324
First Language
English
I have two suggestions for you:

#1: Upload a pre-made .js file.

#2: I think your main focus should be fixing full compatability with Yanfly Item Core as soon as possible. This sounds really cool, and i'd love to be able to use this alongside Yanfly's scripts.
 

winkr7

Veteran
Veteran
Joined
Oct 27, 2015
Messages
54
Reaction score
10
First Language
english
Primarily Uses
N/A
Hello;

I suggest you not use x,y for variables like item id, these are typically coordinate variable names.

yours

winkr7
 

Unconnected42

Veteran
Veteran
Joined
Oct 24, 2015
Messages
110
Reaction score
36
First Language
French
Primarily Uses
I have two suggestions for you:


#1: Upload a pre-made .js file.


#2: I think your main focus should be fixing full compatability with Yanfly Item Core as soon as possible. This sounds really cool, and i'd love to be able to use this alongside Yanfly's scripts.
Concerning your second point, I looked a bit more into it, and I found out that it is already more compatible than I thought at first.


To begin with, it is only when you try using the "independent items" feature of Yanfly's ItemCore that things become bad. And even in that case, it works fine as long as all the concerned weapons/items/armours are set as not independent with the <No Independent Item> tag.


Since I don't really see the point of independent ammunition, I think I won't really try to adapt for that case.


I am more concerned about independent weapons. *These* should be able to be used alongise with my script, and they currently do not, so I will probably do something about it.
 
Last edited by a moderator:

Unconnected42

Veteran
Veteran
Joined
Oct 24, 2015
Messages
110
Reaction score
36
First Language
French
Primarily Uses
I updated the plug-in !


Now it can deal with independent weapons from Yanfly's ItemCore.


However, ammunition must still be set as Not Independent to work properly.


Also, it is now possible to have skill usage cost gold.
 

Ozuma

Villager
Member
Joined
Jun 26, 2013
Messages
19
Reaction score
5
Primarily Uses
Some way to use weapons such as ammo? I would like to make a Skill "Throwing Daggers", for example.

Great work!
 

Silent Darkness

Robomage
Veteran
Joined
Nov 28, 2013
Messages
2,284
Reaction score
324
First Language
English
Some way to use weapons such as ammo? I would like to make a Skill "Throwing Daggers", for example.

Great work!
Here's my reccomendation. Make Throwing Daggers a skill that uses a throwing dagger ammo type.
 

a6p

Veteran
Veteran
Joined
Nov 1, 2015
Messages
30
Reaction score
8
First Language
English
Can we set whether the item is consumed by the use of the skill?

Also: what happened?

 

Unconnected42

Veteran
Veteran
Joined
Oct 24, 2015
Messages
110
Reaction score
36
First Language
French
Primarily Uses
Can we set whether the item is consumed by the use of the skill?


Also: what happened?


For now, the item is always consumed when the skill is used.


As for the bug you are showing, could you tell me more about the context?


For example :


- when it happened exactly ? (when opening skill window, when attacking, outside/inside of battle, at the beginning of a battle exactly, etc)


- whether you have other plug-ins running or not ?


- what were the values for the ammunition plug-in parameters ? (did you change the default values or not)


I remember I had a bug like this at some point during development, but I dont remember at all when and why it happened, and it was supposed to be corrected...


Also, if you can, try using F8 when running your game to launch the console, then do a screen capture of what it tells. That would be extremely helping !
 

HeroicJay

Veteran
Veteran
Joined
Jun 23, 2014
Messages
321
Reaction score
175
First Language
English
Primarily Uses
RMMV
This plug-in should normally be placed under all plug-ins that you are using if possible, especially Yanfly's since it actually uses some of their features if they are present.
Careful with blanket assertions like this one. It modifies skill cost, and thus must go above my dualtech plugin.

Also for compatibility with my plugin, I would recommend that you return the length of the remaining text area after writing the skill cost (in pixels) from Window_SkillList.drawSkillCost. The later versions of Yanfly's plugins do this; you can just imitate what Yanfly does.
 
Last edited by a moderator:

gambitben

Veteran
Veteran
Joined
Jun 8, 2013
Messages
143
Reaction score
106
First Language
Spanish English
Primarily Uses
RMMV
I have the same bug as above, it happens when this plugin is below Yanfly's skill core plugin. 

TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': float parameter 1 is non-finite.

    at TypeError (native)

    at Bitmap.getPixel (file:///C:/Users/Ben/Documents/Games/Stream/js/rpg_core.js:689:30)

    at Window_SkillList.Window_Base.textColor (file:///C:/Users/Ben/Documents/Games/Stream/js/rpg_windows.js:176:28)

    at Window_SkillList.drawAmmoCost (file:///C:/Users/Ben/Documents/Games/Stream/js/plugins/Ammunition.js:434:36)

    at Window_SkillList.drawSkillCost (file:///C:/Users/Ben/Documents/Games/Stream/js/plugins/Ammunition.js:411:14)

    at Window_SkillList.drawSkillCost (file:///C:/Users/Ben/Documents/Games/Stream/js/plugins/YEP_X_SkillCooldowns.js:1348:48)

    at Window_SkillList.drawItem (file:///C:/Users/Ben/Documents/Games/Stream/js/rpg_windows.js:2208:14)

    at Window_SkillList.Window_Selectable.drawAllItems (file:///C:/Users/Ben/Documents/Games/Stream/js/rpg_windows.js:1250:18)

    at Window_SkillList.refresh (file:///C:/Users/Ben/Documents/Games/Stream/js/rpg_windows.js:2234:10)

    at Window_SkillList.setStypeId (file:///C:/Users/Ben/Documents/Games/Stream/js/rpg_windows.js:2146:14)

 

that is how the error reads.
 

Unconnected42

Veteran
Veteran
Joined
Oct 24, 2015
Messages
110
Reaction score
36
First Language
French
Primarily Uses
Ok, I just looked into this (the type error crash).

Answer : rename your 'Ammunition.js' file as 'UNCO_AmmunitionSystem.js' (the name given at the beginning of the code) and you should be fine. :)

Detailed explanation in spoiler for those who want to know why exactly :

First, the actual line incriminated is line 434 from Ammunition.js.

This line reads :

this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));

Since the message error says that the reason for crashing is that getImageData gets something that is not a float as a parameter that should be a float, it probably means that ultimately the variable Unco.Param.ammoFontColor should be a number but is not.
This variable is actually initialized earlier by a plug-in parameter. The only explanation is that you did put something that is not a font color number as the value for this parameter. Actually, I can reproduce your bug when I put some random non-number value for this parameter !

So the problem is certainly that the plug-in cannot read the parameter value at all because it has an unexpected name since the plug-in name matters when you want your code to read the parameters !

Careful with blanket assertions like this one. It modifies skill cost, and thus must go above my dualtech plugin.
 

You are right about that ! So right, actually, that during my tests concerning the point above, I realized that AmmunitionSystem should probably also go above the Yanfly's SkillCooldown plug-in as well, since the philosophy of SCD is to replace any existing cost with the cooldown info when the skill cannot be used because of cooldown, and Ammunition breaks that too if it is placed below. It seems it works fine if you put them in that order (Ammunition above, CoolDown below).

 

Also for compatibility with my plugin, I would recommend that you return the length of the remaining text area after writing the skill cost (in pixels) from Window_SkillList.drawSkillCost. The later versions of Yanfly's plugins do this; you can just imitate what Yanfly does.
 

Well... it does that already, I think. I relied a lot on imitating Yanfly's scripts when I wrote my own, so I just copied that feature in my DrawAmmo function without even thinking, at first.

EDIT : okay, drawAmmo did the job correctly, but I just forgot the return in drawSkill when calling the previous version of the function... Now Ammunition can work fine with DualTechs, normally...
 
Last edited by a moderator:

HeroicJay

Veteran
Veteran
Joined
Jun 23, 2014
Messages
321
Reaction score
175
First Language
English
Primarily Uses
RMMV
Now Ammunition can work fine with DualTechs, normally...
Well, there's still something I need to do on my end to make it COMPLETELY work fine. I was discussing the possibility last week but never did get around to it. It's a very specific scenario, though.

If your characters are using a dualtech skill that requires the same type of ammunition, and you have enough for each but not for both, you'll almost certainly still be able to use the skill. I haven't actually tested that, but I know my own plugin well enough. You'll blow through all the ammo you have in the process, of course, but the point is that you shouldn't be able to do that at all. Again, this is a known problem in my code; you're fine on your side.
 

wsensor

Villager
Member
Joined
May 2, 2012
Messages
20
Reaction score
5
First Language
English
Primarily Uses
Is there a way to set a max ammo per gun? Then a reload option to reload the ammo.

IE: Pistol holds 6 bullets. While if your using an old shotgun it only holds 2 shells?
 
  • Like
Reactions: PTS

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Potato The game! Few concepts for characters to my game.
Well, well, well, well....Lemme get a look at this fanart.
The Google Play rating for one of my games finally rose above 4.0 after getting review-bombed from a $0 sale. Now the game's sales are doing much better when discounted, so that's nice.
I'm getting close to releasing a demo. Working on formatting my Games in Development post.
I always see a few people asking for C# in next engine and I always thought: Do I not know enough about that language to tell it will affect extensibility and customizability to the negative? Watching a video from SumRndmDde today I feel confirmed.

Forum statistics

Threads
98,221
Messages
950,471
Members
129,518
Latest member
noireoxla
Top