Save-Point
Ammo Script - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Archives (https://www.save-point.org/forum-105.html)
+--- Forum: Creation Asylum Archives (https://www.save-point.org/forum-90.html)
+---- Forum: Scripts & Code Snippets (https://www.save-point.org/forum-92.html)
+----- Forum: RPG Maker XP Code (https://www.save-point.org/forum-93.html)
+------ Forum: Enhancement/Modification Scripts (https://www.save-point.org/forum-98.html)
+------ Thread: Ammo Script (/thread-6485.html)



Ammo Script - Dubealex - 05-27-2005

Ammo Script Version 1
Dubealex
May 27 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


This is a basic ammo script. It will check who is attacking, with which weapon, and it will decrease an item number that is linked with that weapon.

It also checks during the attack menu selection if you still have ammo for the weapon you have equiped, and if not, the attack option is disabled.

What happen afterward, and what the user can do, is up to you.

PART 1

OPen up SCENE_BATTLE4 and find the following line:

Code:
target.damage_pop = true



It should be around line #433. Then, BELOW it, add the following code:

Code:
#--------------------------------------------------------------------------
#DUBEALEX AMMO SCRIPT
#--------------------------------------------------------------------------
active_actor=@active_battler.index #Findind who is attacking

if @active_battler.is_a?(Game_Actor) and @active_battler.current_action.kind == 0
    actor=$game_party.actors[active_actor] #Shortcut
    ammo_type=actor.weapon_id #Shortcut again
  
    case ammo_type #Checking the Weapon ID
        when 1 #When weapon ID "number" is used...
            $game_party.lose_item(1, 1) #Decrease ammo: (Item ID, Number to decrease)
        when 2
            $game_party.lose_item(2, 1)
    end
end

#--------------------------------------------------------------------------
#END OF AMMO SCRIPT
#--------------------------------------------------------------------------



The only part you need to customize for your game in this block is the following part:

Code:
case ammo_type #Checking the Weapon ID
          when 1 #When weapon ID "number" is used...
            $game_party.lose_item(1, 1) #Decrease ammo: (Item ID, Number to decrease)
          when 2  
            $game_party.lose_item(2, 1)
        end



This is where you define which wepon ID# is linked with which Item ID#, and the amount to decrease on each attack. It's simple, you just add/remove more WHEN lines in the CASE block, and you change the numbers. The comments in the code should be enough to guide you.

- Your weapon ID and Ammo ID must be the same. It means that if your weapon SHOTGUN have ID#13, the ammo for the SHOTGUN must be ID#13 too.

PART 2

Open up SCENE_BATTLE3, and find the following line:

Code:
def update_phase3_basic_command


It should be around line #109. Then, BELOW it, add the following code:

Code:
#DUBEALEX AMMO SCRIPT - CHECK FOR AMMO
active_actor=@active_battler.index
actor=$game_party.actors[active_actor]
ammo_type=actor.weapon_id
weapon_name=$data_weapons[$game_actors[active_actor+1].weapon_id].name
ammo_count=$game_party.item_number(ammo_type)
can_attack=true
if ammo_count <= 0
    can_attack=false
    @help_window.set_text("Ammo Left: " + weapon_name + " " + "(NO AMMO)")
else
    @help_window.set_text("Ammo Left: " + weapon_name + " " + "[" + ammo_count.to_s + "]")
end
#END OF CHECKING FOR AMMO


This block actually checks your ammo before you can execute a normal attack, if you have no ammo, the ATTACK selection is disabled. This block also shows to the player at the top of the screen which weapon is equiped, and how much ammo is left in the weapon. You have nothing to customize in this block, unless you know how to script and want to enhance it with something, like more colors or images or even gradient bars.

PART 3

Then, in the same page (SCENE_BATTLE3), find the following line:

Code:
case @actor_command_window.index



It should be around line #137. Then, you should see, just BELOW it a line that says:

Code:
when 0  # 攻撃


You need to add the following code just BELOW the WHEN line:


Code:
#LOCKING ATTACK IF NO AMMO
unless can_attack
    $game_system.se_play($data_system.buzzer_se)
    return
end
#END OF LOCKING ATTACK



You dont need to change anything in that block. Thius block will ensure that when you are out of ammo, you cannot attack with the weapon.

CONCLUSION

There, you have a basic ammo script. What you do with it from this point on is up to you. Have fun !