Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Makeshift droptype enum
- local None, Bomb, Super, Missile, Small, Large = 0,1,2,3,4,5
- neededDrop = None
- rns = {13, 2, 6, 8, 7, 9, 14, 10, 2, 4, 14, 4, 12, 15, 13, 12, 11, 1, 3, 15, 0, 6, 7, 8, 11, 5, 0, 3, 5, 1, 9, 10}
- enHealth = { }
- chosenEnemyIndex = -1
- clickBoxSize = 8
- prevClick = false
- pause = false
- -- functions for displaying drop
- function DrawHighlight(x, y) -- displays a box
- gui.line(x-clickBoxSize, y-clickBoxSize, x+clickBoxSize, y-clickBoxSize, "green")
- gui.line(x-clickBoxSize, y-clickBoxSize, x-clickBoxSize, y+clickBoxSize, "green")
- gui.line(x-clickBoxSize, y+clickBoxSize, x+clickBoxSize, y+clickBoxSize, "green")
- gui.line(x+clickBoxSize, y-clickBoxSize, x+clickBoxSize, y+clickBoxSize, "green")
- end
- function DrawNone(x, y) -- displays an X for no drop
- gui.line(1+x, 1+y, 6+x, 6+y, "white")
- gui.line(1+x, 6+y, 6+x, 1+y, "white")
- end
- function DrawSmall(x, y) -- displays a small health drop
- gui.line(3+x, 1+y, 4+x, 1+y, "#D030D0")
- gui.pixel(2+x, 2+y, "#D030D0")
- gui.pixel(5+x, 2+y, "#D030D0")
- gui.line(1+x, 3+y, 1+x, 4+y, "#D030D0")
- gui.box(3+x, 3+y, 4+x, 4+y, "#D030D0")
- gui.line(6+x, 3+y, 6+x, 4+y, "#D030D0")
- gui.pixel(2+x, 5+y, "#D030D0")
- gui.pixel(5+x, 5+y, "#D030D0")
- gui.line(3+x, 6+y, 4+x, 6+y, "#D030D0")
- end
- function DrawLarge(x, y) -- displays a large health drop
- gui.line(2+x, y, 5+x, y, "#D030D0")
- gui.pixel(1+x, 1+y, "#D030D0")
- gui.pixel(6+x, 1+y, "#D030D0")
- gui.line(x, 2+y, x, 5+y, "#D030D0")
- gui.line(3+x, 2+y, 4+x, 2+y, "#D030D0")
- gui.line(2+x, 3+y, 2+x, 4+y, "#D030D0")
- gui.line(5+x, 3+y, 5+x, 4+y, "#D030D0")
- gui.line(3+x, 5+y, 4+x, 5+y, "#D030D0")
- gui.line(7+x, 2+y, 7+x, 5+y, "#D030D0")
- gui.pixel(1+x, 6+y, "#D030D0")
- gui.pixel(6+x, 6+y, "#D030D0")
- gui.line(2+x, 7+y, 5+x, 7+y, "#D030D0")
- end
- function DrawMissile(x, y) -- displays a missile drop
- gui.box(3+x, y, 4+x, 1+y, "#D030D0")
- gui.box(3+x, 2+y, 4+x, 4+y, "#A0A0A0")
- gui.line(2+x, 5+y, 5+x, 5+y, "#A0A0A0")
- gui.box(1+x, 6+y, 6+x, 7+y, "#A0A0A0")
- end
- function DrawSuper(x, y) -- displays a super missile drop
- gui.line(2+x, y, 5+x, y, "#30D030")
- gui.line(1+x, 1+y, 6+x, 1+y, "#30D030")
- gui.box(1+x, 2+y, 6+x, 4+y, "#A0A0A0")
- gui.box(2+x, 5+y, 5+x, 6+y, "#A0A0A0")
- gui.line(3+x, 7+y, 4+x, 7+y, "#A0A0A0")
- end
- function DrawBomb(x, y) -- displays a power bomb drop
- gui.line(2+x, 1+y, 5+x, 1+y, "#A0A0A0")
- gui.line(1+x, 2+y, 1+x, 5+y, "#A0A0A0")
- gui.line(2+x, 2+y, 2+x, 5+y, "#D030D0")
- gui.line(3+x, 2+y, 4+x, 2+y, "white")
- gui.box(3+x, 3+y, 4+x, 4+y, "#A0A0A0")
- gui.line(3+x, 5+y, 4+x, 5+y, "white")
- gui.line(5+x, 2+y, 5+x, 5+y, "#D030D0")
- gui.line(6+x, 2+y, 6+x, 5+y, "#A0A0A0")
- gui.line(2+x, 6+y, 5+x, 6+y, "#A0A0A0")
- end
- function DrawPause(x, y) -- displays a pause sign
- local color = "#000000A0"
- if(pause) then
- color = "#00FFFFFF"
- end
- gui.box( x, y-1, x+7, y+8, color)
- gui.box(2+x, 1+y, 2+x, 6+y, "white")
- gui.box(5+x, 1+y, 5+x, 6+y, "white")
- end
- function DrawArrow(x, y) -- displays an arrow
- gui.line(10+x, 4+y, 16+x, 4+y, "red")
- gui.line(9+x, 4+y, 12+x, 1+y, "red")
- gui.line(9+x, 4+y, 12+x, 7+y, "red")
- end
- function DrawMenu()
- local x = 10
- local y = 10
- DrawDrop(Small, x, y, (neededDrop == Small))
- DrawDrop(Large, x+10, y, (neededDrop == Large))
- DrawDrop(Missile, x+20, y, (neededDrop == Missile))
- DrawDrop(Super, x+30, y, (neededDrop == Super))
- DrawDrop(Bomb, x+40, y, (neededDrop == Bomb))
- DrawPause(x+50, y)
- end
- function PerformMenu(mouseX, mouseY)
- local hit = false
- local x = 14
- local y = 14
- local selectedDrop = None
- if math.abs(mouseX - x) < 4 and math.abs(mouseY - y) < 4 then
- selectedDrop = Small
- hit = true
- end
- if math.abs(mouseX - (x + 10)) < 4 and math.abs(mouseY - y) < 4 then
- selectedDrop = Large
- hit = true
- end
- if math.abs(mouseX - (x + 20)) < 4 and math.abs(mouseY - y) < 4 then
- selectedDrop = Missile
- hit = true
- end
- if math.abs(mouseX - (x + 30)) < 4 and math.abs(mouseY - y) < 4 then
- selectedDrop = Super
- hit = true
- end
- if math.abs(mouseX - (x + 40)) < 4 and math.abs(mouseY - y) < 4 then
- selectedDrop = Bomb
- hit = true
- end
- --Pause
- if math.abs(mouseX - (x + 50)) < 4 and math.abs(mouseY - y) < 4 then
- pause = (pause == false)
- hit = true
- end
- if selectedDrop ~= None then
- if neededDrop == selectedDrop then
- neededDrop = None
- else
- neededDrop = selectedDrop
- end
- end
- return hit
- end
- function DrawDrop(dropType, posX, posY, highlight)
- local color = "#000000A0"
- if(highlight) then
- color = "#FFFF00FF"
- end
- gui.box(posX, posY-1, posX+7, posY+8, color, color)
- if dropType == Bomb then
- DrawBomb(posX, posY)
- elseif dropType == Super then
- DrawSuper(posX, posY)
- elseif dropType == Missile then
- DrawMissile(posX, posY)
- elseif dropType == Large then
- DrawLarge(posX, posY)
- elseif dropType == Small then
- DrawSmall(posX, posY)
- else
- DrawNone(posX, posY)
- end
- end
- function GetDrop(enID, enProp, dropRN)
- -- get necessary values
- local maxHealth = memory.readword(0x3001530)
- local maxMissiles = memory.readbyte(0x3001532)
- local maxSupers = memory.readbyte(0x3001534)
- local maxBombs = memory.readbyte(0x3001535)
- local currHealth = memory.readword(0x3001536)
- local currMissiles = memory.readbyte(0x3001538)
- local currSupers = memory.readbyte(0x300153A)
- local currBombs = memory.readbyte(0x300153B)
- local fullHealth = (currHealth == maxHealth)
- -- get drop rates
- local offset
- if enProp < 0x80 then
- offset = 0x82B0D70 + (enID * 18)
- else
- offset = 0x82B1BEC + (enID * 18)
- end
- local cmpBomb = 1024 - memory.readword(offset + 8)
- local cmpSuper = cmpBomb - memory.readword(offset + 6)
- local cmpMissile = cmpSuper - memory.readword(offset + 4)
- local cmpLarge = cmpMissile - memory.readword(offset + 2)
- local cmpSmall = cmpLarge - memory.readword(offset)
- if dropRN > cmpBomb then
- if maxBombs > currBombs then
- return Bomb
- elseif fullHealth == false then
- return Large
- elseif maxBombs == 0 then
- return Small
- else
- return Bomb
- end
- elseif dropRN > cmpSuper then
- if maxSupers > currSupers then
- return Super
- elseif fullHealth == false then
- return Large
- elseif maxSupers == 0 then
- return Small
- else
- return Super
- end
- elseif dropRN > cmpMissile then
- if maxMissiles > currMissiles then
- return Missile
- elseif fullHealth == false then
- return Large
- elseif maxMissiles == 0 then
- return Small
- else
- return Missile
- end
- elseif dropRN > cmpLarge then
- if fullHealth == false then
- return Large
- elseif maxMissiles > currMissiles then
- return Missile
- else
- return Large
- end
- elseif dropRN > cmpSmall then
- if fullHealth == false then
- return Small
- elseif maxMissiles > currMissiles then
- return Missile
- else
- return Small
- end
- else
- return None
- end
- end
- while true do
- -- get necessary values
- local frame1 = (memory.readbyte(0x3000C77) + 1) % 256
- local frame2 = (memory.readword(0x3000002) + 1) % 65536
- local cameraX, cameraY = memory.readword(0x30013B8), memory.readword(0x30013BA)
- --Check mouse status
- local nowClick = input.get()["leftclick"]
- local mouseX
- local mouseY
- local clicked = (nowClick and prevClick ~= true)
- prevClick = nowClick
- if clicked then
- mouseX = input.get()["xmouse"]
- mouseY = input.get()["ymouse"]
- if(PerformMenu(mouseX, mouseY)) then
- clicked = false
- end
- end
- --Display Enemy Info
- for i=0,23 do
- local status = memory.readbyte(0x30001AC + i*56)
- local enID = memory.readbyte(0x30001C9 + i*56)
- local enProp = memory.readbyte(0x30001DE + i*56)
- -- handle second part of metroids
- local isMetroid = (enID == 26 and enProp >= 0x80)
- if isMetroid then
- enID = 101
- enProp = 0
- end
- local dropNone
- if enProp < 0x80 then
- dropNone = memory.readword(0x82B0D6E + (enID * 18))
- else
- dropNone = memory.readword(0x82B1BEA + (enID * 18))
- end
- if status > 0 and dropNone < 0x400 then
- -- update enemy's past/current health
- local pastHealth = enHealth[i+1]
- local enemyHealth = memory.readword(0x30001C0 + i*56)
- enHealth[i+1] = enemyHealth
- local enemyX, enemyY = memory.readword(0x30001B0 + i*56), memory.readword(0x30001AE + i*56)
- local posX, posY = bit.arshift(enemyX - cameraX, 2), bit.arshift(enemyY - cameraY, 2)
- if isMetroid then
- posX = posX - 10
- end
- --Select Enemy
- if clicked and math.abs(mouseX - posX) < clickBoxSize and math.abs(mouseY - posY) < clickBoxSize then
- if chosenEnemyIndex == i then
- chosenEnemyIndex = -1
- else
- chosenEnemyIndex = i
- end
- end
- --draw enemy highlight
- if chosenEnemyIndex == i then
- DrawHighlight(posX, posY)
- end
- --draw enemy modPos
- if not isMetroid then
- gui.text(posX, posY+8, (enemyX + enemyY) % 32, "#E04040")
- end
- --Calculate drop RNG and draw drop
- local enRN = rns[((frame1 + bit.rshift(frame2, 4) + i + enemyX + enemyY) % 32) + 1]
- local dropRN = (frame1 + frame2 + enRN*256) % 1024
- if dropRN == 0 then
- dropRN = 1
- end
- DrawDrop(GetDrop(enID, enProp, dropRN), posX, posY)
- -- draw arrow to indicate drop
- if pastHealth ~= enemyHealth and enemyHealth == 0 then
- DrawArrow(posX, posY)
- end
- --Find viable position for chosen enemy and droptype
- if(i == chosenEnemyIndex) then
- acceptedRNs = {}
- local modVal = ((frame1 + bit.rshift(frame2, 4) + chosenEnemyIndex) % 32) + 1
- --Find indexes in rn list that would yield desired result
- for i=1,#rns do
- local dropRN = (frame1 + frame2 + rns[i]*256) % 1024
- if dropRN == 0 then
- dropRN = 1
- end
- if GetDrop(enID, enProp, dropRN) == neededDrop then
- table.insert(acceptedRNs, (i - modVal) % 32)
- end
- end
- --Figure out and print required modPos for viable index to occur
- if(#acceptedRNs > 0) then
- local concatString = ""
- local count = 0
- table.sort(acceptedRNs)
- for key, val in ipairs(acceptedRNs) do
- concatString = concatString .. val .. " "
- count = count + 1
- if(count > 7) then
- concatString = concatString .. "\n"
- count = 0
- end
- end
- gui.text(posX, posY+16, concatString, "#40E040")
- if(pause == true) then
- vba.pause()
- end
- end
- end
- end
- end
- DrawMenu();
- vba.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement