diff --git a/src/core/game3/battle/engine.lua b/src/core/game3/battle/engine.lua index 3cb64397..eb64fa8f 100644 --- a/src/core/game3/battle/engine.lua +++ b/src/core/game3/battle/engine.lua @@ -2079,14 +2079,19 @@ function Engine.canSwitch(st, adapter, battler) if not battler then return true end if battler.expTrapped or battler.escapePrevention or (battler.expTrapTurns or 0) > 0 or battler.expIngrain then -- src/party_menu.c:5964 - return false, RomText.ascii("gText_PkmnCantSwitchOut", { stringVars = { adapter:displayName(battler) } }) + local name = (adapter and adapter.displayName and adapter:displayName(battler)) or "POKéMON" + local ok, txt = pcall(RomText.ascii, "gText_PkmnCantSwitchOut", { stringVars = { name } }) + if ok and txt then return false, txt end + return false, name .. " can't be switched out!" end local holder, ab = Abilities.escapeBlocker(adapter, battler) if holder then -- src/pokemon.c:6029 - return false, State.text(st, "gText_PkmnsXPreventsSwitching", { + local ok, txt = pcall(State.text, st, "gText_PkmnsXPreventsSwitching", { buff1 = State.prefixedName(st, holder), lastAbility = Abilities.id(ab), }) + if ok and txt then return false, txt end + return false, "Can't escape!" end return true end diff --git a/src/core/game3/battle/state.lua b/src/core/game3/battle/state.lua index cbdd8ddb..d8da8396 100644 --- a/src/core/game3/battle/state.lua +++ b/src/core/game3/battle/state.lua @@ -389,13 +389,13 @@ function State.text(st, id, fill) return require("src.core.game3.battle.battle_text").get(id, fill) end --- src/battle_message.c:2248 function State.prefixedName(st, battler, name) name = name or State.displayName(battler) if battler and battler.side == "player" then return name end local RomText = require("src.core.game3.rom_text") local prefix = (st ~= nil and not st.wild) and "sText_FoePkmnPrefix" or "sText_WildPkmnPrefix" - return RomText.plain(prefix) .. name + local ok, pre = pcall(RomText.plain, prefix) + return (ok and pre or (st ~= nil and not st.wild and "Foe " or "Wild ")) .. name end function State.isFainted(battler)