Buttons, equipment and class abilities
A script can hear the buttons players press, deploy Halo 3's equipment, mounted guns and vehicles, hand out equipment, refill ammunition, repair vehicles and spawn players where they chose. Together they make class abilities, such as active camouflage on a key or cover an engineer deploys. Only the host runs them: a player's PC sends nothing but which of their keys they pressed.
| You want | Use |
|---|---|
| A key that triggers an ability | The players' Ability 1 to Ability 4 keys, heard by on button press, with current_player as the player who pressed. See buttons in the script. |
| No repeats while a key is held | Built in: one event per press. is_button_held says the key is still down. |
| To react to Halo 3's own actions | button.jump, crouch, melee, grenade, equipment, flashlight and fire; is_button_held also reads reload, interact, zoom and the movement directions. |
| Active camouflage for a time, with a recharge | A trait set with camouflage 4 and two player timers (below), or the active_camo equipment. |
| Deployable cover, a turret, a Bubble Shield, a vehicle… | place_at_me with their names. |
| Equipment a class carries | current_player.give_equipment(name). |
| An ammunition point, repairs | refill_ammo() for the players near your object; is_of_type(vehicle), get_distance_to and the vehicle's health. |
| A spawn point the player chooses | A key or a script menu, then set_primary_respawn_object. |
| Classes and their loadouts | Classes and get_deployment_class(), or a class number the script keeps, as the Class Abilities example does. |
Ability keys
Every player has four keys for game modes, under Game Mode Abilities in Settings → Keyboard & Mouse and Settings → Controller:
| Key | Keyboard | Controller |
|---|---|---|
| Ability 1 | X | D-pad right |
| Ability 2 | 2 | D-pad left |
| Ability 3 | 3 | D-pad down |
| Ability 4 | H | Not bound |
- The controller column is Halo 3's default button layout. MCC's universal layouts and Infinite choose grenades with the D-pad, so there Ability 1 is D-pad down and Abilities 2 and 3 have no button until the player picks one.
- Players rebind them like any other key, and each split-screen player has their own.
- They do nothing in modes whose script doesn't listen, and never reach Halo 3 itself. They wait while chat, the pause menu or a script menu is open.
- Halo 3's button prompts don't name them. Say which key does what in your HUD text.
Buttons in the script
on button press: do
-- current_player pressed pressed_button.
if pressed_button == button.ability_1 then
current_player.score += 1
end
end
for each player do
if current_player.is_button_held(button.ability_2) then
-- Still held on this tick.
end
end
| Button | A press is | Held while |
|---|---|---|
ability_1 … ability_4 | The player's ability key going down | It's down |
jump | Jump | Jump is held |
crouch | Starting to crouch | Crouching; a controller's stick click toggles it |
melee | A melee attack starting | The attack lasts |
grenade | A grenade throw starting | The throw lasts |
equipment | The player using their equipment | A throw lasts |
flashlight | Flashlight: 4, D-pad up | It's held |
fire | The trigger of the weapon in hand | It's held |
reload, interact (the action button), zoom | No press: held only | It's held |
forward, back, left, right | No press: held only | The movement stick or keys push that way, past a third of the stick's way |
- Halo 3's own buttons still do what they always do; the script hears them too, and can't stop them. They're what the host sees the player do:
melee,grenadeandequipmentcount only when the player really attacks, throws or uses something. Multiplayer characters have no flashlight unless the host turns on a game type's Flashlight option, soflashlightis usually a free button that needs no new key. - Dead players can press too. Check
current_player.is_not_respawning()when an ability needs a body; while they wait, a key can choose their class or spawn point. - Holding a key doesn't repeat it. The host takes at most ten presses a second from a player.
Active camouflage on a key
Give the header a trait set with camouflage 4, invisible:
[[logic.megalo_traits]]
camouflage = 4
Then apply it while a player timer runs, and start a recharge:
alias camo = player.timer[0]
alias recharge = player.timer[1]
on button press: do
if pressed_button == button.ability_1 and current_player.is_not_respawning() and current_player.recharge.is_zero() then
current_player.camo = 8 -- invisible for 8 seconds
current_player.camo.set_rate(-100%)
current_player.recharge = 28 -- ready 20 seconds after
current_player.recharge.set_rate(-100%)
end
end
for each player do
if not current_player.camo.is_zero() then
current_player.apply_traits(script_traits[0])
end
end
To show the recharge in a placed widget, assign the timer to a number, such as current_player.number[0] = current_player.recharge, and put that number in the text. Halo 3's campaign camouflage is also equipment: give_equipment(active_camo) gives ten seconds of it on Use equipment.
Equipment, guns and vehicles by name
place_at_me takes these names, besides weapons, bodies and tag paths:
| Kind | Names | Maps |
|---|---|---|
| Equipment as thrown: it works at once | bubble_shield, deployable_cover, radar_jammer, power_drainer, regenerator, trip_mine, grav_lift, grav_lift_permanent, flare, auto_turret | Every stock multiplayer map |
| Equipment to pick up | bubble_shield_pickup, deployable_cover_pickup, radar_jammer_pickup, power_drainer_pickup, regenerator_pickup, trip_mine_pickup, grav_lift_pickup, flare_pickup, auto_turret_pickup, active_camo_pickup, invincibility_pickup | Every stock multiplayer map |
| Mounted guns, to man | machine_gun_emplacement, plasma_cannon_emplacement, missile_pod_emplacement | Machine gun: every stock multiplayer map. Plasma cannon: all but one. Missile pod: where the map has one. |
| Vehicles | mongoose, ghost, warthog, gauss_warthog, troop_warthog, chopper, prowler, banshee, hornet, scorpion, wraith, shade, elephant | Where the map has them |
alias deployed = player.object[0]
alias emplacement = player.object[1]
on button press: do
-- Cover a short way in front of the player, facing where they face.
current_player.deployed = current_player.biped.place_at_me(deployable_cover, "cover", none, 15, 0, 2, none)
-- A machine gun emplacement anyone can man; a new one replaces the last.
current_player.emplacement.delete()
current_player.emplacement = current_player.biped.place_at_me(machine_gun_emplacement, "emplacement", none, 20, 0, 2, none)
end
- Offsets are in tenths of a Forge unit, along the body's heading, as for any created object. Only bodies take a model variant: the last value is
none. - Deployed equipment is the player's. Made at a player's body, it counts as theirs and their team's, as if they had thrown it. It runs out as Halo 3's own does and disappears, and your reference to it becomes
no_object. - Mounted guns, vehicles and pickups stay until something destroys them, the script deletes them or the round ends.
- A name the map lacks stops the script. Use the names every stock multiplayer map has, or check the maps you'll play.
machine_gun_emplacementandplasma_cannon_emplacementare the guns to man, not themachine_gun_turretandplasma_cannonweapons, which are the guns carried after tearing them off.grav_lift_permanentis the Grav Lift Forge places, which never runs out.auto_turretis the Automated Turret, equipment Halo 3's multiplayer maps carry but its multiplayer never used. It appears and stands where you put it, as Halo 3 left it: try it in your mode before you rely on it.- Declared objects take the same names:
{ kind = "stock", object = "warthog" }. See declared objects.
Give equipment
if current_player.class == Class.engineer then current_player.give_equipment(bubble_shield) end
The player's body carries the equipment in place of anything it carried, and they use it with Use equipment, which the script hears as button.equipment. The names are bubble_shield, deployable_cover, radar_jammer, power_drainer, regenerator, trip_mine, grav_lift, flare, auto_turret, active_camo (ten seconds of invisibility) and invincibility (ten seconds without damage). give_equipment(none) takes it away. Only living players receive it: give it again on each new life, for example when current_player.biped changes.
Ammunition, repairs and object kinds
refill_ammo() leaves energy weapons as they are, and grenades: use a grenade_regeneration trait or a class's grenades. An ammunition point refills the players beside an object every few seconds, behind a timer rather than on every tick. The Class Abilities example does it for each Medic's regenerator:
-- Regenerators refill the ammunition of everyone beside them.
if ammo_pulse.is_zero() then
for each player do
station = current_player.deployed
if current_player.class == Class.medic and station != no_object then
for each player do
if current_player.is_not_respawning() then
distance = current_player.biped.get_distance_to(station)
if distance <= 25 then current_player.refill_ammo() end
end
end
end
end
ammo_pulse.reset()
ammo_pulse.set_rate(-100%)
end
Repairs work the same way: while an Engineer holds Ability 3, the example raises the health of the vehicles within reach a little at a time, twice a second:
if current_player.class == Class.engineer and current_player.is_not_respawning() and current_player.is_button_held(button.ability_3) and current_player.repair_pulse.is_zero() then
current_player.repair_pulse = 1
current_player.repair_pulse.set_rate(-200%)
for each object do
if current_object.is_of_type(vehicle) then
distance = current_object.get_distance_to(current_player.biped)
health = current_object.health
if distance <= 30 and health > 0 and health < 100 then
health += 5
if health > 100 then health = 100 end
current_object.health = health
end
end
end
end
Spawn where the player chose
Mark the spots on your map with Forge's labels, then let players choose with a key or a script menu, and hand the object to set_primary_respawn_object:
on widget click: do
if clicked_widget == 10 then
for each object with label "command_point" do
if current_object.spawn_sequence == 1 then
current_player.set_primary_respawn_object(current_object)
end
end
end
end
Cooldowns, limits and cleanup
- Cooldowns: a player timer per ability, started with
set_rate(-100%)when the ability is used and checked withis_zero(). Timers survive death, so a recharge carries on into the next life. - One at a time: keep the object in a player variable and
delete()the old one before making a new one. Deletingno_objectdoes nothing. - How many: count with
for each object with label "cover" dobefore making another. - Where:
get_distance_tofrom an objective, a spawn or an enemy's body lets you refuse a spot. Objects are placed from the body, not where the player aims: keep offsets short so they stay on the same floor. - Lifetime: deployed equipment ends by itself. For anything else, start a timer when you create it and delete it when the timer runs out.
never_garbage_collectkeeps an object Halo 3 would otherwise clean up. - Leaving: objects a player made stay after they leave; the round's end removes everything the script created. A script can have at most 2,048 created objects at once.
- Per-player state, such as cooldowns, deployed objects and the chosen class, belongs in
player.number,player.timerandplayer.objectvariables. They follow the player through deaths and are cleared when they leave.
Class Abilities example
megalo-class-abilities.rmeg is a team Slayer mode with three classes, one 15-minute round to 50 points. To choose spawn points, label objects spawn_point in Forge and save the map; without them, everyone spawns where Halo 3 puts them.
- Ability 4 chooses your class for your next life. You start as an Infiltrator.
- Infiltrator: Ability 1 turns you invisible for 8 seconds, ready again 20 seconds after.
- Engineer: spawns with a Bubble Shield. Ability 1 deploys cover (30 seconds to recharge), Ability 2 a machine gun emplacement (60 seconds; a new one replaces the last), and holding Ability 3 beside a damaged vehicle repairs it.
- Medic: Ability 1 deploys a regenerator (45 seconds), which also refills the ammunition of everyone beside it every 5 seconds.
- While you wait to respawn, Ability 1 chooses the next object labeled
spawn_pointon the map, then Halo 3's own spawns again.
Placed widgets on the right, above Halo 3's score, show your class and each ability's recharge; while you wait, a line in the middle shows where you'll spawn.
What abilities can't do
- Abilities are what the script makes of buttons, objects, traits and timers. There are no new animations, models or HUD icons.
- A script can't stop Halo 3's own buttons from acting, only hear them.
- Objects are placed from the player's body and heading, not where they aim. Short offsets work best. To put one where they aim, read the point with
get_crosshair_x(),_y()and_z()and move the object there withset_position;game.raycasttests the ground between two points first. - Vehicles appear only on maps that have them, unless you name a tag the map loads; equipment and the machine gun emplacement on every stock multiplayer map.
