DocsMegalithObjects and the world

Objects, attachments and physics

Any object reference works with these: a player's biped, an object in a loop, or one the script created.

place_at_me(type, label, flags, x, y, z, variant)
Creates an object at this one and returns it. See creating objects.
delete(), kill(false)
Removes it, or destroys it as damage would. kill(true), a silent kill, stops the script.
attach_to(other, x, y, z, relative)
Sticks it to another object, offset by −128 to 127 tenths of a Forge unit. relative follows the other object's facing, absolute the map's. Detach before attaching it elsewhere.
detach()
Lets it go where it is.
get_carrier()
The player found through the attachment parents, or no_player.
set_hidden(true)
Hides it, for every player.
set_invincibility(true)
Makes it take no damage. Kill boundaries still remove it.
set_garbage_collection_disabled(true)
Stops the game from cleaning it up when it lies around. Invincibility alone doesn't.
set_scale(50)
Its size in percent, 10 to 300. A player's body: each of theirs from now on. 0 or less does nothing; other values out of range stop the script.
set_velocity(x, y, z)
Sets it moving, in Forge units a second along the world's axes, at most 100 each. A player's body moves on every PC, so a player who joined is pushed just as the host is.
get_velocity_x(), get_velocity_y(), get_velocity_z()
How fast it moves along each of the world's axes, in thousandths of a Forge unit a second, fine enough for a slow body. set_velocity sets the same speed in whole units.
add_velocity(x, y, z)
Pushes it: its velocity changed by this much, in set_velocity's units.
is_grounded()
(condition) A player's body: on the ground, not in the air. Anything else: at rest.
phys_locked(0 or 1), is_phys_locked()
Held where it is, still, until let go, as Forge's Fixed physics holds an object: every PC sees it stay.
get_speed()
Feet a second, as a whole number.
get_distance_to(other)
Distance in tenths of a Forge unit, rounded up, at least 1 for objects that exist and 0 for no_object.
get_x(), get_y(), get_z()
Where it is, in tenths of a Forge unit.
get_yaw(), get_pitch(), get_roll()
Which way it faces, in degrees.
set_position(x, y, z)
Moves it there, in tenths. An attached object stays with its parent until it's detached. A zone the mode declares moves with it.
set_rotation(yaw, pitch, roll)
Turns it, in degrees. An attached object keeps its facing.
face_toward(target, x, y, z)
Turns it about its own up until it faces target, as Reach's rotate-toward action does. Scripts that ask for rotate_to want this one.
copy_rotation_from(other, true)
Turns it to face as the other does: true fully, false heading only. An attached object keeps its facing.
move_to(x, y, z)
Kept for older scripts: set_position in whole Forge units, within 100,000.
team
The team it belongs to, such as a flag's or a team's Forge object, else no_team. Read only.
health, shields, max_health, max_shields
Health and shields left, in percent of the maximums, and the maximums, in percent of the character's own. See health, shields and seats.
set_vehicle_use(0 or 1), set_turret_use(0 or 1)
A player's body: as the player's own call. Another biped: whether it may ride vehicles or use turrets.
set_difficulty(easy, normal, heroic, legendary or none)
An AI's body: the difficulty it fights at from now on, how it aims, how long it fires and the damage it deals; none gives its spawner's or the game's again. Its health and shields stay as they were when it was made.
get_driver(), get_seat_occupant(seat), get_occupant_count(), get_seat_count()
A vehicle's riders. See vehicles and seats.
is_of_type(type)
(condition) Tests what it is. See object types.
has_forge_label("gift")
(condition) Tests for a label, on a Forge object, one the script made, or one the mode declares.
set_forge_label("label" or none)
A label of the script's own on any object, beside its Forge label and the label it was made with: for each object with label and has_forge_label then find it by either. none takes the script's own off. At most 1,024 objects carry one.
duplicate("label")
A copy of the object where it is, under that label.
shape_contains(other)
(condition) Whether another object is inside this zone. See Forge zones.
spawn_sequence
The Spawn Sequence saved on a Forge object, −128 to 127, read only. 0 for objects without one.
play_sound("path"), start_looping_sound("path")
See sounds.
set_waypoint_visibility, set_waypoint_icon, set_waypoint_priority
See waypoints.
set_damage_from, set_damage_team, set_damage_player, set_damage_multiplier, apply_damage
See damage.
set_deploy_point, get_territory_owner, get_capture_progress
See squads and the deployment map.

Creating objects

  • type is anything in object types that can be made, or the name of an object the mode declares. It must be a constant: a name, a text, or an object to copy.
  • label is a text or number for for each object with label, or none. flags is none, absolute_orientation or never_garbage_collect, one at a time. The offsets are constants in tenths of a Forge unit, −128 to 127, along the object's heading. The last value is none or, for a body, one of its model variants.
  • Up to 2,048 created objects at a time (16 for each of 128 players): delete the ones you're done with. Created objects are removed when the round ends, except bodies players are in, and sizes, hiding and invincibility go back to normal.
  • An attached object can sit where a loose one can't survive: check where things land when you detach them on your map.
  • absolute_orientation makes offsets follow the object's full orientation; the other flags use its heading.
  • A no_object basis gives no_object. Named objects the map lacks, or that the engine refuses, stop the script.

You can use a newly returned object in the same event; its position and rotation are provisional until the next tick. A biped reached through a player and through an object loop is the same reference, with the same variables.

Attachment cycles and chains over 32 objects stop the script. Attaching to yourself or no_object, or attaching an object that's already attached, does nothing. Attachments keep the object's world orientation and size. Round cleanup restores size, visibility, protection and garbage collection; moves, deletions and attachment changes aren't generally reversed. Pass false to set_hidden, set_invincibility or set_garbage_collection_disabled to take that back.

The Object Controls example puts it together:

megalo-object-controls.rmeg
-- Each life gets a miniature shotgun, attached to the player for five
-- seconds before it drops into the world. Halo 3 must supply the weapon tag.
alias gift = player.object[0]
alias previous_body = player.object[1]
alias stage = player.number[0]
alias release_time = player.timer[0]
declare player.timer[0] = 5
declare global.timer[0] = 60

on init: do
    global.timer[0].set_rate(-100%)
end

for each player do
    if current_player.is_not_respawning() then
        if current_player.previous_body != current_player.biped then
            current_player.previous_body = current_player.biped
            current_player.stage = 0
        end
        if current_player.stage == 0 then
            current_player.gift = current_player.biped.place_at_me(shotgun, "gift", never_garbage_collect, 0, 0, 5, none)
            current_player.gift.set_scale(50)
            current_player.gift.set_invincibility(true)
            current_player.gift.attach_to(current_player.biped, 0, 0, 5, relative)
            current_player.release_time.reset()
            current_player.release_time.set_rate(-100%)
            current_player.stage = 1
        end
        if current_player.stage == 1 and current_player.release_time.is_zero() then
            current_player.gift.detach()
            current_player.gift.set_invincibility(false)
            current_player.gift.set_velocity(0, 1, 0)
            current_player.stage = 2
        end
    end
end

global.number[0] = 0
for each object with label "gift" do
    global.number[0] += 1
end
script_widget[0].set_text("Scripted gifts: %n", global.number[0])
script_widget[0].set_visibility(all_players, true)
if global.timer[0].is_zero() then game.end_round() end

Taken away and made again

despawn()
Takes the object away. A Forge-placed one stays away (its respawn timer doesn't make it again) until respawn_objects names its label; another goes for good, as delete does.
game.respawn_objects("label")
Makes again, at their Forge places, the objects labeled label the mode took away.

A new round makes every Forge object again. To hold back a phase's vehicles and weapons, label them in Forge and take them away when the round starts:

Part of a script
on init: do
    for each object with label "phase_2" do
        current_object.despawn()
    end
end

Forge zones

shape_contains(object) tests a Forge object's zone too: the shape and size its Forge properties give it (Properties → Zone shape: a sphere's radius; a cylinder's radius, top and bottom; a box's width, length, top and bottom), turned with the object, as Halo 3's King of the Hill hills, territories and Forge's own zones have them. A zone the mode declares in its header keeps its own shape. An object's zone holds its own place, so current_object.shape_contains(current_object) tells whether it has one. A box's width and length are whole sizes, centered on the object.

A player's living body (shape_contains(current_player.biped)) counts as inside when its feet or a point of its body just above them are, as Halo 3's hills, territories and flag returns test it, so a player standing on a flag return plate set a little above the floor is in its zone. Any other object counts by its origin.