Request Odd (math) problem to solve in AutoIt/AutoHotkey script

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

TomeWyrm

New Member
Jul 29, 2019
898
1
1
TL;DR I want to make a script that will teleport me in an ever-widening spiral from the center of a set of 4 bounding coordinates I choose (which can be set in the script file), preferably with the ability to exclude a (likely central) zone so as to aid in resumption after interruption. I'm using AutoHotKey because
A: I use AHK already anyway
B: It is usable in any console (CLI or the default MC server console) or even in single player (assuming cheats are enabled, of course). Which beats out the only script I've seen to date nethergen.sh in part 2 of this Reddit post.



So I have a mod pack (based on the Absque Sole sub-pack of Resonant Rise 3). I added many mods, but the important ones in this case are the Reasonable Realism mods by Draco18s. Not in and of themselves, but because they require Custom Ore Generation. I pre-generate all my worlds to prevent the single worst source of lag during normal play: Chunk Generation.

So most of you unfamiliar with COG at this point are probably wondering what the issue is.

The issue is that my usual methods of pre-generating the world aren't working! Admin Command Toolkit either crashes the world or stops running, and Minecraft Land Generator would take a frankly obscene amount of time to generate a reasonably sized world with some of my mods (yes even pared down to the ones that are REQUIRED for World Generation).

Enter my current AutoHotKey script.
Code:
SetKeyDelay 100

Pause::Pause

$HOTKEYGOESHERE::
XStart := -512
ZStart := -512
XEnd := 512
ZEnd := 512
TeleportGap := 64

XCoord := XStart
ZCoord := ZStart
While XCoord <= XEnd
  {
    While ZCoord <= XEnd
      {
        Send /tp %XCoord% 256 %ZCoord%{enter}
        ZCoord += TeleportGap
        Sleep, 2500
      }
    ZCoord:= ZStart
    XCoord+= TeleportGap
  }
Return

Which methodically goes from the NW corner of the selected grid, teleports with whatever spacing you set, and goes south through the whole series of values, teleports one gap's width to the east and back up at the most northern coordinate, repeating until it hits the X/Z end values.

This works reasonably well, but is extremely inelegant, obnoxious to start/stop, causes some lag when it starts the next "column" of teleports, and also doesn't do very much good if you need to stop in the middle for some reason; the generated terrain is almost certainly nowhere near spawn, and if you have some form of mapping it looks HORRIBLE.

Which is where I'm asking for help. I can conceive of a better method, and the simple steps within which to produce those sets of coordinates to teleport to... I just can't translate that to a working script.

It's simple: a spiral!

  • Start at the center of a given quartet of coordinates.
  • Teleport after each math step.
  • Increment your X coordinate by the gap amount
  • Increment your Z coordinate by the gap amount
  • Decrement X by gap amount twice
  • Decrement Z by gap amount twice
  • Increment X by gap amount thrice
  • Increment Z by gap amount thrice
  • Repeat, switching increment/decrement every X and increasing the number of times you do so by 1 each switch.
  • Stop when you've reached (or exceeded) any two of "start" or "end" coordinates.

You could even probably add the ability to exclude a zone for people that already have some terrain generated, or need to resume at a later date or something. Probably with some if statements like
Code:
If X > XZoneMin
  AND X < XZoneMax
  AND Z > ZZoneMin
  AND Z <ZZoneMax
    Skip Teleport Step
else Teleport Step

I'm sure there's a better way to do that, too :)






Which brings me to the point... anyone able to actually make that script a reality?

If you want to check to see if something is possible http://ahkscript.org/docs/Variables.htm
That page should be all you need, if not this is the base page for the documentation: http://ahkscript.org/docs/AutoHotkey.htm
 

zemerick

New Member
Jul 29, 2019
667
0
1
A simple way is to do an If direction.

Something like:

Code:
If direction = north {
    while Zcoord <= centerZ + length/2 {
        teleport code
        Zcoord + gap
    }
}
else if direction = west{
    while XCoord >= centerX - length/2 {
        teleport code
       XCoord - gap
}

etc. This way, you only have to handle 1 leg each time. Then, you just rotate the direction in a set spiral. Something at the end like:

Code:
if direction = north {
    direction == east
}

All of that inside a simple while loop, like:

Code:
while XCoord <= XEnd && ZCoord <= ZEnd{
}

There's a few details to work out, especially if you want some of your added features. Unfortunately I don't know AHK scripting ( and I'm already trying to learn JAVA ), but this should get you moving in the right direction. Maybe someone who actually knows it can pop in with a better/more complete solution.

Warning: There might be some issues with my specific code, that is just supposed to be a quick example. For the love of all things code, don't copy and paste:) You should be able to work out the details on your own though, and learn that much more about AHK scripting.
 

TomeWyrm

New Member
Jul 29, 2019
898
1
1
I knew it would take some additional variables. I think I'll try this sometime later today/tomorrow and report back. I think the only thing I need to add is length incrementing every paired direction (east/west, north/south).

Incidentally I think I actually could copy/paste that (and substitute obviously), and it should work. AutoIt is a pretty natural scripting language.