Help - Search - Members - Calendar
Full Version: Ammo Requirements
RPG RPG Revolution Forums > Scripting > Script Tutorials > GML / Other
Ty
Script Name: Ammo Requirements
Written by: Synthesize
Current Version: V.1.00
Release Date: August 15, 2007

What is it?
With this script the actors can only attack and/or do specific skills if they have enough ammo in the inventory. The designer can set every weapon to use it's very own unique ammo count and ammo easily via the options at the top.

Features
- Each weapon can use a different amount of ammo (Say a shotgun fires 5 rather then a pistol which fires 1)
- Each weapon can have it's own ammo
- Easily define skills that require ammo and the amount of ammo needed
- Skills use the current equipped weapons ammo rather then a defined value.

The Script
Place in a New Script Above Main.
CODE
#============================================================================
#                            Syn's Ammo Requirements  
#----------------------------------------------------------------------------
# Written by Synthesize
# Version 1.00
# August 15, 2007
# Tested with SDK 2.1
#============================================================================
#----------------------------------------------------------------------------
# Customization Section
#----------------------------------------------------------------------------
module Ammo
  # Format = {weapon_id => Ammo_cost}
  Range_weapons_id = {17 => 1}
  # Format = {weapon_id => Item_id
  Range_ammo_id = {17 => 33}
  # Format = {skill_id => Ammo_cost}
  Skill_ammo = {73 => 3}
  # Note on Skills: When using Skills the Current Ammo for the equipped
  # weapon will be used. So if Skill 73 is used and Weapon 17 is equipped
  # then Ammo #33 will be used.
end
#----------------------------------------------------------------------------
# Begin Scene_Battle
#----------------------------------------------------------------------------
class Scene_Battle
  # Alias Methods
  alias syn_scene_battle_range make_basic_action_result
  alias syn_scene_battle_skill make_skill_action_result
  #----------------------------------------------------
  # Alias the Attacking method
  #----------------------------------------------------
  def make_basic_action_result
    # Gather the current Ammo Cost
    gather_ammo_cost = Ammo::Range_weapons_id[@active_battler.weapon_id]
    # Gather the Current Ammo
    gather_ammo = Ammo::Range_ammo_id[@active_battler.weapon_id]
    # Check if the Active Battler is attacking and if they are using a ranged weapon
    if @active_battler.current_action.basic == 0 and Ammo::Range_weapons_id.has_key?(@active_battler.weapon_id)
      # Check the Ammo Count
      if $game_party.item_number(gather_ammo) >= gather_ammo_cost
        # Sufficient Ammo, remove item
        $game_party.lose_item(gather_ammo,gather_ammo_cost)
        syn_scene_battle_range
      else
        # Insufficient Ammo
        @help_window.set_text("#{@active_battler.name} cannot attack due to insufficient Ammo", 1)
      end
      # Call Default Code
    else
      syn_scene_battle_range
    end
  end
  #----------------------------------------------------
  # Alias the Skill method
  #----------------------------------------------------
  def make_skill_action_result
    # Gather the current Ammo Cost
    gather_ammo_cost = Ammo::Skill_ammo[@active_battler.current_action.skill_id]
    # Gather Ammo
    gather_ammo = Ammo::Range_ammo_id[@active_battler.weapon_id]
    # Check if the Actor is using a defiend skill
    if Ammo::Skill_ammo.has_key?(@active_battler.current_action.skill_id)
      # Check if Ammo is present
      if $game_party.item_number(gather_ammo) >= gather_ammo_cost
        # Sufficient Ammo, remove item
        $game_party.lose_item(gather_ammo,gather_ammo_cost)
        # Call Default Code
        syn_scene_battle_skill
      else
        # Set Window; Do Nothing
        @help_window.set_text("#{@active_battler.name} cannot attack due to insufficient Ammo", 1)
      end
      # Otherwise SKip the check and call default code
    else
      syn_scene_battle_skill
    end
  end
end
#============================================================================
# Written by Synthesize
# Special Thanks: ~Emo~ for the request
#----------------------------------------------------------------------------
#                            Ammo Requirements
#============================================================================


Usage:
This script may be used in either a commercial project or a free ware project free of charge. However, credit must be present somewhere in the project.

Editing/Distribution:
Feel free to redistribute this post to other boards/websites. Just keep the wording the same. As for editing the script to suite your tastes feel free. Just keep the original header/footer in tact.

If you have any questions or you found a bug, please PM me or make a post with the following:
1.) SDK Version
2.) Other Scripts
3.) Factors of the bug (What did you do to make it happen?)
4.) version
5.) Error Line

Cheers,

Syn
jens009
Sweet Script! Now we can fire only a limited amount of arrows.

Hey Syn, I was just wondering. Is there a script like a Weapon Durability or something like that? You are able to use a weapon a certain amount of times then it will break. Just like an ammo script but you would still be able to repair the weapon. I remember seeing one in Dubealex or in Rmxp.org. I just can't remember.

Nevertheless, Excellent script syn.
Ty
Actually you can do that by making a simple mod to this script. Change it so if the weapon was sued X amount of times then remove the item from the players inventory and add an item of the weapon broken.
Snarfinllama
Wait, I am completely confused - do i make an item called 'Bronze Arrows' etc. or what? and exactly how do I use the custimazation part of it.

Sorry but the comments on this are hard to follow (atleast for me)

huh.gif

EDIT ---------


1 more thing if you dont mind,


does anyone know a possible way to make the weapon ITSELF the ammo

i.e throwing knives for my game.

The module looks like you need an item id.

Synth, can you tell me how i would go about doing this?
KiteDXX
CODE
#----------------------------------------------------------------------------
# Customization Section
#----------------------------------------------------------------------------
module Ammo
  # Format = {weapon_id => Ammo_cost}
  Range_weapons_id = {17 => 1}
  # Format = {weapon_id => Item_id
  Range_ammo_id = {17 => 33}
  # Format = {skill_id => Ammo_cost}
  Skill_ammo = {73 => 3}
  # Note on Skills: When using Skills the Current Ammo for the equipped
  # weapon will be used. So if Skill 73 is used and Weapon 17 is equipped
  # then Ammo #33 will be used.
end


In that section:

-Weapon ID 17 (The 17th weapon in the Database) uses 1 ammo in order to attack.
-Weapon ID 17 (The 17th weapon in the Database) uses Item ID 33 (The 33rd item in the Database) as ammo.
-Skill ID 73 (The 73rd skill in the Database) requires 3 ammo to use. The item ammo that is depleted to use Skill 73 is the weapon that you have equipped when you use it.

In order to add more weapons and ammo requirements to the script, you would add new sets to the hash. For example, if I wanted to add Weapon ID 18 to use 4 of Item ID 34 as ammo, I would change the section like so:

CODE
Range_weapons_id = {17 => 1, 18 => 4}
Range_ammo_id = {17 => 33, 18 => 34}


You basically add a comma, then add the ID of the weapon, a "=>", then the ID of the item (or the quantity you want to deplete in order to use the weapon, depending on which section you are in).

If you were to use the example addition I gave you, Weapon ID 18 would be "Bronze Bow" while Item ID 34 would be "Bronze Arrows". You would require 4 "Bronze Arrows" in order to attack with "Bronze Bow". You can freely change the numbers in the example to adapt to your own project.

As for the other question, that function does not exist in the script. However, it would be viable to just have something like "Throwing Knife Satchel" for the weapon and "Throwing Knife" as the item used. Otherwise, you would have to make additions or modifications to the script itself, and I'm not truly advanced with scripts to know how to do that. :/
Alrian
Hi guys I'm new here and I wanted to know if there is any chance of this Script being usefull in RPG Maker VX confused.gif
If I wrote anything wrong, please forgive me cause I'm a brazilian maker ok ? thumbsup.gif
Anyway thanks for the lost time rolleyes.gif
Ty
It could be useful in RMVX, but it won't work in RMVX the way it is now.
D3wil666
in my game is a lot of bows and when i copy script it don't work. Bow shots when character don't have ammo
saninu
Beautiful Script. =D
Ceegamus
So, would it be possible to include more than one ammo for a weapon?
Krenic-The-Hedgehog
dude, it works, but only for ONE weapon!
I tryed to double it with (a diferent wapon of course) but it just keep saying Errors!
help please cuz I need for more than 3 weapons in my F1 game
Trind
So... wait... I'm completely new at the whole scripting part.

Do I just create one new script in the Script Editor and paste all that in there, or do I have to cut parts out and paste them in different areas of the Script Editor?

Oh, by the way, I have RPG Maker VX. If this is for XP, how do I modify the script to run in VX?
vVTalonVv
I'm having a tough time understanding this. Could somebody possibly explain it in simpler terms? I have NO scripting experience whatsoever so its going to take me some time to learn.

Pretty much for my game idea, I need to have ammo and such (its a zombie survival horror). Is it possible to make it so that there are clips of ammunition for lets say... a pistol with 16 shots? And when the ammo is used up, how can I have it so that it takes a round/turn to reload?

Also, is it possible to switch weapons during a battle? The point of this would be if your character ran out of ammo for gun A, he/she could switch to gun B or his/her knife.


To anyone who can help me with this questions, it would be greatly appreciated. Thanks again!
funkidud3
can you just make ammo for skills only, because i want to have the close range weapons as the primary weapons and long range weapons as skills
jens009
QUOTE (funkidud3 @ Apr 3 2008, 11:54 PM) *
can you just make ammo for skills only, because i want to have the close range weapons as the primary weapons and long range weapons as skills

Hmm, this script may not be what you are looking for. Because the skills and weapons work together within the code. as stated in this line:
CODE
  # Note on Skills: When using Skills the Current Ammo for the equipped
  # weapon will be used. So if Skill 73 is used and Weapon 17 is equipped
  # then Ammo #33 will be used.


You should try Dervvulfman's Skills that Consume Items (DBS Version) instead.
funkidud3
Thanks jens
Blaz3r
can someone edit this script?
you know, more weapons with ammo, not only one ^^
or, how do it? ^^

Edit: sorry, it's easy to do that ^^' never mind
deathreaper123
Is it only me...
I dunno, I done everything as it needed to be, but I can't find the effect of the script in the game...

Not in database, not in game itself...
please help!
Krenic-The-Hedgehog
sorry repeating this but I really need help on this one...

QUOTE
dude, it works, but only for ONE weapon!


I tried to double the script code, but the RM XP makes me delete sme lines or modify
I copied your whole code, and I modified my parts (which means, the IDs of the weapons) but I can't seem to do it on more weapons, only on one...

thank you
Ty
Well, time to answer some questions. Sorry for the looooong delay.

QUOTE
dude, it works, but only for ONE weapon!
I tryed to double it with (a diferent wapon of course) but it just keep saying Errors!
help please cuz I need for more than 3 weapons in my F1 game


In the Configuration section of the script, you define which weapons use which ammo and how much ammo they use. You add additional weapons by making changes like this:
CODE
# Format = {weapon_id => Ammo_cost}
Range_weapons_id = {17 => 1}

The above is the default configuration line of code. Now all you do is add a comma (,) and insert a new weapon. Like so:
CODE
# Format = {weapon_id => Ammo_cost}
Range_weapons_id = {17 => 1, 21 => 1}

Now what we did is added a new option inside the Hash. The Hash is different, yet similar to the array (array = [0,1,2,3]). The biggest difference is that data inside a hash cannot be changed. This means you cannot do things like hash = {1 => 1} += 1. The way the Hash works is that is has a trigger value and a return value. When the trigger value is called somewhere in a script, the result will be the return value. So take the following example:
CODE
class something
def something
Hash = {"Yellow" => "Blue"}
p hash["Yellow"]
end
end


In the example above, the hash 'hash' is storing the information "Yellow." So when the information stored within the hash is called, in this case, "Yellow" is the trigger value, the result will be "Blue." After saying this, we can conclude that 'Ammo Requirements' searching the hash specified in the Configuration file for the weapon ID the actor currently has equipped, if the value is in the configuration, it will return the amount of ammo the weapon needs to fire.

The script can have an unlimited amount of weapons that require ammo, all that is needed is a small modification to the configuration section.

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

@Trend: This will not work for RPG Maker VX.


JuliusHawke
Can you post a demo? I'd understand the script more if I could examine it in action.
EchoRose13
QUOTE (KiteDXX @ Feb 15 2008, 12:55 PM) *
CODE
#----------------------------------------------------------------------------
# Customization Section
#----------------------------------------------------------------------------
module Ammo
  # Format = {weapon_id => Ammo_cost}
  Range_weapons_id = {17 => 1}
  # Format = {weapon_id => Item_id
  Range_ammo_id = {17 => 33}
  # Format = {skill_id => Ammo_cost}
  Skill_ammo = {73 => 3}
  # Note on Skills: When using Skills the Current Ammo for the equipped
  # weapon will be used. So if Skill 73 is used and Weapon 17 is equipped
  # then Ammo #33 will be used.
end


In that section:

-Weapon ID 17 (The 17th weapon in the Database) uses 1 ammo in order to attack.
-Weapon ID 17 (The 17th weapon in the Database) uses Item ID 33 (The 33rd item in the Database) as ammo.
-Skill ID 73 (The 73rd skill in the Database) requires 3 ammo to use. The item ammo that is depleted to use Skill 73 is the weapon that you have equipped when you use it.

In order to add more weapons and ammo requirements to the script, you would add new sets to the hash. For example, if I wanted to add Weapon ID 18 to use 4 of Item ID 34 as ammo, I would change the section like so:

CODE
Range_weapons_id = {17 => 1, 18 => 4}
Range_ammo_id = {17 => 33, 18 => 34}


You basically add a comma, then add the ID of the weapon, a "=>", then the ID of the item (or the quantity you want to deplete in order to use the weapon, depending on which section you are in).

If you were to use the example addition I gave you, Weapon ID 18 would be "Bronze Bow" while Item ID 34 would be "Bronze Arrows". You would require 4 "Bronze Arrows" in order to attack with "Bronze Bow". You can freely change the numbers in the example to adapt to your own project.

As for the other question, that function does not exist in the script. However, it would be viable to just have something like "Throwing Knife Satchel" for the weapon and "Throwing Knife" as the item used. Otherwise, you would have to make additions or modifications to the script itself, and I'm not truly advanced with scripts to know how to do that. :/


I keep getting a syntax error on the lines I modify, exactly as you said to. Whats going on with it?
I modify with "{1 => 2, 2 =>2}" as an example. But it says there is a syntax error on the line in which I use this.
monzdname
I really like this script and would like to use it, but I've encountered some problems.
At first, everything was ok, the script was running well and every time I attack, an ammo is consumed. As seen in my item menu.

Now here comes the problem..
First, when i used that skill thingy, wherein the battler consumes ammo when using skill, the ammo is not consumed. I've tested a gun skill
wherein it must consume 5 bullets. But it doesn't. I dont know what went wrong, coz the database are ok (the numbers corresponding to my database in the script) and the normal attack thing went fine anyway so why would not it work on skill..

Here's my bigger problem..
The attack thing was working perfectly fine, until i deplete my ammo. Every time I attack with my ammo depleted, instead of saying "not enough ammo" or something like that. I get a syntax error. Is this compatible with Minkoff/DerVVulfman's Animated Battller?? Coz I'm using it and the syntax error occured at "Battle Scene" script around line 254 of that animated battler.

Well thats it. Hope this can be fixed, coz I dont have any idea on scripting..


Night_Runner
@> monzdname: Welcome to the forums.

For your first problem, I can't replicate it. I used a skill enough times to depete my ammo, and it then stoped attacking, just like it should.
I then tried a few combinations of using the skill with the weapon, and it still worked.
You definitely don't delete in ammo for the weapon you have equipped, when using skills?


For your second problem, there's no need to credit fro this, I only wrote 1 extra line
[Show/Hide] Night_Runner's Ammo Requirements Edit
CODE
#============================================================================
#                            Syn's Ammo Requirements  
#----------------------------------------------------------------------------
# Written by Synthesize
# Version 1.00
# August 15, 2007
# Tested with SDK 2.1
#============================================================================
#----------------------------------------------------------------------------
# Customization Section
#----------------------------------------------------------------------------
module Ammo
  # Format = {weapon_id => Ammo_cost}
  Range_weapons_id = {17 => 1, 18=> 2}
  # Format = {weapon_id => Item_id
  Range_ammo_id = {17 => 33, 18=> 34}
  # Format = {skill_id => Ammo_cost}
  Skill_ammo = {73 => 1}
  # Note on Skills: When using Skills the Current Ammo for the equipped
  # weapon will be used. So if Skill 73 is used and Weapon 17 is equipped
  # then Ammo #33 will be used.
end
#----------------------------------------------------------------------------
# Begin Scene_Battle
#----------------------------------------------------------------------------
class Scene_Battle
  # Alias Methods
  alias syn_scene_battle_range make_basic_action_result
  alias syn_scene_battle_skill make_skill_action_result
  #----------------------------------------------------
  # Alias the Attacking method
  #----------------------------------------------------
  def make_basic_action_result
    # Gather the current Ammo Cost
    gather_ammo_cost = Ammo::Range_weapons_id[@active_battler.weapon_id]
    # Gather the Current Ammo
    gather_ammo = Ammo::Range_ammo_id[@active_battler.weapon_id]
    # Check if the Active Battler is attacking and if they are using a ranged weapon
    if @active_battler.current_action.basic == 0 and Ammo::Range_weapons_id.has_key?(@active_battler.weapon_id)
      # Check the Ammo Count
      if $game_party.item_number(gather_ammo) >= gather_ammo_cost
        # Sufficient Ammo, remove item
        $game_party.lose_item(gather_ammo,gather_ammo_cost)
        syn_scene_battle_range
      else
        # Insufficient Ammo
        @help_window.set_text("#{@active_battler.name} cannot attack due to insufficient Ammo", 1)
        @active_battler.current_action.basic = 3
      end
      # Call Default Code
    else
      syn_scene_battle_range
    end
  end
  #----------------------------------------------------
  # Alias the Skill method
  #----------------------------------------------------
  def make_skill_action_result
    # Gather the current Ammo Cost
    gather_ammo_cost = Ammo::Skill_ammo[@active_battler.current_action.skill_id]
    # Gather Ammo
    gather_ammo = Ammo::Range_ammo_id[@active_battler.weapon_id]
    # Check if the Actor is using a defiend skill
    if Ammo::Skill_ammo.has_key?(@active_battler.current_action.skill_id)
      # Check if Ammo is present
      if $game_party.item_number(gather_ammo) >= gather_ammo_cost
        # Sufficient Ammo, remove item
        $game_party.lose_item(gather_ammo,gather_ammo_cost)
        # Call Default Code
        syn_scene_battle_skill
      else
        # Set Window; Do Nothing
        @help_window.set_text("#{@active_battler.name} cannot attack due to insufficient Ammo", 1)
      end
      # Otherwise SKip the check and call default code
    else
      syn_scene_battle_skill
    end
  end
end
#============================================================================
# Written by Synthesize
# Special Thanks: ~Emo~ for the request
#----------------------------------------------------------------------------
#                            Ammo Requirements
#============================================================================
monzdname
@Night_Runner

Thanks, about that first problem, i already solved it and is working perfectly fine.
Now I'm gonna try the script you posted and hope it'll work. Thank you
mafioso
Hello, need to ask one thing..
Is this compatible with Cogwheel's RTAB?
Because everytime i paste this script, an error occurs.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.