Yesterday, 02:44 AM
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.
The Script
Code:
# * KLastDefeat XP * #
# Scripter : Kyonides
# 2025-08-21
# * 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 retrieve the EXP you had lost there.
# * Script Calls * #
# - Set a custom Lose EXP Percent Before Battle starts
# $game_temp.lose_exp_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
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
clear_last_spot
end
def clear_last_spot
@last_spot_map_id = 0
@last_spot_xy = []
@lost_exp = []
end
def last_spot?
@last_spot_map_id > 0 and @player_new_map_id == @last_spot_map_id
end
def remove_last_spot
lost_exp = @lost_exp.map {|exp| exp.abs }
$game_party.actors_change_exp(lost_exp)
clear_last_spot
end
attr_accessor :last_spot_event, :last_spot_map_id, :last_spot_xy
attr_accessor :lose_exp_percent, :lost_exp
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
all_events = load_data(sprintf("Data/Map%03d.rxdata", event.map_id))
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
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
$game_temp.last_spot_map_id = $game_map.map_id
$game_temp.last_spot_xy = $game_player.xy
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

Include my nickname in your game credits.
You might also include a link to this forum.
That's it!

"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-PixelArtist.png]](https://www.save-point.org/images/userbars/SP1-PixelArtist.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-PixelArtist.png]](https://www.save-point.org/images/userbars/SP1-PixelArtist.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE