じ☆ve冰风 发表于 2026-7-27 10:38:58

KLastDefeat XP

KLastDefeat XP

by Kyonides​

Introduction

There was once upon a gaming time when certain user was looking for a way to automatize some custom battle loss common event the user needed to mark the last spot where the player's party died. It was supposed to let the player retrieve the EXP the heroes had lost there. This support request led me to create and publish this curious scriptlet here.

Please read the embedded comments to learn how to use it properly. If some portion of the code does not include a comment, then the reason got to be that it has a very self evident name already.

How to Disable an Option

You can disable either the experience lost or the gold lost features by setting the START_LOSE_EXP_PERCENT or the START_LOSE_GOLD_PERCENT constant to 0 (zero).

During gameplay, you would need to use any of these script calls.

EXP
                Ruby:       
$game_temp.lose_exp_percent = 0


GOLD
                Ruby:       
$game_temp.lose_gold_percent = 0


The Script

                Ruby:       
# * KLastDefeat XP * #
#   Scripter : Kyonides
#   v1.1.0 - 2025-09-03

# * THIS IS NOT A PLUG & PLAY SCRIPT * #

# This scriptlet allows you to automatically clone a template event that
# will be used to mark the last place where you were killed by mobs.
# The KLastDefeat module includes several CONSTANTS that you should edit to let
# the scriptlet find and clone your template event whenever it is needed.

# By using a script call, you can now retrieve the EXP or the Gold your actors
# had lost there.

# If you don't want the heroes to lose either EXP or gold, set the value of
# the START_LOSE_ constants to 0 and that option will be disabled by default.

# * Script Calls * #

# - Set a custom Lose EXP Percent Before Battle starts
# $game_temp.lose_exp_percent = 25

# - Set a custom Lose Gold Percent Before Battle starts
# $game_temp.lose_gold_percent = 25

# - Let the party retrieve the EXP they had lost on that map.
# $game_temp.remove_last_spot

module KLastDefeat
START_LOSE_EXP_PERCENT = 1
START_LOSE_GOLD_PERCENT = 1
EVENT_MAP_ID = 1
EVENT_ID = 5
CLONE_EVENT_ID = 1000

class EventData
    def initialize(map_id, event_id)
      @map_id = map_id
      @id = event_id
    end
    attr_accessor :map_id, :id
end

extend self
def setup_event_data
    EventData.new(EVENT_MAP_ID, EVENT_ID)
end

def remove_event_id?(event_id)
    CLONE_EVENT_ID == event_id
end
end

class Game_Temp
alias :kyon_last_dft_gm_tmp_init :initialize
def initialize
    kyon_last_dft_gm_tmp_init
    @last_spot_event = KLastDefeat.setup_event_data
    @lose_exp_percent = KLastDefeat::START_LOSE_EXP_PERCENT
    @lose_gold_percent = KLastDefeat::START_LOSE_GOLD_PERCENT
    clear_last_spot
end

def clear_last_spot
    @last_spot_map_id = 0
    @last_spot_xy = []
    @lost_exp = []
    @lost_gold = 0
end

def last_spot?
    @last_spot_map_id > 0 and @player_new_map_id == @last_spot_map_id
end

def set_last_map_data
    @last_spot_map_id = $game_map.map_id
    @last_spot_xy = $game_player.xy
end

def remove_last_spot
    if @lose_exp_percent > 0
      lost_exp = @lost_exp.map {|exp| exp.abs }
      $game_party.actors_change_exp(lost_exp)
    end
    if @lose_gold_percent > 0
      $game_party.gain_gold(@lost_gold)
    end
    clear_last_spot
end
attr_accessor :last_spot_event, :last_spot_map_id, :last_spot_xy
attr_accessor :lose_exp_percent, :lose_gold_percent, :lost_exp, :lost_gold
end

class Game_Party
def actors_exp_percent(percent)
    @actors.map {|actor| actor.exp * percent / 100 }
end

def actors_change_exp(exp)
    if exp.is_a?(Numeric)
      @actors.each {|actor| actor.exp += exp }
    else
      @actors.each_with_index {|actor, n| actor.exp += exp }
    end
end
end

class Game_Map
alias :kyon_last_dft_gm_map_stp :setup
def setup(map_id)
    kyon_last_dft_gm_map_stp(map_id)
    setup_last_spot if $game_temp.last_spot_map_id == @map_id
end

def setup_last_spot
    mx, my = $game_temp.last_spot_xy
    event = $game_temp.last_spot_event
    if event.map_id == @map_id
      all_events = @map.events
    else
      map = load_data(sprintf("Data/Map%03d.rxdata", event.map_id))
      all_events = map.events
    end
    event = all_events.dup
    event.id = KLastDefeat::CLONE_EVENT_ID
    event.x = mx
    event.y = my
    @events = Game_Event.new(@map_id, event)
end

def delete_last_spot
    @events.delete(KLastDefeat::CLONE_EVENT_ID)
end
end

class Game_Character
def xy
    [@x, @y]
end
end

class Interpreter
alias :kyon_last_dft_inter_transfer_player :command_201
alias :kyon_last_dft_inter_command_end :command_end
def command_end
    kyon_last_dft_inter_command_end
    $game_map.delete_last_spot if KLastDefeat.remove_event_id?(@event_id)
end

def command_201
    result = kyon_last_dft_inter_transfer_player
    $game_map.setup_last_spot if $game_temp.last_spot?
    result
end
end

class Scene_Battle
alias :kyon_last_dft_scn_btl_btl_end :battle_end
def process_last_spot
    if $game_temp.lose_exp_percent > 0
      percent = -$game_temp.lose_exp_percent
      lost_exp = $game_party.actors_exp_percent(percent)
      $game_party.actors_change_exp(lost_exp)
      $game_temp.lost_exp = lost_exp
    end
    if $game_temp.lose_gold_percent > 0
      gold = $game_party.gold
      lost_gold = $game_temp.lose_gold_percent * gold / 100
      $game_party.lose_gold(lost_gold)
      $game_temp.lost_gold = lost_gold
    end
    $game_temp.set_last_map_data
end

def battle_end(result)
    process_last_spot if result == 2
    kyon_last_dft_scn_btl_btl_end(result)
end
end


DOWNLOAD DEMO NOW!​

Terms & Conditions

Free as in beer for non commercial games.
Include my nickname in your game credits.
You might also include a link to this forum.
That's it!
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7


本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/klastdefeat-xp.179700/
页: [1]
查看完整版本: KLastDefeat XP