• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Help with Breeding Bot Macro

3
Posts
4
Years
    • Seen Jul 2, 2019
    I would like to write a LUA script for Pokemon Black 2 that walks back and forth, collects eggs from the Day Care man and deposits those eggs into the PC before repeating the process. The goal is to have a breeding bot that will collect a large number of eggs for IV and shiny hunting while I'm AFK. I've already done something similar with a macro on my computer but I think the whole process could be done more efficiently with a LUA script; can anyone point me towards a tutorial or someone else who has attempted something like this?
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Do you know Lua? If not I guess the first place to start is a generic Lua tutorial. You'll have to check your emulator's documentation for how to program macros for it—you've not mentioned/linked to the emulator you're using so we can't help with that.

    I guess the things you want to look for are:

    1. Which memory address contains whether or not an egg is ready at the Day Care.
    2. Which memory address contains how many Pokémon are in the current box (it's probably N+1 memory addresses, where the 1 is the current box, and the N are for each slot whether there's a Pokémon in that slot).

    Both of these you can probably find using a regular memory editor/explorer.
    You'll also have to think about how you want to handle moving the player around—I'd probably just hand code all the paths (i.e. turn your walking macros directly into code) rather than try and do any generic path finding.
     
    Last edited:
    3
    Posts
    4
    Years
    • Seen Jul 2, 2019
    I'm using DeSmuME to emulate Black 2, I've read a handful of LUA tutorials but unfortunately haven't been able to find any instructions for what I specifically want to do. Basically all I would need to know is how to write a script that moves my character back and forth along Route 3 stopping frequently to pick eggs up from the daycare man as they spawn then drops those eggs off in the PC and repeats. The only thing I really need to know how to code in LUA is making the emulator do a single button press; I read the TASvideos tutorial (tasvideos(dot)org(slash)LuaScripting(dot)html) on how to write a script that autofires a button but I'm unsure of how to use the joypad.set function to issue a single button press instead of just holding the button down. Can anyone with LUA knowledge inform me of what that code would be?
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    If you know how to hold down a button, is there some way to specify how long to hold that button for? Presumably a single button press is just holding the button for a small number of frames.

    If I were you I'd either be looking for a parameter that is the number of frames to hold for, or a function that pauses the script for a number of frames (which might be called sleep or wait?). In any case, it's more of a DeSmuME question than a Lua one, so I'd expect to find the answer in the emulator manual rather than in a Lua tutorial.

    EDIT: Moved this to ROM hacking. Not sure if that's the best place, maybe a RH mod will come by and move it again.
     
    Last edited:
    3
    Posts
    4
    Years
    • Seen Jul 2, 2019
    Right now the LUA script I've written holds each button down for fifteen frames before releasing it, which the emulator counts as one button press. I have managed to script my character walking back and forth and talking to the daycare guy which adds the eggs to my party, now I have to write the sequence of moving my character into the daycare and dropping the eggs in the PC. The script for each button press looks like this:

    while true do
    joypad.set(1, {up=true})
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    joypad.set(1, {up=false})
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()
    emu.frameadvance()

    Coding it like this works well for what I'm trying to do but dealing with so many lines of code is unwieldy. I have only the most basic experience with coding so I'm sure that this is a very primitive script, can anyone with LUA experience suggest a way that I could clean this up? Basically I need the script to pause for ~15 frames while the button is held down and I'm not sure of how to do that besides putting in fifteen individual frameadvance commands.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    So there are a few things you want to look into.

    First is a loop, usually a for loop (although you could use a while loop and a variable to act as a counter), which will let you say "repeat this n times" (where in your case n will be 15).

    Second you might want to look into functions, so that you can wrap the for loop in a more convenient command. This would make it possible for you to replace your set-wait-set-wait with something like holdButton("up").

    Finally you might want to look into arrays, so that you can have a list of buttons to press and loop over them, e.g. something like buttons = {"up", "up", "right"} (plus a loop over buttons) instead of holdButton("up"); holdButton("up"); holdButton("right").
     
    Last edited:
    Back
    Top