Advertiser Content

Help with Breeding Bot Macro

Started by marcelbruer June 27th, 2019 8:58 AM
  • 1130 views
  • 5 replies
Seen July 2nd, 2019
Posted July 2nd, 2019
3 posts
52 Days
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?

mgriffin

Online now
Posted 1 Hour Ago
600 posts
5.3 Years
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.
Seen July 2nd, 2019
Posted July 2nd, 2019
3 posts
52 Days
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?

mgriffin

Online now
Posted 1 Hour Ago
600 posts
5.3 Years
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.
Seen July 2nd, 2019
Posted July 2nd, 2019
3 posts
52 Days
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.

mgriffin

Online now
Posted 1 Hour Ago
600 posts
5.3 Years
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").
Advertiser Content