Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Simple Ammunition

Status
Not open for further replies.
I need a script that deals with ammo. Basically the way I want it to work is that when you have Guns (A, B, or C) equipped, you need to have a unit of ammo for EACH attack/skill. So when you attack or use a skill, it has to decrease 1 ammo, but only when the character with the gun attacks.
Features Needed
  • Player needs ammo to attack with guns/bows.
  • Script can be set to decrease the ammo by any number, say multishot uses 2 ammo. It needs to decrease by two, so essentially a place in the script to set up individual skills and their costs.
  • Weapons that require ammo need to be able to be specified.
  • Needs to be compatible with the SDK.

If anyone is willing to do this I would much appreciate it because I need it to create a realistic game. Please post here or PM me if you would liek to attempt it. It doesnt seem that hard to me, but if you can suggest an alternative, such as an edit, post it here. The above features absolutely MUST be included. Thanks to whoever tries this. :)

Edit: something like this: http://www.rmxp.org/forums/showthread.php?t=26589 but it needs to expend ammo from your inventory/bag.
 
Sorry for the delay, here is your request:

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
#============================================================================

Place in a new script above Main.

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
 
Syn thats the bomb. I just have 1 question. If I want to add say, weapons that need 2 ammo, do I need to make another line with another {}? Otherwise I believe all I have to do is make commas liek this {21, 22, 23 =>1} if I want them all to use 1 ammo. Correct?
 
Use only one array but separate it with a comma, so like this:

{17 => 1, 18 => 1, 19 => 2, 20 => 2}

When the array is called it looks for the Weapons ID (The first number) and then returns (=>) the second number, which then becomes the number of ammo is needed to attack
 
This topic has been resolved. If ~Emo~ or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top