[XP] Weapon Charge

Started by chaucer, February 20, 2015, 11:10:09 pm

Previous topic - Next topic

chaucer

February 20, 2015, 11:10:09 pm Last Edit: May 22, 2015, 06:27:13 am by chaucer
Weapon Charge
Authors: Chaucer
Version: 1.08
Type: Blizz-ABS Plugin
Key Term: Blizz-ABS Plugin



Introduction

This Script allows players to charge up they're weapons while holding the attack button, similalar to games like zelda & Secret of Mana etc
Upon release the weapons will trigger a skill.


Features


  • Can use custom graphics for charging HUD.

  • Can Set Sound Effect to play when charging is complete.

  • Can Add a charging Sprite Graphic for your actor.




Screenshots
None.


Script
Spoiler: ShowHide

=begin
Script Version:
1.08
Script Description:
This script is an add-on for Blizz abs, it allows weapons to "charge up"
when holding down the attack button, similar to many ABS games, when the
charge time is fulfilled then a skill will be released when the attack
button is release.

Script Instructions:
See module Skill_Charges for skill setup.

***Setting Images***
Background will be used as the background for the charging hud.
Charging is used as the bar that will fill up as the weapon charges.
Bar_Off_X is to center the X coordinate of the Charging bar on the background.
Bar_Off_Y same as above except for the Y coordinate.
Charging_Sprite is used to determine wether to use a character sprite or not
set to true or false.
Charging Sprites must be named as so.
ActorsName_charge_weapon_type(by default weapon type is 1 in blizz abs)
Weapon Types:
1.sword / axe / claws / unarmed / etc. (damages in close front)
2.spear / lance (damages only in front)
3.flail (distant weapon, does not damage close enemies, front)
4.boomerang (returning projectile weapon, front)
5.bow and arrow / gun / shuriken (non-returning projectile, NO consumption)
6.bow and arrow / gun (non-returning projectile, consumes AMMUNITION)
7.shuriken (non-returning projectile, consumes ITSELF)

***Sound Settings***
Sound_Effect, is the sound effect to play on charging completion.
Repeat_Sound, if set to true will replay the sound effect
while the button is held.
 
***Setting Skills for each weapon***
setup your skills as follows.
when [weapon_id] then return [skill_id]
 
Script Notes:
-Opening the menu will reset the timer upon exit.

-If using a bow and arrow(weapon that consumes items), it will consume the
lowest id item that the weapon can use for ammo(if you have any).

=Script Author=
  Chaucer
=end

module Skill_Charges
 #how many frames the timer will count before fully charged
 Timer = 40
 #Charging Background Sprite
 Background = 'Charging_Background'
 #Charging Bar
 Charging = 'Charging'
 #the offset(if needed) of the hud bar
 Bar_Off_X = 4
 Bar_Off_Y = 4
 #wether or not the sprite name will consider the weapon type.
 Weapon_Type = false
 #Use a charging sprite, set to true of false.
 Charge_Sprite = true
 #Sprite Extension name
 Name = '_charge'
 #the sound effect to be played when skill is ready.
 Sound_Effect = 'Charge_Ready'
 #if sound effect should repeat
 Repeat_Sound = true
 
 #Setup for weapons.
 def self.weapon_charge(weapon_id)
   case weapon_id
  #when weapon_id then return skill id
   when 1 then return 1
   when 2 then return 2
   when 3 then return 3
   when 4 then return 4
   when 5 then return 5
   when 6 then return 6
   end
   return 1
 end

end
#==============================================================================
#--------------------------- Charge Skills ------------------------------------
#- Class Dealing with Charging Skills.                                        -
#==============================================================================
class Charge_Skills
#------------------------------------------------------------------------------
#Initialize
#------------------------------------------------------------------------------
 def initialize
   #get variables needed
   @delay = 60
   @dummy = 60
   @ox = Skill_Charges::Bar_Off_X
   @oy = Skill_Charges::Bar_Off_Y
   @player = $game_party.actors[0]
   @counter = Skill_Charges::Timer
   @player_weapon = @player.weapon_id
   @sprites = Skill_Charges::Charge_Sprite
   @charge_speed = BlizzABS::Config::SNEAK_SPEED
   @player_speed = BlizzABS::Config::NORMAL_SPEED
   @type = BlizzABS::Weapons.type(@player_weapon)
   @original_sprite = $game_party.actors[0].character_name
 end
 
#------------------------------------------------------------------------------
#Update
#------------------------------------------------------------------------------
 def update
   #update players info.
   update_player
   #update the delay timer.
   update_delay
   #update the charge timer.
   update_timer
   #update the hud.
   update_hud
   #update sound effect.
   update_sound
   #update players sprite.
   update_sprite if @sprites
   dispose
 end
 
#------------------------------------------------------------------------------
#Update Player information
#------------------------------------------------------------------------------
 def update_player
   
   #when selecting a different character.
   if $game_party.actors[0] != @player
     #dispose of any previous charging sprites
     @stunned = true
     #change the player variable.
     @player = $game_party.actors[0]
     #change sprite variable.
     @original_sprite = $game_party.actors[0].character_name
   end
   
   #when selecting a different weapon and player is the same.
   if @player.weapon_id != @player_weapon
     #update the players weapon variable.
     @player_weapon = @player.weapon_id
     #update the weapon type
     @type = BlizzABS::Weapons.type(@player_weapon)
   end
   
   #checks if the player is charging an attack.
   if @delay == 0
     #changes speed to sneak speed.
     $game_player.normal_speed = @charge_speed if $game_player.normal_speed != @charge_speed
     #checks if the charging timer has finished and release attack button.
     if @timer == @counter && !Input.press?(Input::Attack)
       skill_id = Skill_Charges.weapon_charge(@player_weapon) if skill_id == nil
       $game_player.character_name_org = @original_sprite if $game_player.character_name_org != @original_sprite
       $game_player.use_skill($data_skills[skill_id], true)
     end
   end
 end
 
#------------------------------------------------------------------------------
#Update Delay Timer information
#------------------------------------------------------------------------------
 def update_delay
   #checks if battler size is greater than zero
   if $game_system.battlers_number > 0
     #checks if the player can use attack.
     if $game_player.attack_can_use?
       #if player is holding the attack button
       if Input.press?(Input::Attack)
         #calls to check which states are stuns.
         check_states if @stuns == nil
         #checks if the player has one of those states.
         @stuns.each do |n|
           #if player's stunned reset delay timer.
           if @player.states.include?(n)
             @stunned = true
           else
             #otherwise, countdown the delay
             @delay -= 1 if @delay != 0 unless @delay == 0
           end
         end
       end
     end
   end
 end
 
#------------------------------------------------------------------------------
# Checks the states database for stun states.
#------------------------------------------------------------------------------
 def check_states
   #checks the players states to see if he's stunned
   @stuns = [] if @stuns == nil
   if @stuns == []
     for i in 1...$data_states.size
        if $data_states[i].restriction == 4
          @stuns.push($data_states[i].id)
        end
     end
   end
 end
 
#------------------------------------------------------------------------------
# Update the timer for charging.
#------------------------------------------------------------------------------
 def update_timer
   #if the delay has finished
   if @delay == 0
     #if still holding the attack button
     if Input.press?(Input::Attack)
       @timer = 0 if @timer == nil
       @timer += 1 unless @timer == @counter
     end
   end
 end
 
#------------------------------------------------------------------------------
# Updates the sound effect for charging.
#------------------------------------------------------------------------------
 def update_sound
   #if skill is charged up
   if @timer == @counter
     #set repeat timer.
     if @repeat == nil
       @repeat = 0
     end
     #if repeat sound
     if Skill_Charges::Repeat_Sound
       if @repeat == @counter
         @repeat = nil
         @play = nil
       else
         @repeat += 1
       end
     end
     #setup sound
     sound = Skill_Charges::Sound_Effect if sound == nil
     #if the sound hasn't played
     if @play == nil
       #play the sound effect
       Audio.se_play("Audio/SE/" + sound, $game_variables[8], 150)
       @play = true
     end
   end
 end
#------------------------------------------------------------------------------
# Updates the players sprite.
#------------------------------------------------------------------------------
 def update_sprite
   if @delay == 0
     if @timer > 0
       #reset the players sprite so it doesn't cause any issues.
       $game_player.character_name_org = @original_sprite if @spr_refresh == nil
       @spr_refresh = true
       @ext = Skill_Charges::Name if @ext = nil
       #if the sprite has been reset.
       if @spr_refresh == true
         #set the sprite to charging sprite.
         if Skill_Charges::Weapon_Type
           $game_player.character_name_org = @original_sprite + @ext + '_' + @type if
           $game_player.character_name_org != @original_sprite + @ext + '_' + @type
         else
           $game_player.character_name_org = @original_sprite + @ext if
           $game_player.character_name_org != @original_sprite + @ext
         end
       end
     end
   end
 end
 
#------------------------------------------------------------------------------
#Update for the HUD.
#------------------------------------------------------------------------------
 def update_hud
   if @delay == 0
     #if images are nil
       #setup images and variables needed.
       @background = RPG::Cache.picture(Skill_Charges::Background) if @background == nil
       @bar        = RPG::Cache.picture(Skill_Charges::Charging) if @bar == nil
       @bw1,@bh1 = @background.width,@background.height if @bw1 == nil || @bh1 == nil
       @bw2,@bh2 = @bar.width,@bar.height if @bw2 == nil || @bh2 == nil
       rect1 = Rect.new(0,0,@bw1,@bh1) if rect1 == nil
       rect2 = Rect.new(0,0,@bw2,@bh2) if rect2 == nil
       @x = (@background.width / 2) if @x1 == nil
       @y = (@background.height / 2) - 16 if @y1 == nil
     
     #create sprites if not created.
     if @bhud == nil
       #create background
       @bhud = Sprite.new
       @bhud.bitmap = Bitmap.new(@bw1,@bh1)
       @bhud.bitmap.blt(0, 0, @background, rect1)
       @bhud.x = $game_player.screen_x - @x
       @bhud.y = $game_player.screen_y - @y
       @bhud.z = $game_player.screen_z
     #if it is created
     else
       @bhud.x = $game_player.screen_x - @x
       @bhud.y = $game_player.screen_y - @y
       @bhud.z = $game_player.screen_z
     end
   
     #creates bar when needed
     if @bhud2 == nil
       @bhud2 = Sprite.new
     #if already created
     else
       if @timer > 0 && @timer != @counter
         w = @timer * @counter / @counter
         @bhud2.bitmap = Bitmap.new(w,@bh2)
         @bhud2.bitmap.blt(0, 0, @bar, rect2)
         @bhud2.x = $game_player.screen_x - @x + @ox
         @bhud2.y = $game_player.screen_y - @y + @oy
         @bhud2.z = $game_player.screen_z + 1
       end
       @bhud2.x = $game_player.screen_x - @x + @ox
       @bhud2.y = $game_player.screen_y - @y + @oy
       @bhud2.z = $game_player.screen_z + 1
     end
   end
 end
#------------------------------------------------------------------------------
#Dispose
#------------------------------------------------------------------------------
 def dispose
   #if stunned or no longer pressing attack.
   if @stunned || !Input.press?(Input::Attack)
     #reset all the old variables.
     $game_player.character_name_org = @original_sprite if $game_player.character_name_org != @original_sprite
     $game_player.normal_speed = @player_speed if $game_player.normal_speed == @charge_speed
     @spr_refresh = nil if @spr_refresh != nil
     @bhud2.bitmap.dispose if @bhud2 != nil
     @stunned = false if @stunned == true
     @bhud.bitmap.dispose if @bhud != nil
     @bhud2.bitmap = nil if @bhud2 != nil
     @delay = @dummy if @delay != @dummy
     @bhud.bitmap = nil if @bhud != nil
     skill_id = nil if skill_id != nil
     @bhud2.dispose if @bhud2 != nil
     @repeat = nil if @repeat != nil
     @timer = nil if @timer != nil
     @bhud2 = nil if @bhud2 != nil
     @bhud.dispose if @bhud != nil
     @bhud = nil if @bhud != nil
     @play = nil if @play != nil
   end
 end
end

#==============================================================================
#-------------------------- Scene Map Alias -----------------------------------
#- Alias Scene Map to include Charge Skills.                                  -
#==============================================================================

class Scene_Map
 
 alias update_charge_later update
 
 def charge_new
   if @charging == nil
     @charging = Charge_Skills.new
     @charging.dispose
   end
 end
 
 def update
   update_charge_later
   charge_new
   @charging.update
 end
 
end





Instructions

See Script


Compatibility

Requires Blizz ABS.
Player Must have a weapon equipped or charging won't work.
Must have images for hud in folder(not included might add later.)


Credits and Thanks


  • Chaucer: Author

  • Blizzard, for Blizz-ABS


chaucer

Script Updated.
-Added an option to choose wether sprite uses weapon type for extension.
-Added option to choose your own name for the sprite extension.
-Cleaned up code and removed unnecessary clutter, and possible performance issues.
-Fixed 2 possible issues I didn't notice before.


Sin86

It's a great script and I love it, but I saw some bugs.

You can hold down the attack button during any autorun events, when there is text being displayed, when your character is forced to do a move route. Much of this can be game breaking. Is there any way to disable the script on certain events and then re-enable it when you are ready?

Blizzard

Quote from: Sin86 on August 22, 2024, 03:23:28 pmIt's a great script and I love it, but I saw some bugs.

You can hold down the attack button during any autorun events, when there is text being displayed, when your character is forced to do a move route. Much of this can be game breaking. Is there any way to disable the script on certain events and then re-enable it when you are ready?

Yes, there is. Check the manual for script calls. There is one that disables all ABS controls.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Sin86

August 25, 2024, 05:22:28 pm #4 Last Edit: August 25, 2024, 05:33:39 pm by Sin86
Quote from: Blizzard on August 24, 2024, 03:31:44 am
Quote from: Sin86 on August 22, 2024, 03:23:28 pmIt's a great script and I love it, but I saw some bugs.

You can hold down the attack button during any autorun events, when there is text being displayed, when your character is forced to do a move route. Much of this can be game breaking. Is there any way to disable the script on certain events and then re-enable it when you are ready?

Yes, there is. Check the manual for script calls. There is one that disables all ABS controls.

Tried it while talking to an NPC, it still charges if I hold the attack button. I tried $game_system.blizzabs and $game_system.attack_button and it still thinks it can charge.

Only way this script is ever disabled is if there are no enemy events on the map in the first place.