Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Ammo Requirements
Ty
post Aug 15 2007, 01:09 PM
Post #1


Level 38
Group Icon

Group: +Gold Member
Posts: 1,007
Type: Scripter
RM Skill: Undisclosed




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

This post has been edited by Ty: Sep 4 2010, 05:46 AM


__________________________
My Script Demo link broken? Looking for old scripts? Go here:
http://synthesize.4shared.com
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
KiteDXX
post Feb 15 2008, 11:55 AM
Post #2


Level 7
Group Icon

Group: Member
Posts: 96
Type: Event Designer
RM Skill: Skilled




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. :/


__________________________
Go to the top of the page
 
+Quote Post
   
EchoRose13
post Apr 26 2010, 11:29 PM
Post #3


Level 1
Group Icon

Group: Member
Posts: 14
Type: Event Designer
RM Skill: Intermediate




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.
Go to the top of the page
 
+Quote Post
   
monzdname
post Dec 7 2010, 05:27 PM
Post #4


Level 1
Group Icon

Group: Member
Posts: 10
Type: None
RM Skill: Beginner




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..


Go to the top of the page
 
+Quote Post
   

Posts in this topic
- Synthesize   Ammo Requirements   Aug 15 2007, 01:09 PM
- - jens009   Sweet Script! Now we can fire only a limited a...   Aug 18 2007, 02:59 PM
- - Synthesize   Actually you can do that by making a simple mod to...   Aug 18 2007, 05:17 PM
- - Snarfinllama   Wait, I am completely confused - do i make an item...   Feb 15 2008, 07:18 AM
- - Alrian   Hi guys I'm new here and I wanted to know if t...   Feb 17 2008, 03:31 PM
- - Synthesize   It could be useful in RMVX, but it won't work ...   Feb 18 2008, 11:56 AM
- - D3wil666   in my game is a lot of bows and when i copy script...   Mar 8 2008, 07:22 AM
- - saninu   Beautiful Script. =D   Mar 20 2008, 12:58 PM
- - Ceegamus   So, would it be possible to include more than one ...   Mar 21 2008, 05:03 AM
- - Krenic-The-Hedgehog   dude, it works, but only for ONE weapon! I try...   Mar 27 2008, 12:23 PM
- - Trind   So... wait... I'm completely new at the whole ...   Mar 27 2008, 06:58 PM
- - vVTalonVv   I'm having a tough time understanding this. Co...   Apr 2 2008, 02:54 PM
- - funkidud3   can you just make ammo for skills only, because i ...   Apr 3 2008, 11:40 PM
|- - jens009   QUOTE (funkidud3 @ Apr 3 2008, 11:54 PM) ...   Apr 4 2008, 11:24 AM
|- - funkidud3   Thanks jens   Apr 4 2008, 02:13 PM
- - Blaz3r   can someone edit this script? you know, more weapo...   Jun 23 2008, 02:32 AM
- - deathreaper123   Is it only me... I dunno, I done everything as it ...   Jul 2 2008, 04:52 AM
- - Krenic-The-Hedgehog   sorry repeating this but I really need help on thi...   Jul 2 2008, 01:27 PM
- - Ty   Well, time to answer some questions. Sorry for the...   Jul 11 2008, 12:12 PM
|- - JuliusHawke   Can you post a demo? I'd understand the script...   Nov 29 2009, 01:33 PM
- - Night_Runner   @> monzdname: Welcome to the forums. For your ...   Dec 8 2010, 12:07 AM
|- - monzdname   @Night_Runner Thanks, about that first problem, i...   Dec 8 2010, 09:11 PM
- - mafioso   Hello, need to ask one thing.. Is this compatible ...   Jan 19 2011, 08:29 PM


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 21st May 2013 - 11:21 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker