Save-Point
KLastWords XP - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: KLastWords XP (/thread-12714.html)



KLastWords XP - kyonides - 08-30-2025

KLastWords XP

by Kyonides

Introduction

Some Minecraft-inspired avatar once made a support request where it wanted to display an actor's or enemy's last words before finally collapsing in the battlefield. Well, this scriptlet should allow you all to accomplish this very simple goal.

This is NOT a Plug & Play script at all! Confused

You will have to modify the contents of 4 CONSTANTS to make it work. Some accept ID's (1, 2, etc.) and "strings" while others only numbers, 1 or above.

For further information, please read the comments embedded in the script.

Code:
# * KLastWords XP * #
#   Scripter : Kyonides
#   v1.0.2 - 2025-09-02

# * Not a Plug & Play Script! * #

# This scriptlet lets you display a picture portraying a dying character's
# last words before collapsing on screen.
# Pictures should be placed in the Graphics/Pictures directory.
# To make this possible, you will have to add an actor's or enemy's ID and
# their respective "filenames" to the ACTORS or ENEMIES hashes as a key-value
# pair: ACTORS[ID] = "filename" or ENEMIES[ID] = "filename"
# ID stands for an integer number like 1 or above.
# The offset constants will let you place this new picture on screen very close
# to the original battler.

module KLastWords
  OFFSET_X = 16
  OFFSET_Y = -128
  ACTORS = {}
  ENEMIES = {}
  ACTORS[1] = "death1"
  ACTORS[2] = "death2"
  def self.filenames(type)
    type == :actor ? ACTORS : ENEMIES
  end
end

class Game_Actor
  def real_class
    :actor
  end
end

class Game_Enemy
  def real_class
    :enemy
  end
end

class Sprite_Battler
  unless respond_to?(:last_words_sprt_btlr_up)
    alias :last_words_sprt_btlr_up :update
    alias :last_words_sprt_btlr_disp :dispose
  end
  def update
    last_words_sprt_btlr_up
    reset_last_words
  end

  def reset_last_words
    return unless @last_words and @_collapse_duration == 0
    @last_words = false
    @lw_sprite.bitmap.dispose
    @lw_sprite.dispose
  end

  def create_last_words
    filenames = KLastWords.filenames(@battler.real_class)
    @last_words = filenames.has_key?(@battler.id)
    return unless @last_words
    filename = filenames[@battler.id]
    rect = self.viewport.rect
    @last_viewport ||= Viewport.new(rect.x, rect.y, rect.width, rect.height)
    @last_viewport.z = 200
    @lw_sprite = Sprite.new(@last_viewport)
    @lw_sprite.x = self.x + KLastWords::OFFSET_X
    @lw_sprite.y = self.y + KLastWords::OFFSET_Y
    @lw_sprite.z = self.z + 1000
    @lw_sprite.bitmap = RPG::Cache.picture(filename)
  end

  def collapse
    create_last_words
    super
  end

  def dispose
    last_words_sprt_btlr_disp
    @last_viewport.dispose if @last_viewport
  end
end


Terms & Conditions

Free as in Beer beer for non-commercial games. Gamer
Include my nickname in your game credits.
That's it! Tongue sticking out


RE: KLastWords XP - Ace_V - 09-02-2025

NICE! It fits what I've been looking for. Thank you, kyonides!  Grinning

One thing I did notice, though: the death image that appears persists no matter what. When the character dies, the image appears, but when resurrected, it is still there. It also persists when the game over screen shows up, and only disappears when I go back to the start screen.  Indifferent

EDIT: Nevermind! I moved the script all the way down to just above main, and it functions the same way as the demo! Hooray! Thank you for this script.  Grinning


RE: KLastWords XP - kyonides - 09-02-2025

Maintenance Update

It was convenient for me to publish this update as a way to prevent issues like the infamous F12 reset Bug bug.
Both the script and the demo were updated in tandem.
The script also creates the custom viewport only once now. It will dispose of it when the sprite itself gets disposed as defined in the default Spriteset_Battle's dispose method.

Curiously, there was no need to address the temporary issue Ace_V was facing a while ago. It seems it was just a script-order-related issue. Indifferent