Skip to content

Instantly share code, notes, and snippets.

@MottaTheHutt
Last active November 16, 2022 04:09
Show Gist options
  • Save MottaTheHutt/5a92cc88dd0d60f2f5ab to your computer and use it in GitHub Desktop.
Save MottaTheHutt/5a92cc88dd0d60f2f5ab to your computer and use it in GitHub Desktop.
Gau Bot
-- Work in Progress
local battle = {}
battle.main = function ()
while (memory.readbyte(0x7E3A8F)==0x00) do
while (memory.readbyte(0x7E3219)==0x00 or memory.readbyte(0x7E321B)==0x00 or
memory.readbyte(0x7E321D)==0x00 or memory.readbyte(0x7E321F)==0x00) do
joypad.set(1,{A=true})
snes9x.frameadvance()
end
snes9x.frameadvance()
end
end
return battle
local characters = {
terra = {
name = "Terra",
currentWorldHP = function() return memory.readword(0x7E1609) end,
maxHP = memory.readword(0x7E160B),
partyStatus = memory.readbyte(0x7E1850),
},
locke = {
name = "Locke",
currentWorldHP = function() return memory.readword(0x7E162E) end,
maxHP = memory.readword(0x7E1630),
partyStatus = memory.readbyte(0x7E1851),
},
cyan = {
name = "Cyan",
currentWorldHP = function() return memory.readword(0x7E1653) end,
maxHP = memory.readword(0x7E1655),
partyStatus = memory.readbyte(0x7E1852),
},
edgar = {
name = "Edgar",
currentWorldHP = function() return memory.readword(0x7E169D) end,
maxHP = memory.readword(0x7E169F),
partyStatus = memory.readbyte(0x7E1854),
},
sabin = {
name = "Sabin",
currentWorldHP = function() return memory.readword(0x7E16C2) end,
maxHP = memory.readword(0x7E16C4),
partyStatus = memory.readbyte(0x7E1855),
},
setzer = {
name = "Setzer",
currentWorldHP = function() return memory.readword(0x7E1756) end,
maxHP = memory.readword(0x7E1758),
partyStatus = memory.readbyte(0x7E1859),
},
gau = {
name = "Gau, Gau!",
currentWorldHP = function() return memory.readword(0x7E17A0)end,
maxHP = memory.readword(0x7E17A2),
partyStatus = memory.readbyte(0x7E185B),
},
empty = {
name = "Empty",
currentWorldHP = function() return 1 end,
maxHP = 1,
partyStatus = 2, -- EXPERIMENTAL PLACEHOLDER
},
}
return characters;
-- ***************************************************************************************
-- gau_bot.lua
-- a rage-acquiring bot
-- WiP
--
-- Green beret obscures max_hp value
-- Use back guard. Non-standard formations interfere with heal targetting
-- intangir = probable wipe
--
-- **************************************************************************
NAVIGATION = require "navigation"
PARTY = require "party"
BATTLE = require "battle"
while (true) do
if (memory.readbyte(0x7E3A8F)==0x00) then
BATTLE.main()
end
if (PARTY[1].currentWorldHP()/PARTY[1].maxHP<=0.33 or PARTY[2].currentWorldHP()/PARTY[2].maxHP<=0.33 or
PARTY[3].currentWorldHP()/PARTY[3].maxHP<=0.33 or PARTY[4].currentWorldHP()/PARTY[4].maxHP<=0.33) then
NAVIGATION.visitMobliz()
else
NAVIGATION.patrol()
end
for a=1,25 do
--gui.text(25,25, PARTY[2].currentWorldHP()) -- PRINT A SPECIFIC ADDRESS
snes9x.frameadvance()
end
end
local navigation = {}
function get_world_x_position() return memory.readbyte(0x7E00E0) end
function get_world_y_position() return memory.readbyte(0x7E00E2) end
function get_town_x_position() return memory.readbyte(0x7E0541) end
function get_town_y_position() return memory.readbyte(0x7E00B0) end
function go_right() joypad.set(1, {right=true}); emu.frameadvance() end
function go_up() joypad.set(1, {up=true}); emu.frameadvance() end
function go_down() joypad.set(1, {down=true}); emu.frameadvance() end
navigation.visitMobliz = function ()
-- Returns to Mobliz to heal
while (get_world_y_position() < 0x73) do go_down() end
while (get_world_y_position() > 0x73) do go_up() end
while (get_world_x_position() < 0xDC) do go_right() end
while (get_town_y_position() > 0x25) do go_up() end
while (get_town_x_position() < 0x15) do go_right() end
while (get_town_y_position() > 0x11) do go_up() end
while (get_town_x_position() < 0x18) do go_right() end
go_up()
for f=1,5 do
joypad.set(1,{A=true})
snes9x.frameadvance()
end
for g=1,70 do
joypad.set(1,{A=false})
snes9x.frameadvance()
end
for g=1,5 do
joypad.set(1,{A=true})
snes9x.frameadvance()
end
for z=1,880 do
snes9x.frameadvance()
end
while (get_town_x_position() < 0x15) do go_right() end
while (get_town_y_position() < 0x11) do go_down() end
while (get_town_x_position() < 0x17) do go_right() end
while (get_town_y_position() < 0x2A) do go_down() end
end
navigation.patrol = function ()
-- Moves randomly on world map
if (get_world_y_position() == 0x71) then
go_down()
elseif (get_world_y_position() == 0x75) then
go_up()
elseif (math.random(2)%2==0) then
go_down()
else
go_up()
end
end
return navigation;
local party = {}
local CHARACTERS = require "characters"
local function findCharacters ()
i = 1;
party = {}
for k,character in pairs(CHARACTERS) do
if character.partyStatus%2 == 1 then
party[i] = character
i = i+1
end
end
return party
end
local function sortCharacters(unsorted)
sorted = {CHARACTERS.empty,CHARACTERS.empty,CHARACTERS.empty,CHARACTERS.empty}
for k,character in pairs(unsorted) do
partyPosition = bit.rshift(bit.band(character.partyStatus,0x18),3) + 1
character.partyPosition = partyPosition
sorted[partyPosition] = character
end
return sorted;
end
local function fillEmptySlots(sorted)
filled = {CHARACTERS.empty,CHARACTERS.empty,CHARACTERS.empty,CHARACTERS.empty}
for i=1, 4 do
if sorted[i].name == "Empty" then
filled[i] = CHARACTERS.empty
else
filled[i] = sorted[i]
end
end
return filled
end
function party.createParty()
unsortedParty = findCharacters()
sortedParty = sortCharacters(unsortedParty)
filledParty = fillEmptySlots(sortedParty)
return filledParty
end
-- PRINT TEST Warning: Will crash main.lua, must run party.lua directly ----
-- while (true) do
-- local testString
-- testString1 = findCharacters()
-- testString2 = sortCharacters(testString1)
-- testString3 = fillEmptySlots(testString2)
-- j = 0
-- for i=1,4 do
-- gui.text(17,25+10*j,testString3[i].name)
-- j = j+1
-- end
-- snes9x.frameadvance()
-- end
----------------------------------------------------------------------
return party.createParty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment