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.

[XP] Icon Animation for Weapons -- New version!!

Weapon Icon Animations v2.0
By Near

Introduction

Update!

Now the animation looks more natural, and I added an animation for charsets as well!

Just do "<chara>.animate(<new_chara>, <how long it takes in frames>)

Compatibility between this and Theory's Greater Icons script!

---

This is a little something I cooked up for an ABS I'm planning, and I though I'd share it
with my favorite community, RMXP.org .

Actually I got the idea for this from two sources:
1. I can't sprite 30 weapon animations for every character in my game!
2. Someone requested this a long time ago... Wyatt, I believe.

Features

  • Uses Icons as weapon/shield graphics.
  • Works with events(I think you just need to make some edits to Game_Event)
  • Uses dynamic positioning that is easily changeable to suit your animation needs.

Screenshots

None yet, I'll upload later.

Demo

http://www.mediafire.com/?sharekey=7e28 ... b9a8902bda

Script

[rgss] 
module IconConfig
 
  WeaponZoom = 1.0
 
  ShieldZoom = 0.8
 
end
class Sprite_Weapon < RPG::Sprite
 
  attr_accessor :character
 
  def initialize(viewport, icon_name, character=nil)
    super(viewport)
    @icon_name = icon_name
    @character = character
    self.visible = false
    create_bitmap
    update
  end
 
  def update
    super
    self.visible = @character.anime_attack > 0
    change_direction
  end
 
  def create_bitmap
    self.bitmap = RPG::Cache.icon(@icon_name)
    self.ox = 12
    self.oy = 24
    self.zoom_x = IconConfig::WeaponZoom
    self.zoom_y = IconConfig::WeaponZoom
  end
 
  def change_direction
    case @character.direction
    when 2
      #self.x = @character.screen_x-6
      #self.z = @character.screen_z+31
      self.mirror = false
      change_angle([135,0,16,30], [90,6,10,30], [135,0,16,31], [180,0,18,31])
    when 4
      #self.x = @character.screen_x-10
      #self.z = @character.screen_z-1
      self.mirror = false
      change_angle([45,10,10,-31],[0,10,10,-31],[45,10,10,-31],[90,10,10,-31])
    when 6
      #self.x = @character.screen_x+6
      #self.z = @character.screen_z+31
      self.mirror = true
      change_angle([-45,-2,8,31],[-65,-2,6,31],[-45,-2,8,31],[-25,-6,10,31])
    when 8
      #self.x = @character.screen_x+10
      #self.z = @character.screen_z-1
      self.mirror = true
      change_angle([45,-16,22,-31],[0,-14,14,-31],[45,-18,22,-31],[90,-12,28,-31])
    end
    #self.y = @character.screen_y-10
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
  end
 
  def change_angle(d, a, b, c)
    if @character.anime_attack >= 20
      self.angle = a[0]
      self.x = @character.screen_x-a[1]
      self.y = @character.screen_y-a[2]
      self.z = @character.screen_z+a[3]
    elsif @character.anime_attack >= 15
      self.angle = b[0]
      self.x = @character.screen_x-b[1]
      self.y = @character.screen_y-b[2]
      self.z = @character.screen_z+b[3]
    elsif @character.anime_attack >= 10
      self.angle = c[0]
      self.x = @character.screen_x-c[1]
      self.y = @character.screen_y-c[2]
      self.z = @character.screen_z+c[3]
    else
      self.angle = d[0]
      self.x = @character.screen_x-d[1]
      self.y = @character.screen_y-d[2]
      self.z = @character.screen_z+d[3]
    end
  end
 
end
 
class Sprite_Shield < RPG::Sprite
 
  attr_accessor :character
 
  def initialize(viewport, icon_name, character = nil)
    super(viewport)
    @icon_name = icon_name
    @character = character
    self.visible = false
    create_bitmap
    update
  end
 
  def update
    super
    #return if @character.actor.nil?
    self.visible = true #@character.actor.defending
    change_direction
  end
 
  def create_bitmap
    self.bitmap = RPG::Cache.icon(@icon_name)
    self.ox = 12
    self.oy = 24
    self.zoom_x = IconConfig::ShieldZoom
    self.zoom_y = IconConfig::ShieldZoom
  end
 
  def change_direction
    case @character.direction
    when 2
      self.mirror = true
      set_pos(6,4,6,8)
      #self.x = @character.screen_x+6
      self.z = @character.screen_z+31
    when 4
      self.mirror = false
      set_pos(-4,-6,-4,-2)
      #self.x = @character.screen_x-6
      self.z = @character.screen_z+31
    when 6
      self.mirror = true
      set_pos(6,4,6,8)
      #self.x = @character.screen_x+6
      self.z = @character.screen_z-2
    when 8
      self.mirror = false
      set_pos(-6,-4,-6,-8)
      #self.x = @character.screen_x-6
      self.z = @character.screen_z-2
    end
    self.y = @character.screen_y-5
    self.y -= 2 if @character.direction.between?(6,9)
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
  end
 
  def set_pos(d,a,b,c)
    if @character.anime_attack >= 20
      x_plus = a
    elsif @character.anime_attack >= 15
      x_plus = b
    elsif @character.anime_attack >= 10
      x_plus = c
    else
      x_plus = d
    end
    self.x = @character.screen_x+x_plus
  end
 
end
 
 
[/rgss]

[rgss] 
class Game_Character
  alias n_gc_init initialize
  alias n_gc_update update
  def initialize
    n_gc_init
    @animating = false
    @old_chara_name = ""
    @frames = 0
  end
  def update
    if @animating
      update_animation
      return
    end
    n_gc_update
  end
  def update_animation
    if @frames > 1
      @pattern += 1 if @frames % 4 == 0 && @pattern < 3
      @frames -= 1
      return
    end
    @character_name = @old_chara_name
    @old_chara_name = ""
    @animating = false
  end
  def animate(new_chara, frames)
    @old_chara_name = @character_name
    @character_name = new_chara
    @pattern = 0
    @frames = frames
    @animating = true
  end
  attr_reader :animating, :eek:ld_chara_name, :frames
end
 
 
[/rgss]

[rgss] 
class Spriteset_Map
  alias old_update update
  def initialize
    # Make viewports
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    # Make tilemap
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names
      @tilemap.autotiles = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    # Make panorama plane
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    # Make fog plane
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    # Make character sprites
    @character_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events)
      @character_sprites.push(sprite)
    end
    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
    @weapon_sprites = []
    @weapon_sprites.push(Sprite_Weapon.new(@viewport1, "001-Weapon01", $game_player))
    @shield_sprites = []
    @shield_sprites.push(Sprite_Shield.new(@viewport1, "009-Shield01", $game_player))
    # Make weather
    @weather = RPG::Weather.new(@viewport1)
    # Make picture sprites
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures))
    end
    # Make timer sprite
    @timer_sprite = Sprite_Timer.new
    # Frame update
    update
  end
  def update
    old_update
    for s in @weapon_sprites
      s.update
    end
    for s in @shield_sprites
      s.update
    end
  end
end
 
class Game_Player < Game_Character
  alias n_gp_init initialize
  alias n_gp_update update
  def initialize
    n_gp_init
    @anime_attack = 5
    @actor = $game_party.actors[0]
    @attacking
  end
  def update
    if Input.trigger?(Input::C) && @anime_attack < 10
      @anime_attack = 5
      @attacking = true
      animate(@character_name+"_slash",20)
    end
    if @attacking
      if @anime_attack < 25
        @anime_attack += 1
      else
        @anime_attack = 5
        @attacking = false
      end
    end
    n_gp_update
  end
  attr_accessor :anime_attack, :actor
end
 
 
[/rgss]


[rgss] 
module Theory_Greater_Icons
 
  Icon_Changes = {"001-Weapon01" => "Sword001"}
 
end
 
class Window_Base
 
  def draw_item_name(item, x, y)
    if item == nil
      return
    end
    icon = item.icon_name
    change = Theory_Greater_Icons::Icon_Changes
    for i in change.keys
      if item.icon_name == i
        icon = change
      end
    end
    @bitmap = RPG::Cache.icon(icon)
    case item
    when RPG::Weapon
      weapon = $data_weapons[item.id]
      if weapon.element_set.include?(Theory_Greater_Icons::LegendaryElement)
        self.contents.font.color = Theory_Greater_Icons::LegendaryColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::LegendaryBackground)
      elsif weapon.element_set.include?(Theory_Greater_Icons::RareElement)
        self.contents.font.color = Theory_Greater_Icons::RareColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::RareBackground)
      elsif weapon.element_set.include?(Theory_Greater_Icons::UncommonElement)
        self.contents.font.color = Theory_Greater_Icons::UncommonColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::UncommonBackground)
      elsif !weapon.element_set.include?(Theory_Greater_Icons::RareElement) and !weapon.element_set.include?(Theory_Greater_Icons::UncommonElement) and !weapon.element_set.include?(Theory_Greater_Icons::LegendaryElement)
        self.contents.font.color = normal_color
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::Background)
      end
    when RPG::Armor
      armor = $data_armors[item.id]
      if armor.guard_element_set.include?(Theory_Greater_Icons::LegendaryElement)
        self.contents.font.color = Theory_Greater_Icons::LegendaryColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::LegendaryBackground)
      elsif armor.guard_element_set.include?(Theory_Greater_Icons::RareElement)
        self.contents.font.color = Theory_Greater_Icons::RareColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::RareBackground)
      elsif armor.guard_element_set.include?(Theory_Greater_Icons::UncommonElement)
        self.contents.font.color = Theory_Greater_Icons::UncommonColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::UncommonBackground)
      elsif !armor.guard_element_set.include?(Theory_Greater_Icons::RareElement) and !armor.guard_element_set.include?(Theory_Greater_Icons::UncommonElement) and !armor.guard_element_set.include?(Theory_Greater_Icons::LegendaryElement)
        self.contents.font.color = normal_color
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::Background)
      end
    when RPG::Item
      itema = $data_items[item.id]
      if itema.element_set.include?(Theory_Greater_Icons::LegendaryElement)
        self.contents.font.color = Theory_Greater_Icons::LegendaryColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::LegendaryBackground)
      elsif itema.element_set.include?(Theory_Greater_Icons::RareElement)
        self.contents.font.color = Theory_Greater_Icons::RareColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::RareBackground)
      elsif itema.element_set.include?(Theory_Greater_Icons::UncommonElement)
        self.contents.font.color = Theory_Greater_Icons::UncommonColor
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::UncommonBackground)
      elsif !itema.element_set.include?(Theory_Greater_Icons::RareElement) and !itema.element_set.include?(Theory_Greater_Icons::UncommonElement) and !itema.element_set.include?(Theory_Greater_Icons::LegendaryElement)
        self.contents.font.color = normal_color
        self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::Background)
      end
    end
    self.contents.draw_text(x + Theory_Greater_Icons::Width + 4, y, 212, Theory_Greater_Icons::Width, item.name)
  end
 
end
 
 
 
[/rgss]


Instructions

Just copy and paste. You can edit the Spriteset_Map and Game_Player to your liking
as they're not part of the actual script. They're just to test it.

Just test the game and press C/Space/Enter .

You need this for the example:
001fighter01slash.png

Just rename it to '001-Fighter01_slash', and put in the characters folder in graphics.

Compatibility patch for Greater Icons:
Create an icon for what it looks like in menus, and an icon for the map.
put in the module for the patch:
Icon_Changes = {"icon_map_name" => "icon_menu_name"}
remember to make
"map" => "menu"
things for every icon that is bigger than 24x24.

FAQ

Awaiting Questions...

Compatibility

Designed for RTP charsets. It needs edits to work with most others.

Credits and Thanks

Vlad, I had a look at his ABS and that's how I figured out what to do.
Wyatt(I think) for inspiring me to do this at all.

Terms and Conditions

Do what you will. I won't argue.
 
It just doesnt look natural. Like the other frames at least look feasible. It just doesnt look like how someone would hold a sword. Plus it appears to be too far away from the hand. Remember a person holds a sword in the middle of the hilt, not at the end.
 
I'd add an orientation array- say one icon, the handle is in the upper-left and it runs to lower-right, while another icon is the exact opposite. You'd hold the first one by the handle, and the second by the blade. Allowing a default rotation angle to be added to your own math, would eliminate this, making the script a bit more versatile for in-depth artists.
 
Yeah, but I'd rather not be bothered with all that. I mean, I like the idea, I'm just too lazy to do that right now... :/ maybe tomorrow.
 
lol I told you I thought it was good. The new version has good placement, at least as good as you can get from an icon render. I really don't have many suggestions... perhaps for bigger icons, via a script of course, make it detect the collision? Like if you have a sword that is twice your size, but you have to be right of next to a monster to hit it, little unrealistic. You may also have a different holding position for guns, and a way to check if it is a gun or not.
 
How the hell do I add new weapon icons? :cry:

EDIT:
Is there even suport for this script anymore? I would really love to know how to have an icon for every weapon. If there's a way, you sure as hell didn't explain it. :P
 

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