Problem with a script for Balloon Icon (XP)

Ruby:
#===============================================================#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>SCRIPT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<#
#===============================================================#
#                                                               #
#                        Emotions Script                        #
#                by Ánemus (www.arcadiumrpg.net)                #
#                                                               #
#  This script shows emotions over the player or over the other #
#                     characters of the map.                    #
#                                                               #
#                  $scene.emotion(id,ev,image)                  #
#                                                               #
#           For any comments: [email hidden]            #
#                                                               #
#===============================================================#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>SETTINGS<<<<<<<<<<<<<<<<<<<<<<<<<<<<#
#===============================================================#
#                                                               #
# Number of Repetitions or LOOP:                                #
# That's the number of times the animation of the emotion will  #
# repeat. I recomend 1, because bigger numbers are just way to  #
# repetitive.                                                   #
LOOP = 1
#                                                               #
# Delay:                                                        #
# That's the slowness of the animation. I recomend 3 or 4,      #
# smaller numbers are like flashes, so they aren't really       #
# useful.                                                       #
DELAY = 4
#                                                               #
# Deafult file for emotions:                                    #
# This is a tool to make it easier to use, this way you just    #
# write the id of the animation and the event where you want to #
# show it.
DEFAULTFILE = "Balloon"
#                                                               #
#===============================================================#
#>>>>>>>>>>>>>>>>>>>>>>>>>INSTRUCTIONS<<<<<<<<<<<<<<<<<<<<<<<<<<#
#===============================================================#
#                                                               #
# Whenever you want to use it just use Call Script command      #
# then write:                                                   #
# $scene.emotion(id, ev, image)                                 #
# Being id the number of the emotion in the file (the top one is#
# the 0 and the lowest one the 9), ev the event over which you  #
# are showing the emotion (being -1 for the player and any      #
# other number for events, and image, that is the image file    #
# that you are using for the emotions. This file is to be placed#
# on Pictures folder and should be 256x320 px.                  #
#                                                               #
# Some tips:                                                    #
# If you are using the emotion file specified in DEFAULTFILE    #
# you dont need to include it in the sentence.                  #
# $scene.emotion(id, ev)                                        #
# Now if you are using the default file and also placing the    #
# emotion on the main character, the sentence is reduced to:    #
# $scene.emotion(id)                                            #
#                                                               #
#===============================================================#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>END<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<#
#===============================================================#

#===============================================================#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>CODE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<#
#===============================================================#
class Sprite_Character < RPG::Sprite
alias :old_updateEmo :update
def update
   old_updateEmo
   if @frames != nil
     @pic.x = (@character.screen_x + 5)
     @pic.y = (@character.screen_y - @ph - @ch.to_i+2)
     if @frames > (1 + LOOP*7)*DELAY
       @pic.zoom_x = 0.6
       @pic.zoom_y = 0.6
       @pic.opacity = 100
       @frames -= 1
       return
     elsif @frames > (LOOP*7)*DELAY
       @pic.zoom_x = 1
       @pic.zoom_y = 1
       @pic.opacity = 255
       @frames -= 1
       @iframe = 1
       @gota = 0
       return
     elsif @frames == 0
       @frames = nil
       @pic.bitmap.dispose
       @pic.dispose
       @picid = nil
       return
     else
       @pic.bitmap.clear
       @pic.bitmap.blt(0,0,RPG::Cache.picture(@picig),Rect.new(@iframe*32, @picid*32, 32, 32))
       @pic.zoom_x = 1
       @pic.zoom_y = 1
       @pic.opacity = 255
       @frames -= 1
       if @gota == DELAY
         @iframe += 1
         if @iframe > 7
           @iframe = 1
         end
         @gota = 0
       end
       @gota +=1
     end
   end
end
def emotion (id,ig="Balloon",wt=false)
   if !FileTest.exist?("Graphics/Pictures/"+ig+".png")
     return 0
   end
   @frames = (2 + LOOP*7)*DELAY
   @picid = id > 9 ? 9 : id
   @picig = ig
   @pic = Sprite.new
   @pic.bitmap = Bitmap.new(32,32)
   @pic.bitmap.blt(0, 0, RPG::Cache.picture(@picig), Rect.new(0,32*@picid,32,32))
   @pic.ox = @pic.bitmap.width / 2
   @pic.oy = @ph = @pic.bitmap.height / 2
   @pic.z = 100
   if wt
     return @frames
   else
     return 0
   end
end
def dispose
   super
   if @pic != nil
     @pic.bitmap.dispose
     @pic.dispose
   end
end
end
class Spriteset_Map
def emotion (id,ev=-1,ig=DEFAULTFILE,wt=false)
   if ev.to_i > -1
     @frames = @character_sprites[ev].emotion (id,ig,wt)
   else
     @frames = @character_sprites[@character_sprites.size - 1].emotion(id,ig,wt)
   end
   return @frames
end
end
class Scene_Map
def emotion (id,ev=-1,ig=DEFAULTFILE,wt=false)
   $game_system.map_interpreter.wait_count = @spriteset.emotion (id,ev,ig,wt)
end
end
class Interpreter
def wait_count=(frames)
   @wait_count = frames.to_i
end
end

I found a script online for displaying balloon icon animation and I have a problem with displaying said icon over the main player as shown in the image below.

Inside the script it says that if you want to display balloon icon animation over main player sprite, you should use $scene.emotion(id) command inside the script where id is the animation you want to display. The problem is that when you use $scene.emotion(id), the game displays the balloon icon over the autorun event and not the main player sprite which is the girl sprite on the picture. Am I doing something wrong or is the script a bit bugged? If it's bugged, could some1 help fix it so it works so that I can display the animation over the main player?

The issue persists even if I use $scene.emotion(3,-1)

$scene.emotion(3,18) command works fine as you can see on the picture. It displays the heart animation above event 18 (which is the soldier sprite).

Could it be that some other script is causing this issue?

picture.png

I've moved this thread to Script Support. Thank you.

The script looks correct as the player sprite is the last entry in the @character_sprites array. Did you test in a new project? If it works then you have a conflicting script in your project.
The script works in a new project.

When I delete the script below, the balloon icon script now displays animation above the main player sprite but it does not display it above the soldier anymore for some reason.

How would I go about identifying what the issue is? Any suggestions?


Ruby:
#
#   簡易版マップ軽量化スクリプト  v1.01  by tonbi
#
#     New : 福山さんのパーティ列車移動と併用可能に。
#
#   ・使い方
#
#   Scene_Debug より下、Main より上に、新規セッションを作って、
#   この文章全部を貼り付けてください。
#
#   このスクリプトを使用することで、
#    キャラ描画
#   といった処理が高速化します。
#   高速化するだけなので、何かができるようになるってことはありません。
#
#   あと、使用する際は、↓の部分を必用に応じて書き換えてください。

#========================================================================
#========================================================================
#★スクリプトシェルフの福山さんのパーティ列車移動とあわせて使う場合は、
# このスクリプトを列車移動よりも下にして、
# ↓を、 USE_TRAIN_ACTOR = true としてください。(使わないときは = false)

  USE_TRAIN_ACTOR = false

#========================================================================

#★クリッピングの距離指定(意味わかんなかったらこのままで。)

class Game_Character
   
  DRAWRANGEX = 15 *128  # マップキャラのスプライトを更新する距離
  DRAWRANGEY = 13 *128  # かなり大きいキャラチップを使う場合は増やしてください。
                        # X:14 Y:12前後推奨 *128は変えないでください
                        # ちなみに上がX(横)下がY(縦)です。
end
                     
#========================================================================
                   

#  動作解説
#
#  ・マップスプライト
#       $onscreen[char_ID]
#        このグローバル変数に、画面内フラグを設定
#        画面から遠く離れたキャラクタースプライトは、
#        一切更新しないことで高速化
#

#-------------------------------------------------------------------
# ●Game_Tempクラス
#--------------------------------------------------------------------

class Game_Temp
  alias initialize_tonbi1 initialize
  def initialize
    initialize_tonbi1
   
    $onscreen = []                        # スプライト画面内フラグ
  end
end


  #--------------------------------------------------------------------------
  # ● Game_Characterクラス
  #--------------------------------------------------------------------------

class Game_Character
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  alias update_tonbi1 update
  def update
   
    #画面上での位置
    sx = @real_x - $game_map.display_x - 1280
    sy = @real_y - $game_map.display_y - 960
    # 絶対値を求める
    abs_sx = sx > 0 ? sx : -sx
    abs_sy = sy > 0 ? sy-3 : -sy
     
    # 縦か横が DRAWRANGE タイル以上離れている場合
    if abs_sx > DRAWRANGEX or abs_sy > DRAWRANGEY
      # スプライト非更新にする
      $onscreen[@id]=false
    else
      # スプライト更新ありにする
      $onscreen[@id]=true
    end
   
    update_tonbi1
  end
end

class Spriteset_Map
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  attr_accessor :character_sprites
  def initialize
   
    $onscreen = []
    # ビューポートを作成
    @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
    # タイルマップを作成
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    # パノラマプレーンを作成
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    # フォグプレーンを作成
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
   
    #########################################################★変更
    # キャラクタースプライトを作成
    # 順番変更(プレイヤーを先に作成、イベントはIDと同順)。
    @character_sprites = []
    @party_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites[i]=sprite
      $onscreen[i] = true
    end
    @party_sprites.push(Sprite_Character.new(@viewport1, $game_player))
    #########################################################
   
    # 天候を作成
    @weather = RPG::Weather.new(@viewport1)
    # ピクチャを作成
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    # タイマースプライトを作成
    @timer_sprite = Sprite_Timer.new
    # フレーム更新
    update
  end
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    # タイルマップを解放
    @tilemap.tileset.dispose
    for i in 0..6
      @tilemap.autotiles[i].dispose
    end
    @tilemap.dispose
    # パノラマプレーンを解放
    @panorama.dispose
    # フォグプレーンを解放
    @fog.dispose
    ############################################################★変更
    # キャラクタースプライトを解放
    # nil なら開放しない
    for i in @character_sprites
      if i != nil
        i.dispose
      end
    end
    for i in @party_sprites
      if i != nil
        i.dispose
      end
    end
    ############################################################
    # 天候を解放
    @weather.dispose
    # ピクチャを解放
    for sprite in @picture_sprites
      sprite.dispose
    end
    # タイマースプライトを解放
    @timer_sprite.dispose
    # ビューポートを解放
    @viewport1.dispose
    @viewport2.dispose
    @viewport3.dispose
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # パノラマが現在のものと異なる場合
    if @panorama_name != $game_map.panorama_name or
       @panorama_hue != $game_map.panorama_hue
      @panorama_name = $game_map.panorama_name
      @panorama_hue = $game_map.panorama_hue
      if @panorama.bitmap != nil
        @panorama.bitmap.dispose
        @panorama.bitmap = nil
      end
      if @panorama_name != ""
        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
      end
      Graphics.frame_reset
    end
    # フォグが現在のものと異なる場合
    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
      @fog_name = $game_map.fog_name
      @fog_hue = $game_map.fog_hue
      if @fog.bitmap != nil
        @fog.bitmap.dispose
        @fog.bitmap = nil
      end
      if @fog_name != ""
        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
      end
      Graphics.frame_reset
    end
    # タイルマップを更新
    @tilemap.ox = $game_map.display_x / 4
    @tilemap.oy = $game_map.display_y / 4
    @tilemap.update
    # パノラマプレーンを更新
    @panorama.ox = $game_map.display_x / 8
    @panorama.oy = $game_map.display_y / 8
    # フォグプレーンを更新
    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone
   
    #####################################################★変更
    # キャラクタースプライトを更新
    # 画面外のスプライトは更新しない
    for i in $game_map.events.keys
      if $onscreen[i]
        @character_sprites[i].update
      end
    end
    # プレイヤーキャラ更新
    for i in @party_sprites
      i.update
    end
   
    #####################################################

    # 天候グラフィックを更新
    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update
    # ピクチャを更新
    for sprite in @picture_sprites
      sprite.update
    end
    # タイマースプライトを更新
    @timer_sprite.update
    # 画面の色調とシェイク位置を設定
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    # 画面のフラッシュ色を設定
    @viewport3.color = $game_screen.flash_color
    # ビューポートを更新
    @viewport1.update
    @viewport3.update
  end
end

if USE_TRAIN_ACTOR == true
  module Train_Actor
    module Spriteset_Map_Module
      def setup_actor_character_sprites(characters)
        if !setup_actor_character_sprites?
          for character in characters.reverse
            @party_sprites.unshift(
              Sprite_Character.new(@viewport1, character)
            )
          end
          @setup_actor_character_sprites_flag = true
        end
      end
    end
  end
end
So the emotions script is actually bugged.
Code:
def emotion (id,ev=-1,ig=DEFAULTFILE,wt=false)
   if ev.to_i > -1
     @frames = @character_sprites[ev].emotion (id,ig,wt)
The event ID you pass to this is not the actual map event ID. It's supposed to be one less than its ID, i.e. to play the emotion over event 18 it would be $scene.emotion(0, 17). This can be resolved by just updating the offending line in the script above to [ev - 1].

The new script you introduced (it looks like some caterpillar system) masked the bug, so you don't have to do the fix I mentioned.
Code:
   for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites[i]=sprite #<============== this line right here
      $onscreen[i] = true
    end

The original problem is that the player sprite is no longer being pushed into @character_sprites, but rather a new variable entirely:
Code:
@party_sprites.push(Sprite_Character.new(@viewport1, $game_player))
Going back to the emotions script, find the line
Code:
@frames = @character_sprites[@character_sprites.size - 1].emotion(id,ig,wt)
and change to
Code:
@frames = @party_sprites.last.emotion(id,ig,wt)
At least, I think it's last. Otherwise, try first.
Works fine now.

Changing @character_sprites[ev] to @character_sprites[ev-1] actually didn't work so I changed it back.

It seems the second part you said to change did the trick tho.

The script works now. Thanks, sir.

picture1.png
Changing @character_sprites[ev] to @character_sprites[ev-1] actually didn't work so I changed it back.
Yes, I mentioned you didn't need to do that with the other script you have.
It is for people who DON'T use that other script.
Yes, I mentioned you didn't need to do that with the other script you have.
It is for people who DON'T use that other script.

I missed that part 🙂

Thanks again.

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-a-script-for-balloon-icon-xp.131278/