Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

2 Pages V   1 2 >  
Closed TopicStart new topic
> 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
   
jens009
post Aug 18 2007, 02:59 PM
Post #2


L Did you know? Death gods... only eat apples
Group Icon

Group: +Gold Member
Posts: 2,976
Type: Scripter
RM Skill: Skilled




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.

This post has been edited by jens009: Aug 18 2007, 02:59 PM


__________________________

My RMXP Project:


Farewell RRR. =]
Go to the top of the page
 
+Quote Post
   
Ty
post Aug 18 2007, 05:17 PM
Post #3


Level 38
Group Icon

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




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.


__________________________
My Script Demo link broken? Looking for old scripts? Go here:
http://synthesize.4shared.com
Go to the top of the page
 
+Quote Post
   
Snarfinllama
post Feb 15 2008, 07:18 AM
Post #4


Level 4
Group Icon

Group: Member
Posts: 51
Type: Event Designer
RM Skill: Undisclosed




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?

This post has been edited by Snarfinllama: Feb 15 2008, 07:31 AM
Go to the top of the page
 
+Quote Post
   
KiteDXX
post Feb 15 2008, 11:55 AM
Post #5


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
   
Alrian
post Feb 17 2008, 03:31 PM
Post #6



Group Icon

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




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
Go to the top of the page
 
+Quote Post
   
Ty
post Feb 18 2008, 11:56 AM
Post #7


Level 38
Group Icon

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




It could be useful in RMVX, but it won't work in RMVX the way it is now.


__________________________
My Script Demo link broken? Looking for old scripts? Go here:
http://synthesize.4shared.com
Go to the top of the page
 
+Quote Post
   
D3wil666
post Mar 8 2008, 07:22 AM
Post #8


Level 3
Group Icon

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




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
Go to the top of the page
 
+Quote Post
   
saninu
post Mar 20 2008, 12:58 PM
Post #9


Level 2
Group Icon

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




Beautiful Script. =D


__________________________
All the Bacon in the world couldn't save you now...
Go to the top of the page
 
+Quote Post
   
Ceegamus
post Mar 21 2008, 05:03 AM
Post #10



Group Icon

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




So, would it be possible to include more than one ammo for a weapon?
Go to the top of the page
 
+Quote Post
   
Krenic-The-Hedge...
post Mar 27 2008, 12:23 PM
Post #11


Level 3
Group Icon

Group: Member
Posts: 37
Type: Developer
RM Skill: Intermediate




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


__________________________
The percentages I present below go from -100% to 100% of completion having 0 of percentage the beginning of the actual making.

Projects in the making (that I'll surely work on only by Summer vacations):
RPG Maker XP
-Keyaku's Journey: Legends Live = 20% ====> Rewriting story script (not code) and most characters dialogues...
-Formula 1: Quicker than the end (Title will SURELY change) = -20% ===> Making character graphics...

iPhone Unity
-Avenger = -75% ===> Compiling story, writing script (not code), ideas on adapting it onto the iPhone scene (with actual code that'll bring visual effects)...
Go to the top of the page
 
+Quote Post
   
Trind
post Mar 27 2008, 06:58 PM
Post #12



Group Icon

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




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?

This post has been edited by Trind: Mar 27 2008, 07:22 PM
Go to the top of the page
 
+Quote Post
   
vVTalonVv
post Apr 2 2008, 02:54 PM
Post #13


Level 2
Group Icon

Group: Member
Posts: 25
Type: None
RM Skill: Undisclosed




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!
Go to the top of the page
 
+Quote Post
   
funkidud3
post Apr 3 2008, 11:40 PM
Post #14



Group Icon

Group: Member
Posts: 2
Type: None
RM Skill: Skilled




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

This post has been edited by funkidud3: Apr 4 2008, 03:12 AM
Go to the top of the page
 
+Quote Post
   
jens009
post Apr 4 2008, 11:24 AM
Post #15


L Did you know? Death gods... only eat apples
Group Icon

Group: +Gold Member
Posts: 2,976
Type: Scripter
RM Skill: Skilled




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.


__________________________

My RMXP Project:


Farewell RRR. =]
Go to the top of the page
 
+Quote Post
   
funkidud3
post Apr 4 2008, 02:13 PM
Post #16



Group Icon

Group: Member
Posts: 2
Type: None
RM Skill: Skilled




Thanks jens
Go to the top of the page
 
+Quote Post
   
Blaz3r
post Jun 23 2008, 02:32 AM
Post #17


Level 3
Group Icon

Group: Member
Posts: 33
Type: None
RM Skill: Skilled




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

This post has been edited by Blaz3r: Jun 25 2008, 02:22 AM


__________________________
Be a part of Adventure Quest Worlds History!


Go to the top of the page
 
+Quote Post
   
deathreaper123
post Jul 2 2008, 04:52 AM
Post #18



Group Icon

Group: Member
Posts: 2
Type: Developer
RM Skill: Beginner




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!
Go to the top of the page
 
+Quote Post
   
Krenic-The-Hedge...
post Jul 2 2008, 01:27 PM
Post #19


Level 3
Group Icon

Group: Member
Posts: 37
Type: Developer
RM Skill: Intermediate




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


__________________________
The percentages I present below go from -100% to 100% of completion having 0 of percentage the beginning of the actual making.

Projects in the making (that I'll surely work on only by Summer vacations):
RPG Maker XP
-Keyaku's Journey: Legends Live = 20% ====> Rewriting story script (not code) and most characters dialogues...
-Formula 1: Quicker than the end (Title will SURELY change) = -20% ===> Making character graphics...

iPhone Unity
-Avenger = -75% ===> Compiling story, writing script (not code), ideas on adapting it onto the iPhone scene (with actual code that'll bring visual effects)...
Go to the top of the page
 
+Quote Post
   
Ty
post Jul 11 2008, 12:12 PM
Post #20


Level 38
Group Icon

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




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.




__________________________
My Script Demo link broken? Looking for old scripts? Go here:
http://synthesize.4shared.com
Go to the top of the page
 
+Quote Post
   

2 Pages V   1 2 >
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: 17th June 2013 - 08:41 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker