Advertisement
Guest User

FFIV lua script

a guest
Oct 8th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.90 KB | None | 0 0
  1. -- --------------------------- --
  2. -- Final Fantasy IV LUA script --
  3. --                             --
  4. -- By: Pasky13                 --
  5. -- --------------------------- --
  6.  
  7. -- Globals
  8.  
  9.   char_atbm  = {0, 0, 0, 0, 0}
  10.   enemy_atbm = {0, 0, 0, 0, 0, 0, 0, 0}
  11.  
  12.   -- Change this to the amount of groups you want displayed at a time
  13.   groupmax = 5  
  14.  
  15.   TableEnemyFormation = { "Imp x3",
  16.                           "FloatEye x2",
  17.                           "Eagle x2, FloatEye x1",
  18.                           "Eagle x3",
  19.                           "Imp x3, Sword Rat x1",
  20.                           "SwordRat x2, Imp x2",
  21.                           "Imp x4",
  22.                           "Larva x3",
  23.                           "SandMoth x2, Larva x2",
  24.                           "Sand Man x4",
  25.                           "SandPede x1, Sand Man x2",
  26.                           "SandWorm x1",
  27.                           "Evilshell x3 WaterBug x1",
  28.                           "Pike x3",
  29.                           "CaveToad x3",
  30.                           "Pike x2, Evilshell x2",
  31.                           "Zombie x4",
  32.                           "Pike x2, Evilshell x2, WaterBug x2",
  33.                           "Jelly x4",
  34.                           "TinyMage x2, WaterHag x4",
  35.                           "CaveToad x4",
  36.                           "CaveToad x2, Mad Toad x2",
  37.                           "Aligator x1, Pike x2",
  38.                           "Aligator x2",
  39.                           "Zombie x6",
  40.                           "Aligator x1, WaterBug x2",
  41.                           "Mad Toad x4",
  42.                           "TinyMage x4",
  43.                           "Imp x8",
  44.                           "SwordRat x2, Imp x2, TinyMage x2",
  45.                           "SandWorm x1, Sandpede x1",
  46.                           "SandWorm x2",
  47.                           "Imp x3, Imp Captain x1",
  48.                           "Turtle x1, Imp x2",
  49.                           "Cream x4",
  50.                           "Basilisk x1, Imp x3",
  51.                           "Turtle x2",
  52.                           "Weeper x1, Turtle x1, Basilisk x1",
  53.                           "Basilisk x1, Turtle x1",
  54.                           "Weeper x2",
  55.                           "Skelton x4",
  56.                           "Spirit x2",
  57.                           "Gargoyle x1, Cocktrice x1",
  58.                           "Bomb x3",
  59.                           "Cocktrice x3",
  60.                           "Gargoyle x2",
  61.                           "GrayBomb x2, Bomb x2",
  62.                           "Spirit x2, Skelton x2",
  63.                           "Red Bone x1, Skelton x3",
  64.                           "GrayBomb x2, Bomb x4",
  65.                           "Spirit x3, Skelton x2, Red Bone x1",
  66.                           "Imp Captain x3, Needler x1",
  67.                           "Imp Captain x3, Needler x3",
  68.                           "Imp Captain x4, Imp x2",
  69.                           "SwordRat x3, Needler x3",
  70.                           "Raven x1",
  71.                           "Needler x2, SwordRat x2",
  72.                           "Raven x1 Cockatrice x3",
  73.                           "Spirit x3, Soul x1",
  74.                           "Soul x2, Red Bone x2",
  75.                           "Skelton x3, Red Bone x2",
  76.                           "Lilith x1, Red Bone x2",
  77.                           "Ghoul x1, Red Bone x2, Skelton x2",
  78.                           "Spirit x2, Soul x2, Red Bone x2",
  79.                           "Zombie x2, Ghoul x2",
  80.                           "Ghoul x2, Soul x2",
  81.                           "Revenant x1, Ghoul x3",
  82.                           "Zombie x3, Ghoul x2, Revenant x2",
  83.                           "Lilith x1",
  84.                           "Soul x2, Ghoul x2, Revenant x2",
  85.                           "Soul x3, Ghoul x1, Revenant x1",
  86.                           "Lilith x2",
  87.                           "Piranha x2, FangShel x1, Evilshell x1",
  88.                           "Pike x3, Piranha x3",
  89.                           "Crocdile x1, Piranha x2",
  90.                           "FangShel x3, Aligator x1, Crocdile x1",
  91.                           "Piranha x2, ElecFish x2",
  92.                           "Crocdile x1, ElecFish x3",
  93.                           "AquaWorm x1, Piranha x3",
  94.                           "Hydra x2",
  95.                           "Crocdile x2",
  96.                           "AquaWorm x1, ElecFish x3",
  97.                           "AquaWorm x1, Hydra x1, Crocdile x1",
  98.                           "Guard x2",
  99.                           "Guard x1, Hydra x2",
  100.                           "AquaWorm x2",
  101.                           "StingRat x3, Treant x2",
  102.                           "Panther x1, StingRat x3",
  103.                           "Cannibal x1, Treant x2",
  104.                           "Python x1, StingRat x2",
  105.                           "Ogre x1, Panther x2",
  106.                           "Ogre x2",
  107.                           "Cave Bat x3",
  108.                           "Panther x2",
  109.                           "Mage x2",
  110.                           "CaveNaga x1, Ogre x1",
  111.                           "CaveNaga x1, Python x2",
  112.                           "CaveNaga x1, Python x2",
  113.                           "Ogre x3",
  114.                           "VampGirl x1, Cave Bat x3",
  115.                           "Mage x1, Panther x1, Ogre x1",
  116.                           "Panther x2, Ogre x2",
  117.                           "CaveNaga x2, Python x2",
  118.                           "VampGirl x2, Cave Bat x3",
  119.                           "Panther x2, Ogre x1, CaveNaga x1",
  120.                           "VampGirl x1, Cave Bat x6",
  121.                           "Marion x1, (Summon Puppet x1), Puppet x2",
  122.                           "Marion x1, (Summon Puppet x1), Puppet x3",
  123.                           "Marion x1,(Summon Puppet x1), Puppet x3",
  124.                           "Centaur x1, IceBeast x2",
  125.                           "Centaur x2, IceBeast x2",
  126.                           "Centaur x3",
  127.                           "Centaur x1, Gremlin x2",
  128.                           "Slime x4",
  129.                           "Ice Lizard x1, Slime x3",
  130.                           "Jelly x1, Slime x2, Cream x1",
  131.                           "Gremlin x2, Ice Lizard x2",
  132.                           "Carapace x2, Ice Lizard x2",
  133.                           "SwordMan x2",
  134.                           "SwordMan x1, Ice Lizard x2",
  135.                           "Swordman x2, Ice Lizard x 2",
  136.                           "SwordMan x1, IceBeast x2",
  137.                           "EpeeGirl x2, SwordMan x2",
  138.                           "EpeeGirl x3",
  139.                           "Witch x1, EpeeGirl x1, Swordman x1",
  140.                           "EpeeGirl x1, Ice Lizard x1, IceBeast x1",
  141.                           "Witch x1, EpeeGirl, x1, Centaur x1",
  142.                           "Witch x1, IceBeast x2, EpeeGirl x1",
  143.                           "Witch x1, SwordMan x2, EpeeGirl x1",
  144.                           "Witch x1, EpeeGirl x2",
  145.                           "Imp x1",
  146.                           "Imp x1",
  147.                           "Imp x1",
  148.                           "Imp x1",
  149.                           "Imp x1",
  150.                           "Roc x1, Roc Baby x2",
  151.                           "Roc x1, Roc Baby x3",
  152.                           "HugeCell x4",
  153.                           "HugeCell x3",
  154.                           "GiantBat x3",
  155.                           "GiantBat x4",
  156.                           "GiantBat x3, Cave Bat x3",
  157.                           "Ironback x2",
  158.                           "Ironback x1, Armadilo x1, BlackLiz x1",
  159.                           "Ironback x2, BlackLiz x2",
  160.                           "Skull x3",
  161.                           "Skull x4",
  162.                           "Red Bone x3, Skull x2",
  163.                           "Staleman x1",
  164.                           "Staleman x1, Skull x2",
  165.                           "Staleman x1, Skull x2, Red Bone x2",
  166.                           "Mad Ogre x2",
  167.                           "Mad Ogre x3",
  168.                           "Mad Ogre x4",
  169.                           "BlackCat x2",
  170.                           "BlackCat x3",
  171.                           "Lamia x1, BlackCat x1, Mad Ogre x1",
  172.                           "Mad Ogre x1, BlackCat x2",
  173.                           "Mad Ogre x2, BlackCat x2",
  174.                           "Egg(Lamia x1)",
  175.                           "Lamia x2",
  176.                           "Lamia x3",
  177.                           "Lamia x1, Mad Ogre x1",
  178.                           "BlackCat x2, Lamia x1",
  179.                           "BlackCat x2, Lamia x2",
  180.                           "Balloon x3",
  181.                           "Balloon x4",
  182.                           "Mad Ogre x1, BlackCat x1, Balloon x2",
  183.                           "Grudger x1, Mad Ogre x1, Balloon x2",
  184.                           "Grudger x2",
  185.                           "Grudger x3",
  186.                           "Balloon x3, Grudger x1",
  187.                           "Grudger x2, Lamia x1",
  188.                           "BladeMan x3",
  189.                           "BlackCat x1, BladeMan x1, Mad Ogre x1",
  190.                           "Blademan x1, Balloon x3, BlackCat x1",
  191.                           "Mad Ogre x1, BladeMan x1, BlackCat x1",
  192.                           "Egg(Green Dragon x1)",
  193.                           "Sorcerer x1, (Summon Mad Ogre x1), BladeMan x2",
  194.                           "Sorcerer x1, (Summon BlackCat x1), BladeMan x2",
  195.                           "Sorcerer x1, (Summon BladeMan x1), BladeMan x2",
  196.                           "Sorcerer x1, (Summon Green Dragon x1), BladeMan x2",
  197.                           "Imp x1",
  198.                           "Searcher x1, (Summon Machine x1)",
  199.                           "Searcher x1, (Summon Machine x1), Machine x2",
  200.                           "Machine x2, Beamer x1",
  201.                           "Machine x2, Beamer x2",
  202.                           "Searcher x1, (Summon Horseman x1), Machine x2",
  203.                           "Horseman x1, Machine x2",
  204.                           "MacGiant x1",
  205.                           "MacGiant x1",
  206.                           "Horseman x1, Beamer x2",
  207.                           "Horseman x1, Beamer x1, Machine x1",
  208.                           "Searcher x1, (Summon MacGiant x1)",
  209.                           "MacGiant x1, Horseman x1",
  210.                           "Searcher x1, (Summon Horseman x1), Beamer x2",
  211.                           "Machine x2, Beamer x3",
  212.                           "Horseman x2",
  213.                           "D.Machin x1",
  214.                           "Searcher x1, (Summon D.Machin x1), Beamer x2",
  215.                           "MacGiant x1, Machine x1, Beamer x1",
  216.                           "MacGiant x1, Horseman x1, Beamer x1",
  217.                           "Imp x1",
  218.                           "Machine x3, Beamer x2",
  219.                           "Beamer x1, Machine x2, Horseman x1",
  220.                           "MacGiant x2",
  221.                           "Imp x1",
  222.                           "Imp x6",
  223.                           "SwordRat x6",
  224.                           "FlameDog x2, BlackLiz x2",
  225.                           "Horseman x1, Machine x2",
  226.                           "Horseman x1, Juclyote x2",
  227.                           "Horseman x2",
  228.                           "EvilMask",
  229.                           "Imp x1",
  230.                           "Armadillo x2",
  231.                           "Dark Imp x3, Armadillo x1, BlackLiz x1",
  232.                           "Armadillo x1, Tortise x2",
  233.                           "Dark Imp x4",
  234.                           "Tortise x1, Dark Imp x2",
  235.                           "Tortise x2, Armadillo x1, Black Liz x1",
  236.                           "BlackLiz x3",
  237.                           "Marion x1, (Summon EvilDoll x1), EvilDoll x2",
  238.                           "Marion x1, (Summon EvilDoll x1), EvilDoll x3",
  239.                           "FlameDog x2",
  240.                           "FlameDog x3",
  241.                           "FlameDog x4",
  242.                           "FlameMan x1, FlameDog x2",
  243.                           "FlameMan x2, FlameDog x2",
  244.                           "BlackLiz x2",
  245.                           "BlackLiz x3",
  246.                           "Egg(BlackLiz x1)",
  247.                           "Tortoise x2, BlackLiz x1",
  248.                           "Tortoise x2, BlackLiz x2",
  249.                           "Tofu x4",
  250.                           "Tofu x6",
  251.                           "Chimera x1, Tofu x3",
  252.                           "Chimera x1",
  253.                           "Chimera x2",
  254.                           "Chimera x1, FlameMan x1",
  255.                           "Chimera x1, FlameMan x2",
  256.                           "Chimera x1, FlameDog x2",
  257.                           "Stoneman x1, Medusa x1",
  258.                           "Medusa x2",
  259.                           "Stoneman x2",
  260.                           "Alert x1, (Summon Chimera x1)",
  261.                           "Alert x1, (Summon Stoneman x1)",
  262.                           "Alert x1, (Summon Naga x1)",
  263.                           "Alert x1, (Summon FlameDog x1)",
  264.                           "Alert x1, (Summon Naga x1)",
  265.                           "Egg(Lamia x1), Q. Lamia x1",
  266.                           "Egg(Lamia x3), Q. Lamia x1",
  267.                           "Q. Lamia x1, Egg(Lamia x1), BlackCat x1",
  268.                           "Q. Lamia x1, Egg(Lamia x1), Lamia x2",
  269.                           "Ironman x1",
  270.                           "Ironman x2",
  271.                           "Ironman x1, BladeMan x2",
  272.                           "Green Dragon x1",
  273.                           "BladeMan x1, BlackCat x1, Q. Lamia x1",
  274.                           "Ironman x1, Blackcat x2",
  275.                           "Sorcerer x1, (Summon Q. Lamia x1), BlackCat x2",
  276.                           "Sorcerer x1, (Summon Ironman x1), BlackCat x2",
  277.                           "Sorcerer x1, (Summon Q. Lamia x1), BlackCat x2",
  278.                           "Grudger x2, BladeMan x2",
  279.                           "Grudger x2, BladeMan x2",
  280.                           "Grudger x1, BladeMan x2",
  281.                           "Grudger x1, BlackCat x2, BladeMan x1",
  282.                           "Centpede x1",
  283.                           "TrapRose x1, Centpede x2",
  284.                           "TrapRose x2",
  285.                           "RocLarva x4",
  286.                           "RockMoth x2",
  287.                           "RockMoth x2, RocLarva x2",
  288.                           "TrapRose x1, RockMoth x2",
  289.                           "TrapRose x1, RockMoth x2, RocLarva x2",
  290.                           "ToadLady x1, TinyToad x3",
  291.                           "ToadLady x1, TinyToad x6",
  292.                           "Marlboro x2",
  293.                           "Marlboro x3",
  294.                           "Marlboro x1, Ghost x2",
  295.                           "Ghost x3",
  296.                           "Ghost x4",
  297.                           "Marlboro x1, Ghost x1, DarkTree x1",
  298.                           "Ghost x3, DarkTree x2",
  299.                           "DarkTree x2, Marlboro x1, Ghost x1",
  300.                           "Centpede x1, Marlboro x2",
  301.                           "DarkTree x2, Marlboro x2",
  302.                           "Red Eye x2",
  303.                           "Red Eye x3",
  304.                           "Hooligan x1, Red Eye x1",
  305.                           "Hooligan x1",
  306.                           "Hooligan x2",
  307.                           "Warrior x2, Fiend x2",
  308.                           "Warrior x2, Fiend x4",
  309.                           "Conjurer x1, (Summon Imp x1)",
  310.                           "Conjurer x1, (Summon RockMoth x1)",
  311.                           "Conjurer x1, (Summon Arachne x1)",
  312.                           "Conjurer x1, (Summon HugeNaga x1)",
  313.                           "Conjurer x1, (Summon Clapper x1)",
  314.                           "Arachne x1",
  315.                           "Arachne x2",
  316.                           "Clapper x1",
  317.                           "Clapper x2",
  318.                           "Were Bat x4",
  319.                           "Were Bat x3",
  320.                           "VampLady x1, Were Bat x3",
  321.                           "VampLady x1, Were Bat x6",
  322.                           "VampLady x2, Were Bat x3",
  323.                           "Yellow Dragonragon x1",
  324.                           "Screamer x2",
  325.                           "Mantcore x1, Screamer x1",
  326.                           "HugeNaga x2",
  327.                           "Screamer x1, HugeNaga x1",
  328.                           "HugeNaga x1, Screamer x2",
  329.                           "MoonCell x2, Pudding x2",
  330.                           "Juclyote x2, MoonCell x2, Grenade x1",
  331.                           "Procyote x1, Juclyote x2",
  332.                           "Procyote x1, Pudding x2",
  333.                           "Juclyote x1, Procyote x2",
  334.                           "Red Worm x1, Procyote x1, Juclyote x1",
  335.                           "Red Worm x2",
  336.                           "H.Ito",
  337.                           "K.Higuchi",
  338.                           "K.Aoki",
  339.                           "A.Matsui",
  340.                           "K.Yoshii",
  341.                           "H.Nakada",
  342.                           "Takahashi",
  343.                           "Warlock x1",
  344.                           "Warlock x1, Kary x1",
  345.                           "Warlock x1, Kary x2",
  346.                           "RedGiant x1",
  347.                           "Warlock x1, Kary x1, RedGiant x1",
  348.                           "RedGiant x2",
  349.                           "Warlock x2, RedGiant x1",
  350.                           "Dragon Bone x1",
  351.                           "Ging-Ryu x1",
  352.                           "Dragon Bone x1, Warlock x1",
  353.                           "King-Ryu x2",
  354.                           "Warlock x3",
  355.                           "Blue Dragon x1",
  356.                           "FatalEye x1",
  357.                           "Blue Dragon x2",
  358.                           "Ging-Ryu x1, RedGiant x1",
  359.                           "FatalEye x2",
  360.                           "D.Fossil x1",
  361.                           "King-Ryu x1",
  362.                           "King-Ryu x1, Ging-Ryu x1",
  363.                           "Tricker x1",
  364.                           "Tricker x1",
  365.                           "PinkPuff x5",
  366.                           "EvilMask x1",
  367.                           "Red D. x1",
  368.                           "Red D. x2",
  369.                           "Red D. x1, Behemoth x1",
  370.                           "EvilMask x1",
  371.                           "Behemoth x2",
  372.                           "EvilMask x2",
  373.                           "Red D. x3",
  374.                           "Breath x1",
  375.                           "Mind x1",
  376.                           "Behemoth x1",
  377.                           "Pudding x4",
  378.                           "Pudding x2, Grenade x2",
  379.                           "Balloon x2, Grenade x2",
  380.                           "Slime x1, Tofu x1, Pudding x1",
  381.                           "Red Worm x1, Grenade x3",
  382.                           "TrapRose x1, GlomWing x2, Crawler x2",
  383.                           "Medusa x1, Gorgon x1, Stoneman x1",
  384.                           "Talantla x1, BlackCat x2",
  385.                           "Egg(BlackLiz x1)",
  386.                           "Egg(Lamia x1)",
  387.                           "Egg(HugeNaga x1)",
  388.                           "Egg(Green Dragon x1)",
  389.                           "Egg(Yellow Dragon x1)"
  390.                         }
  391.  
  392.  
  393. local function retrievegroup(formation)
  394.  
  395.     if formation < 0x1DF then
  396.         return TableEnemyFormation[formation+1]
  397.     else
  398.         return "Unknown"
  399.     end
  400.    
  401. end
  402.  
  403. local function ecords_y(y)
  404.     local ex = bit.lshift(bit.band(y,0x0F),3) +0x0C - 0x16
  405.     return ex
  406. end
  407.  
  408. local function ecords_x(x)
  409.     local ey = bit.rshift(bit.band(x,0xF0),1) + 8 + 0x10
  410.     return ey
  411.  end
  412.  
  413. local function rndbattle()
  414.  
  415.     local steps = 0
  416.     local encounter = false
  417.     local val1 = 0
  418.     local val2 = 0
  419.     local val3 = 0
  420.     local val4 = 0
  421.     local val5 = 0
  422.     local rollover = false
  423.     local area = memory.readbyte(0x7E1700)
  424.  
  425.     if area == 0 then
  426.         -- Earth world map
  427.         while encounter == false do
  428.  
  429.             steps = steps +1
  430.  
  431.             val1 = bit.band(bit.rshift(memory.readbyte (0x7E1707),2),0xF8)
  432.             val2 = bit.rshift(memory.readbyte(0x7E1706),5) + val1
  433.             val3 = memory.readbyte(0x0EC300 + val2)
  434.             val4 = memory.readbyte(0x14EE00+((memory.readbyte(0x7E0686)+steps)) % 0x100)
  435.  
  436.             if (memory.readbyte(0x7E0686) + steps) % 0x100 == 0
  437.                 then rollover = true
  438.             end
  439.  
  440.             if rollover == true then
  441.                 val5 = (val4 + (memory.readbyte(0x7E17EF)) + 0x11) % 0x100
  442.             else
  443.                 val5 = (val4 + memory.readbyte(0x7E17EF)) % 0x100
  444.             end
  445.  
  446.             if val5 < val3 then
  447.                 gui.text(145,3,"(Earth world map)",0x0000FFFF)
  448.                 encounter = true
  449.             end
  450.  
  451.             if steps > 500 then
  452.                 encounter = true
  453.                 steps = 0
  454.                 gui.text(145,3,"(No Encounters)",0x0000FFFF)
  455.             end
  456.  
  457.         end
  458.        
  459.     elseif area == 1 then
  460.     -- Underground
  461.  
  462.             while encounter == false do
  463.  
  464.             steps = steps +1
  465.  
  466.             val1 = (memory.readbyte(0x7E0686) + steps) % 0x100
  467.             val2 = memory.readbyte(0x14EE00 + val1)
  468.  
  469.             if val1 == 0 then
  470.                 rollover =  true
  471.             end
  472.  
  473.             if rollover == true then
  474.                 val3 = val2 + ((memory.readbyte (0x7E17EF)+0x11) % 0x100)
  475.             else
  476.                 val3 = val2 + memory.readbyte (0x7E17EF)
  477.             end
  478.  
  479.             val3 = val3 % 0x100
  480.             val4 = memory.readbyte(0x0EC340)
  481.  
  482.             if val3 < val4 then
  483.                 gui.text(145,3,"(Underworld world map)",0x0000FFFF)
  484.                 encounter = true
  485.             end
  486.  
  487.             if steps > 500 then
  488.                 encounter = true
  489.                 gui.text(145,3,"(No Encounters)",0x0000FFFF)
  490.                 steps = 0
  491.             end
  492.  
  493.         end
  494.  
  495.     elseif area == 2 then
  496.     -- Moon
  497.         while encounter == false do
  498.  
  499.             steps = steps +1
  500.  
  501.             val1 = (memory.readbyte(0x7E0686) + steps) % 0x100
  502.             val2 = memory.readbyte(0x14EE00 + val1)
  503.  
  504.             if val1 == 0 then
  505.                 rollover = true
  506.             end
  507.  
  508.             if rollover == true then
  509.                 val3 = val2 + ((memory.readbyte(0x7E17EF) + 0x11)%0x100)
  510.             else
  511.                 val3 = val2 + memory.readbyte (0x7E17EF)
  512.             end
  513.  
  514.             val3 = val3 % 0x100
  515.             val4 = memory.readbyte(0x0EC341)
  516.  
  517.             if val3 < val4 then
  518.                 gui.text(145,3,"(Moon world map)",0x0000FFFF)
  519.                 encounter = true
  520.             end
  521.  
  522.             if steps > 500 then
  523.                 encounter = true
  524.                 gui.text(145,3,"(No Encounters)",0x0000FFFF)
  525.                 steps = 0
  526.             end
  527.  
  528.         end
  529.  
  530.     elseif area > 2 then
  531.     -- Dungeon
  532.  
  533.         while encounter == false do
  534.  
  535.             steps = steps +1
  536.  
  537.             val1 = memory.readbyte(0x7E1702)
  538.  
  539.             if memory.readbyte(0x7E1701) > 0 then
  540.                 val1 = val1 + 0x100
  541.             end
  542.  
  543.             val2 = memory.readbyte(0x0EC342+ val1)
  544.             val3 = memory.readbyte(0x7E0686) + steps
  545.             val3 = val3 % 0x100
  546.             val4 = memory.readbyte(0x14EE00 + val3)
  547.  
  548.             if val3 == 0 then
  549.                 rollover = true
  550.             end
  551.  
  552.             if rollover == true then
  553.                 val5 = val4 + ((memory.readbyte(0x7E17EF) + 0x11) % 0x100)
  554.             else
  555.                 val5 = val4 + memory.readbyte(0x7E17EF)
  556.             end
  557.  
  558.             val5 = val5 % 0x100
  559.  
  560.             if val5 < val2 then
  561.                 gui.text(145,3,"(Dungeon)",0x0000FFFF)
  562.                 encounter = true
  563.             end
  564.  
  565.             if steps > 500 then
  566.                 encounter = true
  567.                 gui.text(145,3,"(No Encounters)",0x0000FFFF)
  568.                 steps = 0
  569.             end
  570.  
  571.         end
  572.  
  573.     end
  574.  
  575.     return steps
  576.  
  577. end
  578.  
  579. local function enemygroup(num)
  580.  
  581.     local area = memory.readbyte(0x7E1700)
  582.     local group = nil
  583.     local x = 0
  584.     local x2 = 0
  585.     local val1 = 0
  586.     local val2 = 0
  587.     local val3 = 0
  588.     local rollover = false
  589.     local rollover2 = false
  590.     local i = 0
  591.  
  592.     if area == 0 then
  593.     -- Earth world map
  594.         for i=0, num do
  595.  
  596.             val1 = bit.band(bit.rshift(memory.readbyte(0x7E1707),2), 0xF8)
  597.             x = (bit.rshift(memory.readbyte(0x7E1706),5) + val1)  % 0x100
  598.             val2 = bit.lshift(memory.readbyte(0x0ec542+x),3)
  599.             x2 = (memory.readbyte(0x7E0687) + i) % 0x100
  600.  
  601.             if (memory.readbyte(0x7E0687) + i) % 0x100 == 0xFF then
  602.                 rollover = true
  603.             end
  604.  
  605.             if rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) == 0xFF then
  606.                 val3 = memory.readbyte(0x7E17EE) +0x11
  607.             elseif rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) ~= 0xFF then
  608.                 val3 = memory.readbyte(0x14EE00 + x2) + ((memory.readbyte(0x7E17EE) + 0x11)  % 0x100)
  609.             elseif rollover == false then
  610.                 val3 = memory.readbyte(0x14EE00 + x2) + memory.readbyte(0x7E17EE)
  611.             end
  612.  
  613.             val3 = val3 % 0x100
  614.             --val3 = (memory.readbyte(0x14ee00+x2) + memory.readbyte(0x7E17EE)) % 0x100
  615.  
  616.             if val3 > 0xFC  then
  617.                 val2 = val2 + 7
  618.             elseif val3 > 0xEC then
  619.                 val2 = val2 + 6
  620.             elseif val3 > 0xCC then
  621.                 val2 = val2 + 5
  622.             elseif val3 > 0xAC then
  623.                 val2 = val2 + 4
  624.             elseif val3 > 0x81 then
  625.                 val2 = val2 + 3
  626.             elseif val3 > 0x56 then
  627.                 val2 = val2 + 2
  628.             elseif val3 > 0x2B then
  629.                 val2 = val2 + 1
  630.             end
  631.  
  632.             val2 = memory.readbyte(0xEC796+val2)
  633.  
  634.             if memory.readbyte(0x7E1701)  > 0 then
  635.                 val2 = val2 + 0x100
  636.             end
  637.  
  638.             group = val2
  639.  
  640.         end
  641.  
  642.     elseif area == 1 then
  643.         -- Underground world map
  644.  
  645.         for i=0, num do
  646.  
  647.             val1 = bit.band(bit.rshift(memory.readbyte(0x7E1707),3),0xFC)
  648.             x = bit.rshift(memory.readbyte(0x7E1706),5)
  649.             x = (x + val1)  % 0x100
  650.             val2 = bit.lshift(memory.readbyte(0x0ec582+x),3)
  651.             x2 = (memory.readbyte(0x7E0687) + i)  % 0x100
  652.  
  653.             if memory.readbyte(0x7E0687) == 0xFF then
  654.                 rollover = true
  655.             end
  656.  
  657.             if rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) == 0xFF then
  658.                 val3 = memory.readbyte(0x7E17EE) +0x11
  659.             elseif rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) ~= 0xFF then
  660.                 val3 = memory.readbyte(0x14EE00 + x2) + ((memory.readbyte(0x7E17EE) + 0x11)  % 0x100)
  661.             elseif rollover == false then
  662.                 val3 = memory.readbyte(0x14EE00 + x2) + memory.readbyte(0x7E17EE)
  663.             end
  664.  
  665.             val3 = val3 % 0x100
  666.  
  667.             if val3 > 0xFC  then
  668.                 val2 = val2 + 7
  669.             elseif val3 > 0xEC then
  670.                 val2 = val2 + 6
  671.             elseif val3 > 0xCC then
  672.                 val2 = val2 + 5
  673.             elseif val3 > 0xAC then
  674.                 val2 = val2 + 4
  675.             elseif val3 > 0x81 then
  676.                 val2 = val2 + 3
  677.             elseif val3 > 0x56 then
  678.                 val2 = val2 + 2
  679.             elseif val3 > 0x2B then
  680.                 val2 = val2 + 1
  681.             end
  682.  
  683.             val2 = memory.readbyte(0xEC796+val2)
  684.  
  685.             if memory.readbyte(0x7E1701) > 0 then
  686.                 val2 = val2 + 0x100
  687.             end
  688.  
  689.             group = val2
  690.  
  691.         end
  692.  
  693.     elseif area == 2 then
  694.     --Moon world map
  695.         for i = 0, num do
  696.  
  697.             if memory.readbyte(0x7E1707) > 0x20 then
  698.                 x = 2
  699.             end
  700.  
  701.             if memory.readbyte(0x7E1706) > 0x20 then
  702.                 x = x + 1
  703.             end
  704.  
  705.             if (memory.readbyte(0x7E0687) + i) %0x100 == 0xFF then
  706.                 rollover = true
  707.             end
  708.  
  709.             val2 = memory.readbyte(0x0EC592 + x)
  710.             val2 = bit.lshift(val2,3)
  711.             x2 = (memory.readbyte(0x7E0687) + i) % 0x100
  712.  
  713.             if rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) == 0xFF then
  714.                 val3 = memory.readbyte(0x7E17EE) +0x11
  715.             elseif rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) ~= 0xFF then
  716.                 val3 = memory.readbyte(0x14EE00 + x2) + ((memory.readbyte(0x7E17EE) + 0x11)  % 0x100)
  717.             elseif rollover == false then
  718.                 val3 = memory.readbyte(0x14EE00 + x2)+ memory.readbyte(0x7E17EE)
  719.             end
  720.  
  721.             val3 = val3 % 0x100
  722.  
  723.             if val3 > 0xFC  then
  724.                 val2 = val2 + 7
  725.             elseif val3 > 0xEC then
  726.                 val2 = val2 + 6
  727.             elseif val3 > 0xCC then
  728.                 val2 = val2 + 5
  729.             elseif val3 > 0xAC then
  730.                 val2 = val2 + 4
  731.             elseif val3 > 0x81 then
  732.                 val2 = val2 + 3
  733.             elseif val3 > 0x56 then
  734.                 val2 = val2 + 2
  735.             elseif val3 > 0x2B then
  736.                 val2 = val2 + 1
  737.             end
  738.  
  739.             val2 = memory.readbyte(0x0EC796+val2)
  740.  
  741.             if memory.readbyte(0x7E1701) > 0 then
  742.                 val2 = val2 + 0x100
  743.             end
  744.  
  745.             group = val2
  746.  
  747.         end
  748.  
  749.     elseif area > 2 then
  750.  
  751.         for i=0, num do
  752.         --Dungeon
  753.             val1 = memory.readbyte(0x7E1702)
  754.  
  755.             if memory.readbyte(0x7E1701) > 0 then
  756.                 val1 = val1 + 0x100
  757.             end
  758.  
  759.             val2 = bit.lshift(memory.readbyte(0x0EC596+val1),3)
  760.             val3 = memory.readbyte(0x14EE00 + ((memory.readbyte(0x7E0687)+i)%0x100))
  761.  
  762.             if memory.readbyte(0x7E0687) == 0xFF then
  763.                 rollover = true
  764.             end
  765.  
  766.             if rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) == 0xFF then
  767.                 val3 = (memory.readbyte(0x7E17EE)+0x11) % 0x100
  768.             elseif rollover == true and ((memory.readbyte(0x7E0687)+i)%0x100) ~= 0xFF then
  769.                     val3 = val3 + ((memory.readbyte(0x7E17EE) + 0x11) % 0x100)
  770.             elseif rollover == false then
  771.                 val3 = val3 + memory.readbyte(0x7E17EE)
  772.             end
  773.  
  774.             val3 = val3 % 0x100
  775.  
  776.             if val3 > 0xFC  then
  777.                 val2 = val2 + 7
  778.             elseif val3 > 0xEC then
  779.                 val2 = val2 + 6
  780.             elseif val3 > 0xCC then
  781.                 val2 = val2 + 5
  782.             elseif val3 > 0xAC then
  783.                 val2 = val2 + 4
  784.             elseif val3 > 0x81 then
  785.                 val2 = val2 + 3
  786.             elseif val3 > 0x56 then
  787.                 val2 = val2 + 2
  788.             elseif val3 > 0x2B then
  789.                 val2 = val2 + 1
  790.             end
  791.  
  792.             val4 = memory.readbyte(0x0EC816 + val2)
  793.  
  794.             if memory.readbyte(0x7E1701) > 0 then
  795.                 val4 = val4 + 0x100
  796.             end
  797.  
  798.             group = val4
  799.  
  800.         end
  801.  
  802.     end
  803.  
  804.     return group
  805.  
  806. end
  807.  
  808. local function predictgroup()
  809.     gui.text(3,13,"Encounter Groups:",0xABFF93FF)
  810.     for i = 0, groupmax-1 do
  811.         if i == 0 then
  812.             gui.text(3,23,"1: " .. retrievegroup(enemygroup(i)) .. " (0x" .. string.format("%X",enemygroup(i)) .. ")",0xABFF93FF)
  813.         else
  814.             gui.text(3,23+(10 * i),i+1 .. ": " .. retrievegroup(enemygroup(i)) .. " (0x" .. string.format("%X",enemygroup(i)) .. ")",0xFFFFFF7F)
  815.         end
  816.     end
  817.  end
  818.  
  819. local function enemygroupexists(num)
  820.  
  821.    local area = memory.readbyte(0x7E1700)
  822.    local group = 0
  823.    local x = 0
  824.    local x2 = 0
  825.    local val1 = 0
  826.    local val2 = 0
  827.    local val3 = 0
  828.    local rollover = false
  829.    local rollover2 = false
  830.    local i = 0
  831.    local j = 0
  832.    
  833.    if area == 0 then
  834.    -- Earth world map
  835.      
  836.          val1 = bit.band(bit.rshift(memory.readbyte(0x7E1707),2), 0xF8)
  837.          x = (bit.rshift(memory.readbyte(0x7E1706),5) + val1)  % 0x100
  838.          val2 = bit.lshift(memory.readbyte(0x0ec542+x),3)
  839.  
  840.          for j = val2, val2+7 do
  841.             if num == memory.readbyte(0xEC796+j) then
  842.                group = 1
  843.             end
  844.             if memory.readbyte(0x7E1701)  > 0 then
  845.                if num == (memory.readbyte(0xEC796+j)+0x100) then
  846.                   group = 1
  847.                end
  848.             end
  849.          end
  850.  
  851.    elseif area == 1 then
  852.       -- Underground world map
  853.  
  854.          val1 = bit.band(bit.rshift(memory.readbyte(0x7E1707),3),0xFC)
  855.          x = bit.rshift(memory.readbyte(0x7E1706),5)
  856.          x = (x + val1)  % 0x100
  857.          val2 = bit.lshift(memory.readbyte(0x0ec582+x),3)
  858.          
  859.          
  860.          for j = val2, val2+7 do
  861.             if num == memory.readbyte(0xEC796+j) then
  862.                group = 1
  863.             end
  864.             if memory.readbyte(0x7E1701)  > 0 then
  865.                if num == (memory.readbyte(0xEC796+j)+0x100) then
  866.                   group = 1
  867.                end
  868.             end
  869.          end
  870.  
  871.    elseif area == 2 then
  872.    --Moon world map
  873.  
  874.          if memory.readbyte(0x7E1707) > 0x20 then
  875.             x = 2
  876.          end
  877.          
  878.          if memory.readbyte(0x7E1706) > 0x20 then
  879.             x = x + 1
  880.          end
  881.          
  882.          val2 = memory.readbyte(0x0EC592 + x)
  883.          val2 = bit.lshift(val2,3)
  884.          
  885.          for j = val2, val2+7 do
  886.             if num == memory.readbyte(0xEC796+j) then
  887.                group = 1
  888.             end
  889.             if memory.readbyte(0x7E1701)  > 0 then
  890.                if num == (memory.readbyte(0xEC796+j)+0x100) then
  891.                   group = 1
  892.                end
  893.             end
  894.          end
  895.  
  896.    elseif area > 2 then
  897.  
  898.       --Dungeon
  899.          val1 = memory.readbyte(0x7E1702)
  900.          
  901.          if memory.readbyte(0x7E1701) > 0 then
  902.             val1 = val1 + 0x100
  903.          end
  904.          
  905.          val2 = bit.lshift(memory.readbyte(0x0EC596+val1),3)  
  906.          
  907.          for j = val2, val2+7 do
  908.             if num == memory.readbyte(0xEC816+j) then
  909.                group = 1
  910.             end
  911.             if memory.readbyte(0x7E1701)  > 0 then
  912.                if num == (memory.readbyte(0xEC796+j)+0x100) then
  913.                   group = 1
  914.                end
  915.             end
  916.          end
  917.  
  918.    end
  919.  
  920.    return group
  921.  
  922. end
  923.  
  924. local function findenemy(e,x)
  925.  
  926.     local c = 0
  927.     local i = 0
  928.     local result  = ": "
  929.  
  930.     if enemygroupexists(e) == 0 then
  931.         result = "(Enemy not present in area)"
  932.         return result
  933.     end
  934.  
  935.     while c ~= x  do
  936.         if enemygroup(i) == e then
  937.             c = c +1
  938.  
  939.             if c ~= x then
  940.                 result = result .. i .. ","
  941.             else
  942.                 result = result .. i
  943.             end
  944.  
  945.         end
  946.  
  947.       i = i + 1
  948.  
  949.       if i >= 500 and c == 0 then
  950.          result = "(Enemy not present in next 500 battles)"
  951.          c = x
  952.       end
  953.     end
  954.  
  955.     result = retrievegroup(e) .. " (" .. string.format("%X",e) .. ")" .. result
  956.     return result
  957.  
  958. end
  959.  
  960. local function drawatb_e(x,y,atb,e)
  961.     gui.box(x-3, y-4, x+17, y-1, 0x00000000, 0x000000FF)
  962.  
  963.     if atb == 0 then
  964.         enemy_atbm[e] = 0
  965.         gui.box(x-3, y-4, x+17, y-1, 0xFF0000C0, 0000000000)
  966.  
  967.     else
  968.         if enemy_atbm[e] == 0 then
  969.             enemy_atbm[e] = atb
  970.         end
  971.  
  972.         gui.box(x-3, y-4, (x-3)+20-((20/enemy_atbm[e])*atb), y-1, 0xFF0000C0, 0000000000)
  973.         --gui.text(x,y, enemy_atb[e] .. "/" .. enemy_atbm[e])
  974.  
  975.     end
  976. end
  977.  
  978. local function drawatb_c(x,y,atb,c)
  979.     gui.box(x-3, y-4, x+17, y-1, 0x00000000, 0x000000FF)
  980.  
  981.     if atb == 0 then
  982.         char_atbm[c] = 0
  983.         gui.box(x-3, y-4, x+17, y-1, 0xFFFF00C0, 0000000000)
  984.  
  985.     else
  986.         if char_atbm[c] == 0 then
  987.             char_atbm[c] = atb
  988.         end
  989.        
  990.         gui.box(x-3, y-4, (x-3)+20-((20/char_atbm[c])*atb), y-1, 0xFFFF00C0, 0000000000)
  991.         --gui.text(x,y, character_atb[c] .. "/" .. char_atbm[c])
  992.  
  993.     end
  994. end
  995.  
  996. -- For who knows what reason, the data of the characters are not in order, so this fix it
  997. local function fix(character)
  998.     fix_order = {3, 1, 5, 2, 4}
  999.     return fix_order[character]
  1000. end
  1001.  
  1002. while true do
  1003.  
  1004.     character_atb = {}
  1005.     character_x = {}
  1006.     character_y = {}
  1007.    
  1008.     for c=1, 5 do
  1009.         character_atb[fix(c)] = memory.readbyte(0x7E2A07 + 0x15*(c-1))
  1010.         character_x[fix(c)]   = memory.readbyte(0x7EEFC5 + 0x10*(c-1))
  1011.         character_y[fix(c)]   = memory.readbyte(0x7EEFC6 + 0x10*(c-1))
  1012.     end
  1013.  
  1014.  
  1015.     enemy_atb = {}
  1016.     enemy_cur_hp = {}
  1017.     enemy_max_hp = {}
  1018.     enemy_xy = {}
  1019.  
  1020.     for e=1, 8 do
  1021.         enemy_atb[e]    = memory.readbyte(0x7E2A70 + 0x15*(e-1))
  1022.         enemy_cur_hp[e] = memory.readword(0x7E2287 + 0x80*(e-1))
  1023.         enemy_max_hp[e] = memory.readword(0x7E2289 + 0x80*(e-1))
  1024.         enemy_xy[e]     = memory.readbyte(0x7E29A5 + 0x01*(e-1))
  1025.     end
  1026.  
  1027.     battle = memory.readbyte(0x7E0201)
  1028.     attack = memory.readbyte(0x7E3581) -- normal 00, back 08
  1029.  
  1030.     if battle ~= 0x85 then
  1031.  
  1032.         for c=1, 5 do
  1033.             drawatb_c(character_x[c], character_y[c], character_atb[c], c)
  1034.         end
  1035.  
  1036.         for e=1, 8 do
  1037.             if enemy_cur_hp[e] > 0 then
  1038.                 gui.text( ecords_x(enemy_xy[e]), ecords_y(enemy_xy[e]), e .. " " .. enemy_cur_hp[e] .. "/" .. enemy_max_hp[e] )
  1039.                 drawatb_e(ecords_x(enemy_xy[e]), ecords_y(enemy_xy[e]), enemy_atb[e], e)
  1040.             end
  1041.         end
  1042.  
  1043.     else
  1044.    
  1045.         for i=1,5 do
  1046.             char_atbm[i] = 0
  1047.         end
  1048.  
  1049.         for i=1,8 do
  1050.             enemy_atbm[i] = 0
  1051.         end
  1052.  
  1053.         gui.text(  3, 3, "Steps until random battle: ")
  1054.         gui.text(111, 3, rndbattle(), 0xFFFF00FF)
  1055.         gui.text(125, 3, "("..string.format("%X",memory.readbyte(0x7E0686)) .. ")")
  1056.  
  1057.         if rndbattle() ~= 0 then
  1058.             predictgroup()
  1059.         end
  1060.  
  1061.         -- Uncomment to find a specific enemy group, the way its implemented slows the emulator down tremendously if its a rare spawn or a high amount is desired
  1062.         -- format is findenemy(ENEMY VALUE,NEXT NUMBER OF ENCOUNTERS)
  1063.         -- I.E. findenemy(0x196,5) will look for the next 5 pink puff encounters
  1064.         --gui.text(5,100,findenemy(0x196,2))
  1065.     end
  1066.  
  1067.     snes9x.frameadvance()
  1068.  
  1069. end
  1070.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement