[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

sprites Spoiler
  1.  
  2. module IconConfig
  3.  
  4.   WeaponZoom = 1.0
  5.  
  6.   ShieldZoom = 0.8
  7.  
  8. end
  9. class Sprite_Weapon < RPG::Sprite
  10.  
  11.   attr_accessor :character
  12.  
  13.   def initialize(viewport, icon_name, character=nil)
  14.      super(viewport)
  15.      @icon_name = icon_name
  16.      @character = character
  17.      self.visible = false
  18.      create_bitmap
  19.      update
  20.   end
  21.  
  22.   def update
  23.      super
  24.      self.visible = @character.anime_attack > 0
  25.      change_direction
  26.   end
  27.  
  28.   def create_bitmap
  29.      self.bitmap = RPG::Cache.icon(@icon_name)
  30.      self.ox = 12
  31.      self.oy = 24
  32.      self.zoom_x = IconConfig::WeaponZoom
  33.      self.zoom_y = IconConfig::WeaponZoom
  34.   end
  35.  
  36.   def change_direction
  37.      case @character.direction
  38.      when 2
  39.         #self.x = @character.screen_x-6
  40.         #self.z = @character.screen_z+31
  41.         self.mirror = false
  42.         change_angle([135,0,16,30], [90,6,10,30], [135,0,16,31], [180,0,18,31])
  43.      when 4
  44.         #self.x = @character.screen_x-10
  45.         #self.z = @character.screen_z-1
  46.         self.mirror = false
  47.         change_angle([45,10,10,-31],[0,10,10,-31],[45,10,10,-31],[90,10,10,-31])
  48.      when 6
  49.         #self.x = @character.screen_x+6
  50.         #self.z = @character.screen_z+31
  51.         self.mirror = true
  52.         change_angle([-45,-2,8,31],[-65,-2,6,31],[-45,-2,8,31],[-25,-6,10,31])
  53.      when 8
  54.         #self.x = @character.screen_x+10
  55.         #self.z = @character.screen_z-1
  56.         self.mirror = true
  57.         change_angle([45,-16,22,-31],[0,-14,14,-31],[45,-18,22,-31],[90,-12,28,-31])
  58.      end
  59.      #self.y = @character.screen_y-10
  60.      self.opacity = @character.opacity
  61.      self.blend_type = @character.blend_type
  62.      self.bush_depth = @character.bush_depth
  63.   end
  64.  
  65.   def change_angle(d, a, b, c)
  66.      if @character.anime_attack >= 20
  67.         self.angle = a[0]
  68.         self.x = @character.screen_x-a[1]
  69.         self.y = @character.screen_y-a[2]
  70.         self.z = @character.screen_z+a[3]
  71.      elsif @character.anime_attack >= 15
  72.         self.angle = b[0]
  73.         self.x = @character.screen_x-b[1]
  74.         self.y = @character.screen_y-b[2]
  75.         self.z = @character.screen_z+b[3]
  76.      elsif @character.anime_attack >= 10
  77.         self.angle = c[0]
  78.         self.x = @character.screen_x-c[1]
  79.         self.y = @character.screen_y-c[2]
  80.         self.z = @character.screen_z+c[3]
  81.      else
  82.         self.angle = d[0]
  83.         self.x = @character.screen_x-d[1]
  84.         self.y = @character.screen_y-d[2]
  85.         self.z = @character.screen_z+d[3]
  86.      end
  87.   end
  88.  
  89. end
  90.  
  91. class Sprite_Shield < RPG::Sprite
  92.  
  93.   attr_accessor :character
  94.  
  95.   def initialize(viewport, icon_name, character = nil)
  96.      super(viewport)
  97.      @icon_name = icon_name
  98.      @character = character
  99.      self.visible = false
  100.      create_bitmap
  101.      update
  102.   end
  103.  
  104.   def update
  105.      super
  106.      #return if @character.actor.nil?
  107.      self.visible = true #@character.actor.defending
  108.      change_direction
  109.   end
  110.  
  111.   def create_bitmap
  112.      self.bitmap = RPG::Cache.icon(@icon_name)
  113.      self.ox = 12
  114.      self.oy = 24
  115.      self.zoom_x = IconConfig::ShieldZoom
  116.      self.zoom_y = IconConfig::ShieldZoom
  117.   end
  118.  
  119.   def change_direction
  120.      case @character.direction
  121.      when 2
  122.         self.mirror = true
  123.         set_pos(6,4,6,8)
  124.         #self.x = @character.screen_x+6
  125.         self.z = @character.screen_z+31
  126.      when 4
  127.         self.mirror = false
  128.         set_pos(-4,-6,-4,-2)
  129.         #self.x = @character.screen_x-6
  130.         self.z = @character.screen_z+31
  131.      when 6
  132.         self.mirror = true
  133.         set_pos(6,4,6,8)
  134.         #self.x = @character.screen_x+6
  135.         self.z = @character.screen_z-2
  136.      when 8
  137.         self.mirror = false
  138.         set_pos(-6,-4,-6,-8)
  139.         #self.x = @character.screen_x-6
  140.         self.z = @character.screen_z-2
  141.      end
  142.      self.y = @character.screen_y-5
  143.      self.y -= 2 if @character.direction.between?(6,9)
  144.      self.opacity = @character.opacity
  145.      self.blend_type = @character.blend_type
  146.      self.bush_depth = @character.bush_depth
  147.   end
  148.  
  149.   def set_pos(d,a,b,c)
  150.      if @character.anime_attack >= 20
  151.         x_plus = a
  152.      elsif @character.anime_attack >= 15
  153.         x_plus = b
  154.      elsif @character.anime_attack >= 10
  155.         x_plus = c
  156.      else
  157.         x_plus = d
  158.      end
  159.      self.x = @character.screen_x+x_plus
  160.   end
  161.  
  162. end
  163.  
  164.  
Expand to see the code.


Game_Character Spoiler
  1.  
  2. class Game_Character
  3.   alias n_gc_init initialize
  4.   alias n_gc_update update
  5.   def initialize
  6.      n_gc_init
  7.      @animating = false
  8.      @old_chara_name = ""
  9.      @frames = 0
  10.   end
  11.   def update
  12.      if @animating
  13.         update_animation
  14.         return
  15.      end
  16.      n_gc_update
  17.   end
  18.   def update_animation
  19.      if @frames > 1
  20.         @pattern += 1 if @frames % 4 == 0 && @pattern < 3
  21.         @frames -= 1
  22.         return
  23.      end
  24.      @character_name = @old_chara_name
  25.      @old_chara_name = ""
  26.      @animating = false
  27.   end
  28.   def animate(new_chara, frames)
  29.      @old_chara_name = @character_name
  30.      @character_name = new_chara
  31.      @pattern = 0
  32.      @frames = frames
  33.      @animating = true
  34.   end
  35.   attr_reader :animating, :old_chara_name, :frames
  36. end
  37.  
  38.  
Expand to see the code.


Example Spoiler
  1.  
  2. class Spriteset_Map
  3.   alias old_update update
  4.   def initialize
  5.      # Make viewports
  6.      @viewport1 = Viewport.new(0, 0, 640, 480)
  7.      @viewport2 = Viewport.new(0, 0, 640, 480)
  8.      @viewport3 = Viewport.new(0, 0, 640, 480)
  9.      @viewport2.z = 200
  10.      @viewport3.z = 5000
  11.      # Make tilemap
  12.      @tilemap = Tilemap.new(@viewport1)
  13.      @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
  14.      for i in 0..6
  15.         autotile_name = $game_map.autotile_names[i]
  16.         @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
  17.      end
  18.      @tilemap.map_data = $game_map.data
  19.      @tilemap.priorities = $game_map.priorities
  20.      # Make panorama plane
  21.      @panorama = Plane.new(@viewport1)
  22.      @panorama.z = -1000
  23.      # Make fog plane
  24.      @fog = Plane.new(@viewport1)
  25.      @fog.z = 3000
  26.      # Make character sprites
  27.      @character_sprites = []
  28.      for i in $game_map.events.keys.sort
  29.         sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
  30.         @character_sprites.push(sprite)
  31.      end
  32.      @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  33.      @weapon_sprites = []
  34.      @weapon_sprites.push(Sprite_Weapon.new(@viewport1, "001-Weapon01", $game_player))
  35.      @shield_sprites = []
  36.      @shield_sprites.push(Sprite_Shield.new(@viewport1, "009-Shield01", $game_player))
  37.      # Make weather
  38.      @weather = RPG::Weather.new(@viewport1)
  39.      # Make picture sprites
  40.      @picture_sprites = []
  41.      for i in 1..50
  42.         @picture_sprites.push(Sprite_Picture.new(@viewport2,
  43.            $game_screen.pictures[i]))
  44.      end
  45.      # Make timer sprite
  46.      @timer_sprite = Sprite_Timer.new
  47.      # Frame update
  48.      update
  49.   end
  50.   def update
  51.      old_update
  52.      for s in @weapon_sprites
  53.         s.update
  54.      end
  55.      for s in @shield_sprites
  56.         s.update
  57.      end
  58.   end
  59. end
  60.  
  61. class Game_Player < Game_Character
  62.   alias n_gp_init initialize
  63.   alias n_gp_update update
  64.   def initialize
  65.      n_gp_init
  66.      @anime_attack = 5
  67.      @actor = $game_party.actors[0]
  68.      @attacking
  69.   end
  70.   def update
  71.      if Input.trigger?(Input::C) && @anime_attack < 10
  72.         @anime_attack = 5
  73.         @attacking = true
  74.         animate(@character_name+"_slash",20)
  75.      end
  76.      if @attacking
  77.         if @anime_attack < 25
  78.            @anime_attack += 1
  79.         else
  80.            @anime_attack = 5
  81.            @attacking = false
  82.         end
  83.      end
  84.      n_gp_update
  85.   end
  86.   attr_accessor :anime_attack, :actor
  87. end
  88.  
  89.  
Expand to see the code.


theory's greater icons compatibility patch Spoiler
  1.  
  2. module Theory_Greater_Icons
  3.  
  4.   Icon_Changes = {"001-Weapon01" => "Sword001"}
  5.  
  6. end
  7.  
  8. class Window_Base
  9.  
  10.   def draw_item_name(item, x, y)
  11.     if item == nil
  12.       return
  13.     end
  14.     icon = item.icon_name
  15.     change = Theory_Greater_Icons::Icon_Changes
  16.     for i in change.keys
  17.       if item.icon_name == i
  18.         icon = change[i]
  19.       end
  20.     end
  21.     @bitmap = RPG::Cache.icon(icon)
  22.     case item
  23.     when RPG::Weapon
  24.       weapon = $data_weapons[item.id]
  25.       if weapon.element_set.include?(Theory_Greater_Icons::LegendaryElement)
  26.         self.contents.font.color = Theory_Greater_Icons::LegendaryColor
  27.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::LegendaryBackground)
  28.       elsif weapon.element_set.include?(Theory_Greater_Icons::RareElement)
  29.         self.contents.font.color = Theory_Greater_Icons::RareColor
  30.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::RareBackground)
  31.       elsif weapon.element_set.include?(Theory_Greater_Icons::UncommonElement)
  32.         self.contents.font.color = Theory_Greater_Icons::UncommonColor
  33.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::UncommonBackground)
  34.       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)
  35.         self.contents.font.color = normal_color
  36.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::Background)
  37.       end
  38.     when RPG::Armor
  39.       armor = $data_armors[item.id]
  40.       if armor.guard_element_set.include?(Theory_Greater_Icons::LegendaryElement)
  41.         self.contents.font.color = Theory_Greater_Icons::LegendaryColor
  42.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::LegendaryBackground)
  43.       elsif armor.guard_element_set.include?(Theory_Greater_Icons::RareElement)
  44.         self.contents.font.color = Theory_Greater_Icons::RareColor
  45.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::RareBackground)
  46.       elsif armor.guard_element_set.include?(Theory_Greater_Icons::UncommonElement)
  47.         self.contents.font.color = Theory_Greater_Icons::UncommonColor
  48.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::UncommonBackground)
  49.       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)
  50.         self.contents.font.color = normal_color
  51.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::Background)
  52.       end
  53.     when RPG::Item
  54.       itema = $data_items[item.id]
  55.       if itema.element_set.include?(Theory_Greater_Icons::LegendaryElement)
  56.         self.contents.font.color = Theory_Greater_Icons::LegendaryColor
  57.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::LegendaryBackground)
  58.       elsif itema.element_set.include?(Theory_Greater_Icons::RareElement)
  59.         self.contents.font.color = Theory_Greater_Icons::RareColor
  60.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::RareBackground)
  61.       elsif itema.element_set.include?(Theory_Greater_Icons::UncommonElement)
  62.         self.contents.font.color = Theory_Greater_Icons::UncommonColor
  63.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::UncommonBackground)
  64.       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)
  65.         self.contents.font.color = normal_color
  66.         self.contents.draw_icon(x, y, @bitmap, Theory_Greater_Icons::Background)
  67.       end
  68.     end
  69.     self.contents.draw_text(x + Theory_Greater_Icons::Width + 4, y, 212, Theory_Greater_Icons::Width, item.name)
  70.   end
  71.  
  72. end
  73.  
  74.  
  75.  
Expand to see the code.


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:
Image
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.
nice man, one more script for my archive :)
Looks good except the front view good use work. It just doesn't look right.
I realize this. I'm working on it.

And hopefully Wyatt will look in here.
Alright cool, I'll check in every so often to see when you fix it.
Can you tell me exactly what I should change for the front view?
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.
New version out! Get it while it's hot!

EDIT: A compatibility patch for Theory's Greater Icons has been released!
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.
so this doesn't interest anyone?
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.
Maybe, but this was more created for systems like Prexus's ABS(which doesn't support ranged weapons).
Hmm... I would really love this to be compatible with Blizz ABS.

If you need Blizz ABS to test this to raise compatibility, go to: www.chaos-project.com, and get the latest version to see what you can do. 🙂
How the hell do I add new weapon icons? 😢

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

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=64551