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

[转载发布] ChooseFoes 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 18:49:57 | 显示全部楼层 |阅读模式
    ChooseFoes XP

    by Kyonides


    Introduction

    This scriptlet allows you to open a simple menu where you can choose your enemy's troops based on the current map's random enemy encounter list.
    It will use the map's battleback picture as its backdrop. Don't worry :worried: about this, it will cover the whole RMXP game screen by default.

    You are encouraged to set a custom BGM, otherwise the scene will remain silent until you have finished picking a foe.

    AVAILABLE MODES

    • :accessory
    • :levels
    Accessory Mode

    By the way, setting a specific "Choose Foe" accessory is mandatory here!

    Actors' Level Average Mode

    You must set a default level plus any specific map's average level.

    There's now also an option to skip the random battle just because.


    Optional Script Call

                    Ruby:       
    1. $game_party.choose_foes_mode = :your_mode
    复制代码


    The Script

                    Ruby:       
    1. # * ChooseFoes XP * #
    2. #   Not Exactly a Plug-n-Play Script
    3. #   Scripter : Kyonides
    4. #   1.1.0 - 2026-06-08
    5. # Aliased Methods: Game_Party#initialize, Scene_Map#call_battle
    6. # This scriptlet allows you to open a simple menu where you can choose your
    7. # enemy's troops based on the current map's random enemy encounter list.
    8. # They will be displayed on screen!
    9. # The new MAP_ID_EXTRA_TROOP hash allows you to set a key-value pair of
    10. # MapID => TroopID to add any given troop found in the Troops DB to that map.
    11. # You can replace the TroopID with a :highest or :lowest or :random symbol.
    12. # Notice: This is entirely optional. Use it only for maps that truly need it.
    13. # Thanks to DerVVulfman's evil suggestion, your players might now face a whole
    14. # new set of foes by using a very specific script call. Feel free to change
    15. # the encounter list as many times as needed. Mwahahaha!!
    16. # - AVAILABLE MODES: :accessory and :levels
    17. # * Accessory Mode * #
    18. # Setting a specific "Choose Foe" accessory is mandatory here!
    19. # * Average Level Mode * #
    20. # You must set a default level plus any specific map's average level.
    21. # * Optional Script Calls * #
    22. # * Change Current Mode:
    23. # $game_party.choose_foes_mode = :your_mode
    24. # * Replace Curent Map's Troop ID's:
    25. # $game_party.new_map_troops(TroopID1, etc.)
    26. module ChooseFoes
    27.   MODE = :levels
    28.   ACCESSORY_ID = 33
    29.   MAP_ACTOR_LVL = {}
    30.   MAP_ACTOR_LVL.default = 5
    31.   MAP_ACTOR_LVL[1] = 4
    32.   # MapID => [TroopID1, etc.] or [:highest] or [:lowest] or [:random]
    33.   MAP_ID_EXTRA_TROOPS = {}
    34.   MAP_ID_EXTRA_TROOPS.default = []
    35.   MAP_ID_EXTRA_TROOPS[1] = [10, 11]
    36.   TITLE = "Pick Your Foe"
    37.   NO_TROOP = "No Troop"
    38.   EXTRA_TROOP = "Special Troop"
    39.   # ["Name", Volume or nil, Pitch or nil]
    40.   BGM = ["052-Negative01", nil, nil]
    41.   class TroopWindow < Window_Selectable
    42.     def initialize(width, commands)
    43.       line_max = [commands.size, 4].min + 1
    44.       @commands = commands
    45.       super(0, 0, width, line_max * 32)
    46.       @item_max = commands.size
    47.       @cw = width - 32
    48.       @rect = Rect.new(4, 0, @cw - 8, 32)
    49.       self.contents = Bitmap.new(@cw, @item_max * 32)
    50.       refresh
    51.       self.index = 0
    52.       @last_index = 0
    53.     end
    54.     def refresh
    55.       self.contents.clear
    56.       @item_max.times {|n| draw_item(n, normal_color) }
    57.     end
    58.     def draw_item(n, color)
    59.       self.contents.font.color = color
    60.       @rect.y = 32 * n
    61.       self.contents.draw_text(@rect, @commands[n])
    62.     end
    63.     def update
    64.       super
    65.       @change_troop = false
    66.       if @index != @last_index
    67.         @last_index = @index
    68.         @change_troop = true
    69.       end
    70.     end
    71.     attr_reader :change_troop
    72.   end
    73.   class Scene
    74.     def initialize(cb, replace_troops)
    75.       @callback = cb
    76.       @trooper_max = 8
    77.       @troop_max = $data_troops.size - 1
    78.       @list = []
    79.       map_id = $game_map.map_id
    80.       if replace_troops
    81.         @list += $game_party.map_troop_ids[map_id]
    82.         @commands = @list.map {|n| $data_troops[n].name }
    83.         n = rand(@list.size)
    84.         @troop_id = @list[n]
    85.       else
    86.         @list += $game_map.encounter_list
    87.         @commands = @list.map {|n| $data_troops[n].name }
    88.         troop_ids = MAP_ID_EXTRA_TROOPS[map_id]
    89.         if MAP_ID_EXTRA_TROOPS.has_key?(map_id)
    90.           troop_ids.each {|n| set_extra_troops(n) }
    91.         end
    92.         @troop_id = $game_temp.battle_troop_id
    93.       end
    94.       @list.unshift(nil)
    95.       @commands.unshift(NO_TROOP)
    96.       @troop = Game_Troop.new
    97.       @troop.setup(@troop_id)
    98.       $game_system.se_play($data_system.battle_start_se)
    99.       $game_system.bgm_stop
    100.       bgm = BGM.compact
    101.       bgm = RPG::AudioFile.new(*bgm)
    102.       Audio.play_anon_bgm(bgm)
    103.     end
    104.     def set_extra_troops(troop_id)
    105.       @commands << EXTRA_TROOP
    106.       case troop_id
    107.       when :lowest
    108.         @list << $game_party.lowest_troop_id
    109.       when :highest
    110.         @list << $game_party.highest_troop_id
    111.       when :random
    112.         @list << $game_party.random_troop_id
    113.       when 1..troop_id
    114.         n = [@troop_max, troop_id].min
    115.         @list << n
    116.       end
    117.     end
    118.     def main
    119.       @stage = true
    120.       fn = $game_map.battleback_name
    121.       bb = RPG::Cache.battleback(fn)
    122.       battle_bit = Bitmap.new(640, 480)
    123.       battle_bit.stretch_blt(battle_bit.rect, bb, bb.rect)
    124.       enemies = @troop.enemies
    125.       @backdrop = Sprite.new
    126.       @backdrop.bitmap = battle_bit
    127.       @vp = Viewport.new(0, 0, 640, 320)
    128.       @vp.z = 200
    129.       @battlers = []
    130.       @trooper_max.times do |n|
    131.         battler = Sprite_Battler.new(@vp, enemies[n])
    132.         battler.change(enemies[n])
    133.         @battlers << battler
    134.       end
    135.       @help_window = Window_Help.new
    136.       @help_window.set_text(TITLE, 1)
    137.       @command_window = TroopWindow.new(240, @commands)
    138.       @command_window.x = 200
    139.       @command_window.y = 320
    140.       @command_window.index = @list.index(@troop_id)
    141.       Input.update
    142.       Graphics.transition(Graphics.frame_rate)
    143.       while @stage
    144.         Graphics.update
    145.         Input.update
    146.         update
    147.       end
    148.       Graphics.freeze
    149.       dispose
    150.     end
    151.     def update
    152.       @command_window.update
    153.       if @command_window.change_troop
    154.         i = @command_window.index
    155.         troop_id = @list[i]
    156.         if troop_id
    157.           @troop.setup(troop_id)
    158.         else
    159.           @troop.empty!
    160.         end
    161.         enemies = @troop.enemies
    162.         @trooper_max.times do |n|
    163.           sbattler = @battlers[n]
    164.           sbattler.change(enemies[n])
    165.         end
    166.       end
    167.       if Input.trigger?(Input::B) or Input.trigger?(Input::C)
    168.         $game_system.se_play($data_system.decision_se)
    169.         @stage = nil
    170.         n = @command_window.index
    171.         troop_id = @list[n]
    172.         if troop_id
    173.           $game_temp.battle_troop_id = troop_id
    174.           @callback.call
    175.           return
    176.         else
    177.           $game_temp.battle_calling = false
    178.           $game_temp.menu_calling = false
    179.           $game_temp.menu_beep = false
    180.           $game_temp.battle_troop_id = 0
    181.           $game_player.make_encounter_count
    182.           $game_player.straighten
    183.           $game_map.autoplay
    184.           $scene = Scene_Map.new
    185.         end
    186.       end
    187.     end
    188.     def dispose
    189.       @battlers.each do |s|
    190.         s.bitmap.dispose if s.bitmap
    191.         s.dispose
    192.       end
    193.       @command_window.dispose
    194.       @help_window.dispose
    195.       @vp.dispose
    196.       @backdrop.bitmap.dispose
    197.       @backdrop.dispose
    198.     end
    199.   end
    200. end
    201. module Audio
    202.   def self.play_anon_bgm(bgm)
    203.     if !bgm or bgm.name.empty?
    204.       bgm_stop
    205.     else
    206.       bgm_play("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch)
    207.     end
    208.     Graphics.frame_reset
    209.   end
    210. end
    211. class Game_Actor
    212.   def can_pick_foes?
    213.     ChooseFoes::ACCESSORY_ID == @armor4_id and @armor4_id > 0
    214.   end
    215. end
    216. class Game_Party
    217.   alias :kyon_chs_foes_gm_pty_init :initialize
    218.   def initialize
    219.     kyon_chs_foes_gm_pty_init
    220.     @choose_foes_mode = ChooseFoes::MODE
    221.     @defeated_troop_ids = []
    222.     @map_troop_ids = {}
    223.   end
    224.   def choose_foes_with_accessory?
    225.     @actors.find {|a| a.can_pick_foes? } != nil
    226.   end
    227.   def choose_foes_level_avg?
    228.     avg_level = @actors.inject(0) {|t, a| t + a.level }
    229.     avg_level /= @actors.size
    230.     map_level = ChooseFoes::MAP_ACTOR_LVL[$game_map.map_id]
    231.     avg_level >= map_level
    232.   end
    233.   def choose_foes?
    234.     case @choose_foes_mode
    235.     when :accessory
    236.       return choose_foes_with_accessory?
    237.     when :levels
    238.       return choose_foes_level_avg?
    239.     end
    240.   end
    241.   def lowest_troop_id
    242.     @defeated_troop_ids.min || 1
    243.   end
    244.   def highest_troop_id
    245.     @defeated_troop_ids.max || 1
    246.   end
    247.   def random_troop_id
    248.     n = rand(@defeated_troop_ids.size)
    249.     @defeated_troop_ids[n] || 1
    250.   end
    251.   def new_map_troops?(map_id)
    252.     @map_troop_ids.has_key?(map_id)
    253.   end
    254.   def new_map_troops(*troop_ids)
    255.     n = $game_map.map_id
    256.     @map_troop_ids[n] = troop_ids.flatten
    257.   end
    258.   attr_accessor :choose_foes_mode, :map_troop_ids
    259.   attr_reader :defeated_troop_ids
    260. end
    261. class Game_Troop
    262.   def empty!
    263.     @enemies = []
    264.   end
    265. end
    266. class Sprite_Battler
    267.   def change(battler)
    268.     @battler = battler
    269.     unless @battler
    270.       self.bitmap = nil
    271.       loop_animation(nil)
    272.       return
    273.     end
    274.     @battler_name = @battler.battler_name
    275.     @battler_hue = @battler.battler_hue
    276.     self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
    277.     @width = self.bitmap.width
    278.     @height = self.bitmap.height
    279.     self.ox = @width / 2
    280.     self.oy = @height
    281.     self.x = @battler.screen_x
    282.     self.y = @battler.screen_y
    283.     self.z = @battler.screen_z
    284.   end
    285. end
    286. class Scene_Map
    287.   alias :kyon_chs_foes_scn_mp_cll_btl :call_battle
    288.   def call_battle
    289.     list = $game_map.encounter_list
    290.     if list.size < 2
    291.       kyon_chs_foes_scn_mp_cll_btl
    292.       return
    293.     else
    294.       cb = method(:kyon_chs_foes_scn_mp_cll_btl)
    295.       map_id = $game_map.map_id
    296.       if $game_party.new_map_troops?(map_id)
    297.         $scene = ChooseFoes::Scene.new(cb, true)
    298.       elsif $game_party.choose_foes?
    299.         $scene = ChooseFoes::Scene.new(cb, false)
    300.       end
    301.     end
    302.   end
    303. end
    复制代码


    Terms & Conditions

    Free as in beer.
    Include my nickname in your game credits.
    You may mention this forum there as well.
    That's it!



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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-4 11:52 , Processed in 0.064820 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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