DavidJCobb / ReachVariantEditor

A tool for editing Halo: Reach game variants.
24 stars 9 forks source link

Control specific forge pieces in a script #10

Closed jackbrookes closed 3 years ago

jackbrookes commented 3 years ago

Could anyone point to API reference for how to control specific forge pieces in a script? I.e. set position of a wall, etc, if possible.

DavidJCobb commented 3 years ago

You would need to put a gametype label on the desired piece when editing your map in Forge. Then, you can use a for-each-object-with-label loop to run code for all objects with that label. The current_object object variable will hold the object that the code is currently running for.

As for how to actually move objects, there isn't a dedicated "set position" function, nor a "move object in X direction by Y many units" function. The general approach for moving an object by an arbitrary amount would be something like this:

  1. Spawn a Hill Marker near the object, at the direction and distance that you want.
  2. Attach the object to the Hill Marker, using (0, 0, 0) as the offset.
  3. Detach the object from the Hill Marker.
  4. Delete the Hill Marker.

It's a bit janky, but from what I remember, attaching and detaching is the same trick that Bungie used to move one object to another. These APIs will allow you to move objects with a precision of 0.1 Forge units; if for whatever reason you need to be more precise, you can use object.place_between_me_and with multiple Hill Markers; just make sure to delete all of the Hill Markers you spawn for that.

jackbrookes commented 3 years ago

Thank you I will give it a try!

jackbrookes commented 3 years ago

@DavidJCobb I would like to move an object over time, I have everything setup, but seems I can't use a timer object value in setting position. E.g. an example I expected to sawtooth an object across 2m distance:

global.number[0] = global.timer[0]
global.number[0] %= 20
example.attach_to(current_object, global.number[0], 0, 0, absolute)

Any suggestions on how to solve this?

ghost commented 3 years ago

@jackbrookes use object scaling to move an object a specific distance using a variable. You also have more precise control of the offset you are moving an object with scaling. In this old gametype I allow the user to use spawn squence to control the speed/offset per tick of an object they want to move and hill markers to point in the direction. Also my gametype does some weird stuff on the local trigger to allow non-hosts to see its smooth movement without it spazzing out. platform_v2_despawn_issue.zip

check out the gametype code and example map to learn how it works.

ghost commented 3 years ago

Also I made it so the platform moves players that are on top of it.

https://streamable.com/xcqthk

ghost commented 3 years ago

Keep in mind non-script made objects will despawn overtime when abandoned.