设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 79|回复: 0

[转载发布] KLastDefeat XP

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9015

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58751
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68660

    灌水之王

    发表于 2026-7-27 10:38:58 | 显示全部楼层 |阅读模式
    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:       
    1. $game_temp.lose_exp_percent = 0
    复制代码


    GOLD
                    Ruby:       
    1. $game_temp.lose_gold_percent = 0
    复制代码


    The Script

                    Ruby:       
    1. # * KLastDefeat XP * #
    2. #   Scripter : Kyonides
    3. #   v1.1.0 - 2025-09-03
    4. # * THIS IS NOT A PLUG & PLAY SCRIPT * #
    5. # This scriptlet allows you to automatically clone a template event that
    6. # will be used to mark the last place where you were killed by mobs.
    7. # The KLastDefeat module includes several CONSTANTS that you should edit to let
    8. # the scriptlet find and clone your template event whenever it is needed.
    9. # By using a script call, you can now retrieve the EXP or the Gold your actors
    10. # had lost there.
    11. # If you don't want the heroes to lose either EXP or gold, set the value of
    12. # the START_LOSE_ constants to 0 and that option will be disabled by default.
    13. # * Script Calls * #
    14. # - Set a custom Lose EXP Percent Before Battle starts
    15. # $game_temp.lose_exp_percent = 25
    16. # - Set a custom Lose Gold Percent Before Battle starts
    17. # $game_temp.lose_gold_percent = 25
    18. # - Let the party retrieve the EXP they had lost on that map.
    19. # $game_temp.remove_last_spot
    20. module KLastDefeat
    21.   START_LOSE_EXP_PERCENT = 1
    22.   START_LOSE_GOLD_PERCENT = 1
    23.   EVENT_MAP_ID = 1
    24.   EVENT_ID = 5
    25.   CLONE_EVENT_ID = 1000
    26.   class EventData
    27.     def initialize(map_id, event_id)
    28.       @map_id = map_id
    29.       @id = event_id
    30.     end
    31.     attr_accessor :map_id, :id
    32.   end
    33.   extend self
    34.   def setup_event_data
    35.     EventData.new(EVENT_MAP_ID, EVENT_ID)
    36.   end
    37.   def remove_event_id?(event_id)
    38.     CLONE_EVENT_ID == event_id
    39.   end
    40. end
    41. class Game_Temp
    42.   alias :kyon_last_dft_gm_tmp_init :initialize
    43.   def initialize
    44.     kyon_last_dft_gm_tmp_init
    45.     @last_spot_event = KLastDefeat.setup_event_data
    46.     @lose_exp_percent = KLastDefeat::START_LOSE_EXP_PERCENT
    47.     @lose_gold_percent = KLastDefeat::START_LOSE_GOLD_PERCENT
    48.     clear_last_spot
    49.   end
    50.   def clear_last_spot
    51.     @last_spot_map_id = 0
    52.     @last_spot_xy = []
    53.     @lost_exp = []
    54.     @lost_gold = 0
    55.   end
    56.   def last_spot?
    57.     @last_spot_map_id > 0 and @player_new_map_id == @last_spot_map_id
    58.   end
    59.   def set_last_map_data
    60.     @last_spot_map_id = $game_map.map_id
    61.     @last_spot_xy = $game_player.xy
    62.   end
    63.   def remove_last_spot
    64.     if @lose_exp_percent > 0
    65.       lost_exp = @lost_exp.map {|exp| exp.abs }
    66.       $game_party.actors_change_exp(lost_exp)
    67.     end
    68.     if @lose_gold_percent > 0
    69.       $game_party.gain_gold(@lost_gold)
    70.     end
    71.     clear_last_spot
    72.   end
    73.   attr_accessor :last_spot_event, :last_spot_map_id, :last_spot_xy
    74.   attr_accessor :lose_exp_percent, :lose_gold_percent, :lost_exp, :lost_gold
    75. end
    76. class Game_Party
    77.   def actors_exp_percent(percent)
    78.     @actors.map {|actor| actor.exp * percent / 100 }
    79.   end
    80.   def actors_change_exp(exp)
    81.     if exp.is_a?(Numeric)
    82.       @actors.each {|actor| actor.exp += exp }
    83.     else
    84.       @actors.each_with_index {|actor, n| actor.exp += exp[n] }
    85.     end
    86.   end
    87. end
    88. class Game_Map
    89.   alias :kyon_last_dft_gm_map_stp :setup
    90.   def setup(map_id)
    91.     kyon_last_dft_gm_map_stp(map_id)
    92.     setup_last_spot if $game_temp.last_spot_map_id == @map_id
    93.   end
    94.   def setup_last_spot
    95.     mx, my = $game_temp.last_spot_xy
    96.     event = $game_temp.last_spot_event
    97.     if event.map_id == @map_id
    98.       all_events = @map.events
    99.     else
    100.       map = load_data(sprintf("Data/Map%03d.rxdata", event.map_id))
    101.       all_events = map.events
    102.     end
    103.     event = all_events[event.id].dup
    104.     event.id = KLastDefeat::CLONE_EVENT_ID
    105.     event.x = mx
    106.     event.y = my
    107.     @events[event.id] = Game_Event.new(@map_id, event)
    108.   end
    109.   def delete_last_spot
    110.     @events.delete(KLastDefeat::CLONE_EVENT_ID)
    111.   end
    112. end
    113. class Game_Character
    114.   def xy
    115.     [@x, @y]
    116.   end
    117. end
    118. class Interpreter
    119.   alias :kyon_last_dft_inter_transfer_player :command_201
    120.   alias :kyon_last_dft_inter_command_end :command_end
    121.   def command_end
    122.     kyon_last_dft_inter_command_end
    123.     $game_map.delete_last_spot if KLastDefeat.remove_event_id?(@event_id)
    124.   end
    125.   def command_201
    126.     result = kyon_last_dft_inter_transfer_player
    127.     $game_map.setup_last_spot if $game_temp.last_spot?
    128.     result
    129.   end
    130. end
    131. class Scene_Battle
    132.   alias :kyon_last_dft_scn_btl_btl_end :battle_end
    133.   def process_last_spot
    134.     if $game_temp.lose_exp_percent > 0
    135.       percent = -$game_temp.lose_exp_percent
    136.       lost_exp = $game_party.actors_exp_percent(percent)
    137.       $game_party.actors_change_exp(lost_exp)
    138.       $game_temp.lost_exp = lost_exp
    139.     end
    140.     if $game_temp.lose_gold_percent > 0
    141.       gold = $game_party.gold
    142.       lost_gold = $game_temp.lose_gold_percent * gold / 100
    143.       $game_party.lose_gold(lost_gold)
    144.       $game_temp.lost_gold = lost_gold
    145.     end
    146.     $game_temp.set_last_map_data
    147.   end
    148.   def battle_end(result)
    149.     process_last_spot if result == 2
    150.     kyon_last_dft_scn_btl_btl_end(result)
    151.   end
    152. 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!



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

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-4 12:49 , Processed in 0.089741 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表