From 19e3874f801886ea6f50319f31395a264436b5cc Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Wed, 15 Apr 2015 11:17:52 -0700 Subject: [PATCH] Support index selection on pokemon menu helper, restrict heal checking to primary pokemon --- ai/control.lua | 2 +- storage/inventory.lua | 6 +++--- storage/pokemon.lua | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ai/control.lua b/ai/control.lua index a2aa5cf..60c5489 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -256,7 +256,7 @@ end -- Items function Control.canRecover() - return potionInBattle and (not battleYolo or not Control.yolo) + return potionInBattle and (not battleYolo or not Control.yolo) and Pokemon.mainFighter() end function Control.set(data) diff --git a/storage/inventory.lua b/storage/inventory.lua index e00604e..d06abf8 100644 --- a/storage/inventory.lua +++ b/storage/inventory.lua @@ -119,11 +119,11 @@ function Inventory.teach(item, poke, replaceIdx, altPoke) elseif column == 15 then Menu.select(0, true) else - local idx = 0 + local teachIndex = 0 if poke then - idx = Pokemon.indexOf(poke, altPoke) + teachIndex = Pokemon.indexOf(poke, altPoke) end - Menu.select(idx, true) + Pokemon.select(teachIndex) end else return false diff --git a/storage/pokemon.lua b/storage/pokemon.lua index 3e2636e..0ed67f1 100644 --- a/storage/pokemon.lua +++ b/storage/pokemon.lua @@ -283,6 +283,10 @@ function Pokemon.isDeployed(...) end end +function Pokemon.mainFighter() + return Pokemon.index(0) == Memory.value("battle", "our_id") +end + function Pokemon.isEvolving() return Memory.value("menu", "pokemon") == 144 end @@ -328,7 +332,11 @@ function Pokemon.getDVs(name) return bit.rshift(attackDefense, 4), bit.band(attackDefense, 15), bit.rshift(speedSpecial, 4), bit.band(speedSpecial, 15) end -function Pokemon.select(name) - return Menu.select(indexOf(name), true, false, nil, false, Memory.value("player", "party_size")) +function Pokemon.select(target) + if type(target) == "string" then + target = indexOf(target) + end + return Menu.select(target, true, false, nil, false, Memory.value("player", "party_size")) end + return Pokemon