KLastDefeat XP - kyonides - 08-22-2025
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
Code: $game_temp.lose_exp_percent = 0
GOLD
Code: $game_temp.lose_gold_percent = 0
The Script
Code: # * 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[n] }
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[event.id].dup
event.id = KLastDefeat::CLONE_EVENT_ID
event.x = mx
event.y = my
@events[event.id] = 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
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!
RE: KLastDefeat XP - kyonides - 08-23-2025
Maintenance Update
Well, I have to come back in order to fix a bug I had encountered after creating the second map on my script demo. It was unable to load another map's events because it was missing a single line of code. More specifically speaking, it only loading the map data just as intended, but it never looked for the actual events to load the template event. That's why the map object was unable to find an Array method. Oops!
Today's release solved that problem for good.
RE: KLastDefeat XP - DerVVulfman - 08-25-2025
One more bug: After pressing New Game in the title screen, the screen goes blank as it would when it exits to go to the field map. But before it enters,
Script 'Scene_Map' line 154: NoMethodError occurred.
undefined method 'trigger_double?' for Input:Module.
Those are direct edits to the Scene_Map code. I figure you were doing HiddenChest tests.. Ya need to remove that block of code after the 'unless $game_player.moving?' block.
RE: KLastDefeat XP - kyonides - 08-25-2025
On the so called bug
Not a (script-related) bug but a leftover from a general test demo. There's no need to change the current version of the script at all.
Updating the demo... DONE!
RE: KLastDefeat XP - kyonides - 09-04-2025
Script Update
Version 1.1.0 has been released today!
This release now allows you as the game developer to set a starting lost gold percentage for the poor heroes that have been defeated at any given point. Later on you can use a script call to alter that percentage at will.
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
Code: $game_temp.lose_exp_percent = 0
GOLD
Code: $game_temp.lose_gold_percent = 0
|