Skip to content

Metroid Prime SWEP is a passion project recreation of the original Metroid Prime character controller for Garry's Mod.

Notifications You must be signed in to change notification settings

JWalkerMailly/MetroidPrimeSWEP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Metroid Prime SWEP

Steam Downloads Steam Favorites Steam File Size
Metroid Prime SWEP is a passion project recreation of the original Metroid Prime character controller for Garry's Mod with utmost fidelity in mind. The project also ships with a comprehensive API and a multitude of hooks for developers to integrate their own add-ons.

Workshop Link


Features

  • Save States
  • Power Beam, Wave Beam, Ice Beam and Plasma Beam
  • Charge Beam
  • Missiles
  • Super Missiles, Wavebuster, Ice Spreader and Flamethrower
  • Combat Visor, Scan Visor, Thermal Visor and X-Ray Visor
  • Lock On System
  • Log Book System
  • Space Jump, Dashing and Air Movement
  • Grapple Beam
  • Power Suit, Varia Suit, Gravity Suit and Phazon Suit damage reduction
  • Morph Ball, Boost Ball, Spider Ball
  • Bombs and Power Bombs
  • And more...

Controls

Key Default Action
IN_ATTACK Mouse 1 Fire Beam, Charge Beam, Bombs (Morph Ball)
IN_ATTACK2 Mouse 2 Fire Missile, Missile Combo, Power Bombs (Morph Ball)
IN_SPEED Shift Lock On, Scan, Grapple Beam, Spider Ball (Morph Ball)
IN_JUMP Space Bar Space Jump, Dash (Lock On), Boost Ball (Morph Ball)
KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_DOWN Arrow Keys Switch Beam
KEY_E + KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_DOWN E + Arrow Keys Switch Visor
IN_CROUCH Left Control Key Morph Ball / Unmorph

Options & Cheats

An options menu is available in Sandbox mode from the Spawn Menu. It will be found in the extended portion of the menu in a category labelled "Metroid Prime". The options menu allows users and developers to tweak the display options of their session and enable / disable upgrades as they wish, granted sv_cheats is turned on.


Game Commands

The following commands are all accessible from the options menu:

Command Values Description
mp_cheats_autosave 0 / 1 Enables or disables autosave upon dying or removing the Power Suit.
mp_cheats_damagetakenscale 1 - 10 Multiplies damage taken while using the Power Suit.
mp_cheats_damagegivenscale 1 - 10 Multiplies damage dealt while using the Power Suit.
mp_cheats_scandashing 0 / 1 Enables or disables Scan Dashing feature found in first release of Metroid Prime.
Control Commands

Warning: Changing controls may have consequences and cause conflicts with other addons. Change at your own risk. Controls use the KEY enums, see the following link for a list of possible values: https://wiki.facepunch.com/gmod/Enums/KEY.

ConVar Values Description
mp_controls_selectorlayer 0 - 159 Defines the visor layer key to use when changing visors.
mp_controls_selector1 0 - 159 Defines the key to use to swap to Beam/Visor 1.
mp_controls_selector2 0 - 159 Defines the key to use to swap to Beam/Visor 2.
mp_controls_selector3 0 - 159 Defines the key to use to swap to Beam/Visor 3.
mp_controls_selector4 0 - 159 Defines the key to use to swap to Beam/Visor 4.
Gesture Commands

The following commands are all accessible from the options menu. Gestures can be used to change Beam/Visor using mouse movements instead of keyboard inputs.

ConVar Values Description
mp_options_gestures 0 / 1 Enables or disables gesture feature.
mp_controls_gesture 0 - 159 Defines the key to hold down to initiate a gesture.
mp_options_gesturedzone 0.1 - 1.0 Defines the mouse movement dead zone for gestures. Default value of 0.125.
mp_options_gesturealpha 0.1 - 1.0 Defines the mouse sensitivity for gestures. Default value of 0.125.
mp_options_gesturehelp 0 / 1 Show gesture calibration on screen.
Display Commands

The following commands are all accessible from the options menu:

Command Values Description
mp_options_autoaim 0 / 1 Enables or disables auto-aim.
mp_options_viewmodelfov 54 - 76 Changes viewmodel FOV.
mp_options_widescreenfix 0 / 1 Stretches HUD to fill widescreen displays.
mp_options_visoropacity 0 - 100 Opacity of heads-up-display.
mp_options_helmetopacity 0 - 100 Opacity of Samus' helmet.
mp_options_hudlag 0 / 1 Enables or disables HUD lag.
mp_options_facereflection 0 / 1 Enables or disables Samus' face reflection on Combat Visor.
mp_options_keephud 0 / 1 Enables or disables HUD display even when the Power Suit is not in use. Must be in inventory.
Cheat Commands

The following commands are all accessible from the options menu:

Command Args Args Description
mp_cheats_savestate - - Save current session.
mp_cheats_deletestate - - Delete current session.
mp_cheats_set_missileamount 0 - 255 - Set current missile ammo count.
mp_cheats_set_missilecapacity 0 - 255 - Set missile max ammo count.
mp_cheats_enable_powerbeam 0 / 1 - Enables or disables Power Beam.
mp_cheats_enable_wavebeam 0 / 1 - Enables or disables Wave Beam.
mp_cheats_enable_icebeam 0 / 1 - Enables or disables Ice Beam.
mp_cheats_enable_plasmabeam 0 / 1 - Enables or disables Plasma Beam
mp_cheats_enable_chargebeam 0 / 1 - Enables or disables Charge Beam.
mp_cheats_enable_supermissile 0 / 1 - Enables or disables Super Missile Combo.
mp_cheats_enable_wavebuster 0 / 1 - Enables or disables Wavebuster Combo.
mp_cheats_enable_icespreader 0 / 1 - Enables or disables Ice Spreader Combo.
mp_cheats_enable_flamethrower 0 / 1 - Enables or disables Flamethrower Combo.
mp_cheats_enable_spacejump 0 / 1 - Enables or disables Space Jump.
mp_cheats_enable_grapplebeam 0 / 1 - Enables or disables Grapple Beam.
mp_cheats_enable_powersuit 0 / 1 - Enables or disables Power Suit.
mp_cheats_enable_variasuit 0 / 1 - Enables or disables Varia Suit.
mp_cheats_enable_gravitysuit 0 / 1 - Enables or disables Gravity Suit.
mp_cheats_enable_phazonsuit 0 / 1 - Enables or disables Phazon Suit.
mp_cheats_set_energytankamount 0 - 14 - Sets base filled energy tank amount. Although this command exists, you probably shouldn't use it.
mp_cheats_set_energytankcapacity 0 - 14 0 / 1 First argument sets max energy tank capacity. Second argument to refill health or not.
mp_cheats_enable_combatvisor 0 / 1 - Enables or disables Combat Visor.
mp_cheats_enable_scanvisor 0 / 1 - Enables or disables Scan Visor.
mp_cheats_enable_thermalvisor 0 / 1 - Enables or disables Thermal Visor.
mp_cheats_enable_xrayvisor 0 / 1 - Enables or disables X-Ray Visor.
mp_cheats_enable_morphball 0 / 1 - Enables or disables Morph Ball.
mp_cheats_enable_morphballbombs 0 / 1 - Enables or disables Morph Ball Bombs.
mp_cheats_enable_morphballboost 0 / 1 - Enables or disables Boost Ball.
mp_cheats_enable_morphballspider 0 / 1 - Enables or disables Spider Ball.
mp_cheats_set_powerbombamount 0 - 8 - Sets current Power Bomb count.
mp_cheats_set_powerbombcapacity 0 - 8 - Sets Power Bomb max ammo.

Addon Integration

The supplied API offers methods for other addons to integrate with this project. Here you will find a guide on all available features and endpoints.


Damage Types

Weapons use a combination of custom damage types:

DMG Type Value Weapons
DMG_MP_NULL 0 Unused
DMG_MP_POWER 1 Power Beam, Super Missile
DMG_MP_WAVE 2 Wave Beam, Wavebuster
DMG_MP_ICE 4 Ice Beam, Ice Spreader
DMG_MP_PLASMA 8 Plasma Beam, Flamethrower
DMG_MP_BOMB 16 Bombs, Power Bombs
DMG_MP_SPECIAL 32 Missile, Super Missile, Wavebuster, Ice Spreader, Flamethrower, Power Bombs

To check for a specific damage type, use: https://wiki.facepunch.com/gmod/CTakeDamageInfo:GetDamageCustom

Adding Threat Indicator Support

To add entities to the threat indication system, use the following stub in an autorun script:

game.MetroidPrimeThreats.Add("entity_class_name")
Adding Log Book Support

There are two ways to add Log Book support to your entities. The first method declares the Log Book data directly in your shared.lua file. The second approach makes use of an autorun script to register your entity into the game. If you are the author of the entity you wish to add support for, the first approach is recommended. If you are not the author, your only option will be the second method.

Method 1
In your shared.lua file, declare the following:

ENT.LogBook = {
	Description = "",
	Left = Material(""), // or nil
	Right = Material("") // or nil
}

Values:

Var Description
Description Text to be displayed on the Scan Visor upon scan completion.
Left Material to be displayed on the left side of the Scan Visor upon scan completion.
Right Material to be displayed on the right side of the Scan Visor upon scan completion.

Additional Values:

Var Description
ScanDuration Time required to scan entity. (Default of 1.33)

Method 2
In your autorun script, add the following stub and change the values to your needs:

game.MetroidPrimeLogBook.Add("entity_class_name", {
	Description = "",
	Left = Material(""), // or nil
	Right = Material("") // or nil
})

VTF/VMT Templates
You can use the following templates for creating your scan images. You can resize the frame however you want as long as your final VTF dimensions are 256 x 512.

Here is what your VMT should look like:

"UnlitGeneric"
{
	"$basetexture" "your/texture/path/here"
	"$additive"    "1"
	"$vertexalpha" "1"
	"$vertexcolor" "1"
}
Adding Grapple Beam Anchors

To add grapple beam anchors, use the following stub in an autorun script:

game.MetroidPrimeAnchors.Add("entity_class_name")
Adding Spider Ball Surfaces

The Spider Ball uses surface properties to determine if it can ride along surfaces. To learn more about surface properties, see the following link: https://developer.valvesoftware.com/wiki/Material_surface_properties

By default, the Spider Ball will ride along any metallic surface. To add new surfaces, use the following stub in an autorun script:

game.MetroidPrimeSpiderSurfaces.Add("surface_prop_name")
Adding Lock-On Support

By default, the weapon will use the world space center of an entity to lock on. The API offers a way to define a lock-on attachment. The first method declares the attachment in your Initialize hook. The second approach makes use of an autorun script to register your attachment into the game. If you are the author of the entity you wish to add support for, the first approach is recommended. If you are not the author, your only option will be the second method. Attachments are dynamic, you can change the attachment at any time in your logic as long as it is called server-side. See API section for all available functions in the Entity section.

Method 1
In your Initialize hook:

function ENT:Initialize()

	-- Code.

	if (self.SetLockOnAttachment) then self:SetLockOnAttachment("your_attachment_name") end
end

Method 2
In your autorun script, add the following stub and change the values to your needs:

game.MetroidPrimeLockOn.Add("entity_class_name", "your_attachment_name")

Architecture Overview

There are a lot of moving pieces and a lot of different states to this weapon. The project employs a number of design patterns to aid in its maintainability and debugging. At the core of the system lies four state machine classes responsible for keeping track of all timings and states. The state machines act as the data access layer for all networked properties of the weapon.


Weapon Layer (mp_weapon_powersuit)

This is the default SWEP implementation. This is where all files are loaded. This layer only contains functions relevant to the GLua API and calls to the event layer.

  • setup.lua : Loads all files and configurations.
  • shared.lua : Standard implementation, exposes Primary Attack, Secondary Attack and Think logic.
  • init.lua : Standard implementation, tells the game how the weapon should behave when dropped or equipped.
  • cl_init.lua: Standard implementation, calls to the rendering stack to display the HUD and how the view should behave.

Events Layer (Logic)

The events layer is divided into four sections:

This layer contains most of the logic for the Power Suit, everything from firing projectiles, movement, target acquisition, etc. This layer communicates with the state machines to update timings and states.

State Machine Layer (Data)

State machines are created inside InstallDataTables and are responsible for installing all necessary network variables onto a Power Suit instance. There are four state machines in total:

This is the data access layer. This is where events and hooks tap into the timings and states of the weapon. State machines act as classes and are exposed to every part of the code in order to maintain separation of concerns. Although you can interact with state machines directly, you should avoid doing so unless you know what you are doing. To access the state machines on a Power Suit instance, refer to the following code:

local weapon = ply:GetPowerSuit();  // Get Power Suit instance using API.

local armcannon = weapon.ArmCannon; // Arm Cannon state machine instance.
local helmet    = weapon.Helmet;    // Helmet state machine instance.
local morphball = weapon.MorphBall; // Morph Ball state machine instance.
local powersuit = weapon.PowerSuit; // Power Suit state machine instance.

Hooks

List of all available hooks.


State Events
MP.OnSaveState(powersuit)
Description

Called when a Power Suit has saved its state to disk.

Arguments

1. Entity powersuit Power Suit weapon reference.

Example
hook.Add("MP.OnSaveState", "DEBUG.OnSaveState", function(powersuit)
	print("MP.OnSaveState", powersuit);
end);

Visor Events
MP.OnVisorChanged(powersuit, previousVisor, nextVisor)
Description

Called when changing visors.

Arguments

1. Entity powersuit Power Suit weapon reference.

2. Number previousVisor Previous visor index.

3. Number nextVisor New visor index.

Example
hook.Add("MP.OnVisorChanged", "DEBUG.OnVisorChanged", function(powersuit, previousVisor, nextVisor)
	print("MP.OnVisorChanged", powersuit, previousVisor, nextVisor);
end);

MP.OnTargetChanged(powersuit, target)
Description

Called when visor target has changed.

Arguments

1. Entity powersuit Power Suit weapon reference.

2. Entity target New target.

Example
hook.Add("MP.OnTargetChanged", "DEBUG.OnTargetChanged", function(powersuit, target)
	print("MP.OnTargetChanged", powersuit, target);
end);

MP.OnScanCompleted(powersuit, target)
Description

Called when the Scan Visor has finished scanning.

Arguments

1. Entity powersuit Power Suit weapon reference.

2. Entity target Scanned target entity.

Example
hook.Add("MP.OnScanCompleted", "DEBUG.OnScanCompleted", function(powersuit, target)
	print("MP.OnScanCompleted", powersuit, target);
end);

Beam Events
MP.OnBeamChanged(powersuit, previousBeam, nextBeam)
Description

Called when changing beams.

Arguments

1. Entity powersuit Power Suit weapon reference.

2. Number previousBeam Previous beam index.

3. Number nextBeam New beam index.

Example
hook.Add("MP.OnBeamChanged", "DEBUG.OnBeamChanged", function(powersuit, previousBeam, nextBeam)
	print("MP.OnBeamChanged", powersuit, previousBeam, nextBeam);
end);

MP.ChargeBeamThink(powersuit)
Description

Called on every frame/tick the charge beam is active.

Arguments

1. Entity powersuit Power Suit weapon reference.

Example
hook.Add("MP.ChargeBeamThink", "DEBUG.ChargeBeamThink", function(powersuit)
	print("MP.ChargeBeamThink", powersuit);
end);

Morph Ball Events
MP.OnMorphBall(ply, powersuit, morphball)
Description

Called upon transitioning into Morph Ball mode.

Arguments

1. Entity ply Player that morphed.

2. Entity powersuit Power Suit weapon reference.

3. Entity morphball Morph Ball entity reference.

Example
hook.Add("MP.OnMorphBall", "DEBUG.OnMorphBall", function(ply, powersuit, morphball)
	print("MP.OnMorphBall", ply, powersuit, morphball);
end);

MP.OnMorphBallUnmorph(ply, powersuit)
Description

Called upon exiting Morph Ball mode.

Arguments

1. Entity ply Player that unmorphed.

2. Entity powersuit Power Suit weapon reference.

Example
hook.Add("MP.OnMorphBallUnmorph", "DEBUG.OnMorphBallUnmorph", function(ply, powersuit)
	print("MP.OnMorphBallUnmorph", ply, powersuit);
end);

MP.OnMorphBallBoost(morphball)
Description

Called when Boost Ball fires.

Arguments

1. Entity morphball Morph Ball entity that boosted.

Example
hook.Add("MP.OnMorphBallBoost", "DEBUG.OnMorphBallBoost", function(morphball)
	print("MP.OnMorphBallBoost", morphball);
end);

MP.MorphBallSpiderThink(morphball, surfaceParent, parentPhys, parentVelocity)
Description

Called every tick the Spider Ball is active.

Arguments

1. Entity morphball Morph Ball entity reference.

2. Entity surfaceParent Surface entity on which Morph Ball is riding.

3. PhysObj parentPhys Physics Object of surface parent.

4. Vector parentVelocity Velocity of parent at Morph Ball position in world coordinates.

Example
hook.Add("MP.MorphBallSpiderThink", "DEBUG.MorphBallSpiderThink", function(morphball, surfaceParent, parentPhys, parentVelocity)
	print("MP.MorphBallSpiderThink", morphball, surfaceParent, parentPhys, parentVelocity);
end);

Movement Events
MP.OnDash(ply, powersuit)
Description

Called upon dashing.

Arguments

1. Entity ply Player that dashed.

2. Entity powersuit Power Suit weapon reference.

Example
hook.Add("MP.OnDash", "DEBUG.OnDash", function(ply, powersuit)
	print("MP.OnDash", ply, powersuit);
end);

Boolean MP.GrappleBeamThink(ply, powersuit, anchor)
Description

Called every tick the Grapple Beam is active.

Arguments

1. Entity ply Player grappling.

2. Entity powersuit Power Suit weapon reference.

3. Entity anchor Entity onto which Grapple Beam is anchored.

Returns

1. Boolean Return true to override default grapple behavior.

Example

The following example will prevent the player from swinging and print the anchor to console.

hook.Add("MP.GrappleBeamThink", "DEBUG.GrappleBeamThink", function(ply, powersuit, anchor)
	print("MP.GrappleBeamThink", ply, powersuit, anchor);
	return true;
end);

Draw Hooks
MP.PreDrawPowerSuitHUD(weapon, damage)
Description

Called before the Power Suit HUD, Visor and components have finished drawing. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Number damage Damage variable, used for animating HUD elements upon damage.

Example
hook.Add("MP.PreDrawPowerSuitHUD", "DEBUG.PreDrawPowerSuitHUD", function(weapon, damage)
	print("MP.PreDrawPowerSuitHUD", weapon, damage);
end);

MP.PostDrawPowerSuitHUD(weapon, damage)
Description

Called after the Power Suit HUD, Visor and components have finished drawing. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Number damage Damage variable, used for animating HUD elements upon damage.

Example
hook.Add("MP.PostDrawPowerSuitHUD", "DEBUG.PostDrawPowerSuitHUD", function(weapon, damage)
	print("MP.PostDrawPowerSuitHUD", weapon, damage);
end);

Boolean MP.PreDrawBeamMenu(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
Description

Called before drawing the Beam Menu component to the screen. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Vector pos Position used for 3D rendering of Beam Menu.

3. Angle angle Angle used for 3D rendering of Beam Menu.

4. Vector up Up vector of angle.

5. Vector right Right vector of angle.

6. Vector forward Forward vector of angle.

7. Number fovCompensation FOV compensation ratio used in 3D rendering of Beam Menu.

8. Number blend Current blend of render calls. Used for transparency of 3D Beam Menu.

9. Boolean widescreen Whether or not to stretch rendering of 3D Beam Menu for wide screens.

Returns

1. Boolean Return True to prevent drawing the default Beam Menu.

Example

The following example will prevent rendering of the Beam Menu and print all arguments to console.

hook.Add("MP.PreDrawBeamMenu", "DEBUG.PreDrawBeamMenu", function(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
	print("MP.PreDrawBeamMenu", weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen);
	return true;
end);

MP.PostDrawBeamMenu(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
Description

Called after drawing the Beam Menu component to the screen. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Vector pos Position used for 3D rendering of Beam Menu.

3. Angle angle Angle used for 3D rendering of Beam Menu.

4. Vector up Up vector of angle.

5. Vector right Right vector of angle.

6. Vector forward Forward vector of angle.

7. Number fovCompensation FOV compensation ratio used in 3D rendering of Beam Menu.

8. Number blend Current blend of render calls. Used for transparency of 3D Beam Menu.

9. Boolean widescreen Whether or not to stretch rendering of 3D Beam Menu for wide screens.

Example
hook.Add("MP.PostDrawBeamMenu", "DEBUG.PostDrawBeamMenu", function(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
	print("MP.PostDrawBeamMenu", weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen);
end);

Boolean MP.PreDrawVisorMenu(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
Description

Called before drawing the Visor Menu component to the screen. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Vector pos Position used for 3D rendering of Visor Menu.

3. Angle angle Angle used for 3D rendering of Visor Menu.

4. Vector up Up vector of angle.

5. Vector right Right vector of angle.

6. Vector forward Forward vector of angle.

7. Number fovCompensation FOV compensation ratio used in 3D rendering of Visor Menu.

8. Number blend Current blend of render calls. Used for transparency of 3D Visor Menu.

9. Boolean widescreen Whether or not to stretch rendering of 3D Visor Menu for wide screens.

Returns

1. Boolean Return True to prevent drawing the default Visor Menu.

Example

The following example will prevent rendering of the Visor Menu and print all arguments to console.

hook.Add("MP.PreDrawVisorMenu", "DEBUG.PreDrawVisorMenu", function(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
	print("MP.PreDrawVisorMenu", weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen);
	return true;
end);

MP.PostDrawVisorMenu(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
Description

Called after drawing the Visor Menu component to the screen. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Vector pos Position used for 3D rendering of Visor Menu.

3. Angle angle Angle used for 3D rendering of Visor Menu.

4. Vector up Up vector of angle.

5. Vector right Right vector of angle.

6. Vector forward Forward vector of angle.

7. Number fovCompensation FOV compensation ratio used in 3D rendering of Visor Menu.

8. Number blend Current blend of render calls. Used for transparency of 3D Visor Menu.

9. Boolean widescreen Whether or not to stretch rendering of 3D Visor Menu for wide screens.

Example
hook.Add("MP.PostDrawVisorMenu", "DEBUG.PostDrawVisorMenu", function(weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen)
	print("MP.PostDrawVisorMenu", weapon, pos, angle, up, right, forward, fovCompensation, blend, widescreen);
end);

Boolean MP.PreDrawMorphBallHUD(weapon)
Description

Called before the Morph Ball HUD has finished drawing. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

Returns

1. Boolean Return true to prevent drawing the Morph Ball HUD.

Example

The following example will prevent drawing the default Morph Ball HUD.

hook.Add("MP.PreDrawMorphBallHUD", "DEBUG.PreDrawMorphBallHUD", function(weapon)
	print("MP.PreDrawMorphBallHUD", weapon);
	return true;
end);

MP.PostDrawMorphBallHUD(weapon)
Description

Called after the Morph Ball HUD has finished drawing. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

Example
hook.Add("MP.PostDrawMorphBallHUD", "DEBUG.PostDrawMorphBallHUD", function(weapon)
	print("MP.PostDrawMorphBallHUD", weapon);
end);

Boolean MP.PreDrawCombatVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

Called before the Combat Visor has finished drawing. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Table beam Current beam config table.

3. Table visor Current visor config table.

4. Vector hudPos Position used to render 3D Combat Visor UI.

5. Angle hudAngle Angle used to render 3D Combat Visor UI.

6. Vector guiPos Position used to render the static elements of the 3D Combat Visor.

7. Color guiColor Color used to render the static elements of the 3D Combat Visor.

8. Number fovRatio FOV ratio used for positioning of 3D elements.

9. Number transition Transition interpolator. This is used to fade visors into each other upon switching.

10. Number transitionStart Transition start, indicates if fading in or out.

11. Boolean widescreen Boolean used to stretch 3D elements for wide screens.

12. Number visorOpacity Visor opacity, set by the command mp_options_visoropacity.

Returns

1. Boolean Return true to prevent drawing the Combat Visor.

Example

The following example will prevent drawing the default Combat Visor.

hook.Add("MP.PreDrawCombatVisor", "DEBUG.PreDrawCombatVisor", function(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
	return true;
end);

MP.PostDrawCombatVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

Called after the Combat Visor has finished drawing. This hook is called inside a 2D rendering context.

Arguments

1. Entity weapon Power Suit weapon reference.

2. Table beam Current beam config table.

3. Table visor Current visor config table.

4. Vector hudPos Position used to render 3D Combat Visor UI.

5. Angle hudAngle Angle used to render 3D Combat Visor UI.

6. Vector guiPos Position used to render the static elements of the 3D Combat Visor.

7. Color guiColor Color used to render the static elements of the 3D Combat Visor.

8. Number fovRatio FOV ratio used for positioning of 3D elements.

9. Number transition Transition interpolator. This is used to fade visors into each other upon switching.

10. Number transitionStart Transition start, indicates if fading in or out.

11. Boolean widescreen Boolean used to stretch 3D elements for wide screens.

12. Number visorOpacity Visor opacity, set by the command mp_options_visoropacity.

Example
hook.Add("MP.PostDrawCombatVisor", "DEBUG.PostDrawCombatVisor", function(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
	print("MP.PostDrawCombatVisor", weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity);
end);

Boolean MP.PreDrawScanVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

This hook is identical to MP.PreDrawCombatVisor.


MP.PostDrawScanVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

This hook is identical to MP.PostDrawCombatVisor.


Boolean MP.PreDrawThermalVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

This hook is identical to MP.PreDrawCombatVisor.


MP.PostDrawThermalVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

This hook is identical to MP.PostDrawCombatVisor.


Boolean MP.PreDrawXRayVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

This hook is identical to MP.PreDrawCombatVisor.


MP.PostDrawXRayVisor(weapon, beam, visor, hudPos, hudAngle, guiPos, guiColor, fovRatio, transition, transitionStart, widescreen, visorOpacity)
Description

This hook is identical to MP.PostDrawCombatVisor.



API

List of all accessible API endpoints to facilitate addon integrations. To view the raw API, click here.


Utility
Entity _player:GetPowerSuit()
Description

Get Power Suit instance of a player.

This function can return nil if the StateIdentifier variable is not set on the instance. StateIdentifier is a special variable used to indicate that the state successfully loaded.
Returns

1. Entity Weapon or nil if not in player's inventory.


Boolean, Entity _player:UsingPowerSuit(ignoreState)
Description

Determines if a player is currently using the Power Suit.

This function can return false,nil if the StateIdentifier variable is not set on the instance. StateIdentifier is a special variable used to indicate that the state successfully loaded.
Arguments

1. Boolean ignoreState Ignores checking for StateIdentifier. Not recommended unless you know what you are doing.

Returns

1. Boolean True if active weapon is Power Suit, False otherwise.

2. Entity Weapon instance if True, nil if False.


Boolean, Entity _player:UsingMorphBall()
Description

Determines if a player is currently using the Morph Ball.

Returns

1. Boolean True if using Morph Ball, False otherwise.

2. Entity Morph Ball entity if True, False otherwise.


Entity
Boolean _entity:IsMorphBall()
Description

Checks if the entity is a Morph Ball.

Returns

1. Boolean True if entity is a Morph Ball and valid, False otherwise.


Boolean _entity:IsGrappleAnchor()
Description

Checks if the entity is a Grapple Anchor.

Returns

1. Boolean True if entity is a registered anchor, False otherwise.


_entity:SetIgnitable(ignitable)
Description

Make entity ignitable when damaged by Plasma Beam.

Arguments

1. Boolean ignitable True if ignitable, False otherwise.


Boolean _entity:IsIgnitable()
Description

Determines if entity can be ignited when damaged by Plasma Beam.

Returns

1. Boolean True if ignitable, False otherwise.


Boolean _entity:CanBeScanned()
Description

Determines if entity can be scanned using the Scan Visor.

Returns

1. Boolean True if scannable, False otherwise.


String, Material, Material, Number _entity:GetLogBookData()
Description

Get Log Book data from an entity.

This function returns nil if no Log Book data was found.
Returns

1. String Description or nil.

2. Material Left image or nil.

3. Material Right image or nil.

4. Number Scan duration or nil.


Boolean _entity:SetXRayHot(hot)
Description

Marks an entity as hot on the X-Ray Visor. Hot entities appear solid white.

Arguments

1. Boolean hot True if hot, False if normal.

Returns

1. Boolean Hot. False on failure.


Boolean _entity:SetXRayCold(cold)
Description

Marks an entity as cold on the X-Ray Visor. Cold entities are invisible.

Arguments

1. Boolean cold True if cold, False if normal.

Returns

1. Boolean Cold. False on failure.


Boolean _entity:IsXRayHot()
Description

Determines if an entity is marked as hot on the X-Ray Visor.

Returns

1. Boolean True if hot, False otherwise.


Boolean _entity:IsXRayCold()
Description

Determines if an entity is marked as cold on the X-Ray Visor.

Returns

1. Boolean True if cold, False otherwise.


Boolean _entity:SetThermalHot(hot)
Description

Marks an entity as hot on the Thermal Visor. Hot entities appear red.

Arguments

1. Boolean hot True if hot, False if normal.

Returns

1. Boolean Hot. False on failure.


Boolean _entity:SetThermalCold(cold)
Description

Marks an entity as cold on the Thermal Visor. Cold entities are invisible.

Arguments

1. Boolean cold True if cold, False if normal.

Returns

1. Boolean Cold. False on failure.


Boolean _entity:IsThermalHot()
Description

Determines if an entity is marked as hot on the Thermal Visor.

Returns

1. Boolean True if hot, False otherwise.


Boolean _entity:IsThermalCold()
Description

Determines if an entity is marked as cold on the Thermal Visor.

Returns

1. Boolean True if cold, False otherwise.


Boolean _entity:HasHeatSignature()
Description

Determines if an entity will appear on the Thermal Visor and is not cold.

Returns

1. Boolean True if has signature, False otherwise.


Boolean _entity:HasXRaySignature()
Description

Determines if an entity is marked as cold or hot on the X-Ray Visor.

Returns

1. Boolean True if has signature, False otherwise.


Vector _entity:GetLockOnPosition()
Description

Get the lock-on position of an entity.

Returns

1. Vector Lock-on position.


Number _entity:GetLockOnAttachment()
Description

Get the lock-on attachment ID.

This function returns 0 if the attachment does not exist and -1 if the model is invalid.
Returns

1. Number Lock-on attachment ID.


_entity:SetLockOnAttachment(name)
Description

Defines the entity's lock-on attachment.

Arguments

1. String name The name of the attachment to use for lock-on.


State
Boolean _player:SavePowerSuitState()
Description

Saves current Power Suit state to disk.

Returns

1. Boolean True if saved successfully, False otherwise.


Boolean _player:LoadPowerSuitState(json)
Description

Loads a state file to the player's Power Suit.

Although you can use this function, you probably shouldn't.
Arguments

1. String json String containing a valid JSON state for the Power Suit.

Returns

1. Boolean True if loaded successfully, False otherwise.


Boolean _player:DeletePowerSuitState(reload)
Description

Deletes current Power Suit state from disk.

Arguments

1. Boolean reload If True, will reset weapon now. If False, will reset weapon on next spawn. Warning: If 'Auto Save' is on and you are reloading weapon on next spawn, this function will basically do nothing.

Returns

1. Boolean True if deleted successfully, False otherwise.


Energy Tanks
Number _player:GetPowerSuitEnergyTanks()
Description

Determines the base amount of filled energy tanks the Power Suit starts with.

This function does not return the current health of the player. Although you can use this function, you probably shouldn't.
Returns

1. Number Base amount of filled energy tanks, or nil on failure.


Number _player:AddPowerSuitEnergyTanks(amount, norefill)
Description

Adds a set amount of base energy tanks.

Although you can use this function, you probably shouldn't.
Arguments

1. Number amount Amount of base energy tanks to add.

2. Boolean norefill False to refill health, True to prevent.

Returns

1. Number Base amount of filled energy tanks, or nil on failure.


Number _player:SetPowerSuitEnergyTanks(amount, norefill)
Description

Sets the amount of base energy tanks.

Although you can use this function, you probably shouldn't.
Arguments

1. Number amount Amount of base energy tanks.

2. Boolean norefill False to refill health, True to prevent.

Returns

1. Number Base amount of filled energy tanks, or nil on failure.


Number _player:GetPowerSuitMaxEnergyTanks()
Description

Determines the total energy tank capacity of a player.

Returns

1. Number Amount of energy tanks, or nil on failure.


Number _player:AddPowerSuitMaxEnergyTanks(amount, refill)
Description

Adds a set amount of energy tanks to the Power Suit.

Arguments

1. Number amount Amount of energy tanks to add.

2. Boolean refill True to refill health, False otherwise.

Returns

1. Number Total amount of energy tanks, nil on failure.


Number _player:SetPowerSuitMaxEnergyTanks(amount, refill)
Description

Sets the amount of energy tanks on the Power Suit.

Arguments

1. Number amount Amount of energy tanks to set.

2. Boolean refill True to refill health, False otherwise.

Returns

1. Number Total amount of energy tanks, nil on failure.


Visors
Boolean _player:IsPowerSuitVisorEnabled(index)
Description

Determines if some visor is enabled on the Power Suit.

Arguments

1. Number index Visor index to test. (Values are 1 to 4)

Returns

1. Boolean True if visor is enabled, False otherwise.


Boolean _player:EnablePowerSuitVisor(index, enable)
Description

Enables or disables a visor on the Power Suit.

Arguments

1. Number index Visor index to enable. (Values are 1 to 4)

2. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Beams
Boolean _player:IsPowerSuitBeamEnabled(index)
Description

Determines if some beam is enabled on the Power Suit.

Arguments

1. Number index Beam index to test. (Values are 1 to 4)

Returns

1. Boolean True if beam is enabled, False otherwise.


Boolean _player:EnablePowerSuitBeam(index, enable)
Description

Enables or disables a beam on the Power Suit.

Arguments

1. Number index Beam index to enable. (Values are 1 to 4)

2. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsPowerSuitChargeBeamEnabled()
Description

Determines if Charge Beam is enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnablePowerSuitChargeBeam(enable)
Description

Enables or disables Charge Beam on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsPowerSuitMissileComboEnabled(index)
Description

Determines if some missile combo is enabled on the Power Suit.

Arguments

1. Number index Beam index to test. (Values are 1 to 4)

Returns

1. Boolean True if combo is enabled, False otherwise.


Boolean _player:EnablePowerSuitMissileCombo(index, enable)
Description

Enables or disables a missile combo on the Power Suit.

Arguments

1. Number index Beam index to enable. (Values are 1 to 4)

2. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Ammo
Number _player:GetPowerSuitAmmo(type)
Description

Determines the current ammo count for a given type.

Currently only supports type "Missile".
Arguments

1. String type Ammo type to check.

Returns

1. Number Ammo count, nil on failure.


Number _player:AddPowerSuitAmmo(type, amount)
Description

Adds a set amount of ammo of a given type.

Currently only supports type "Missile".
Arguments

1. String type Ammo type to add.

2. Number amount Amount of ammo to add.

Returns

1. Number Ammo count, nil on failure.


Number _player:SetPowerSuitAmmo(type, amount)
Description

Sets amount of ammo of a given type.

Currently only supports type "Missile".
Arguments

1. String type Ammo type to set.

2. Number amount Amount to set.

Returns

1. Number Ammo count, nil on failure.


Number _player:GetPowerSuitMaxAmmo(type)
Description

Determines the max ammo capacity for a given type.

Currently only supports type "Missile".
Arguments

1. String type Ammo type to check.

Returns

1. Number Max ammo count, nil on failure.


Number _player:AddPowerSuitMaxAmmo(type, amount)
Description

Adds a set amount of ammo capacity for a given type.

Currently only supports type "Missile".
Arguments

1. String type Ammo type to add.

2. Number amount Capacity to add.

Returns

1. Number Capacity, nil on failure.


Number _player:SetPowerSuitMaxAmmo(type, amount)
Description

Sets ammo capacity of a given type.

Currently only supports type "Missile".
Arguments

1. String type Ammo type to set.

2. Number amount Capacity to set.

Returns

1. Number Capacity, nil on failure.


Suit Upgrades
Boolean _player:IsPowerSuitSpaceJumpEnabled()
Description

Determines if Space Jump is enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnablePowerSuitSpaceJump(enable)
Description

Enables or disables Space Jump on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsPowerSuitGrappleEnabled()
Description

Determines if Grapple Beam is enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnablePowerSuitGrapple(enable)
Description

Enables or disables Grapple Beam on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsPowerSuitSuitEnabled(suit)
Description

Determines if some suit is enabled on the Power Suit.

Arguments

1. Number suit Suit index to test. (Values are 1 to 4)

Returns

1. Boolean True if suit is enabled, False otherwise.


Boolean _player:EnablePowerSuitSuit(suit, enable)
Description

Enables or disables a suit on the Power Suit.

Arguments

1. Number suit Suit index to enable. (Values are 1 to 4)

2. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Morph Ball Upgrades
Boolean _player:IsMorphBallEnabled()
Description

Determines if Morph Ball feature is enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnableMorphBall(enable)
Description

Enables or disables Morph Ball feature on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsMorphBallBombsEnabled()
Description

Determines if Morph Ball Bombs are enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnableMorphBallBombs(enable)
Description

Enables or disables Morph Ball Bombs feature on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsMorphBallBoostEnabled()
Description

Determines if Boost Ball is enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnableMorphBallBoost(enable)
Description

Enables or disables Boost Ball feature on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Boolean _player:IsMorphBallSpiderEnabled()
Description

Determines if Spider Ball is enabled on the Power Suit.

Returns

1. Boolean True if enabled, False otherwise.


Boolean _player:EnableMorphBallSpider(enable)
Description

Enables or disables Spider Ball feature on the Power Suit.

Arguments

1. Boolean enable True to enable, False otherwise.

Returns

1. Boolean True on success, False otherwise.


Power Bombs
Number _player:GetPowerSuitPowerBombAmmo()
Description

Determines the current power bomb ammo count.

Returns

1. Number Power bomb ammo count, nil on failure.


Number _player:AddPowerSuitPowerBombAmmo(amount)
Description

Adds a set amount of power bomb ammo.

Arguments

1. Number amount Amount of power bomb ammo to add.

Returns

1. Number Power bomb ammo count, nil on failure.


Number _player:SetPowerSuitPowerBombAmmo(amount)
Description

Sets power bomb ammo count.

Arguments

1. Number amount Amount of power bomb ammo to set.

Returns

1. Number Power bomb ammo count, nil on failure.


Number _player:GetPowerSuitPowerBombMaxAmmo()
Description

Determines the current power bomb ammo capacity.

Returns

1. Number Power bomb ammo capacity, nil on failure.


Number _player:AddPowerSuitPowerBombMaxAmmo(amount)
Description

Adds a set amount of power bomb ammo capacity.

Arguments

1. Number amount Power bomb ammo capacity to add.

Returns

1. Number Power bomb ammo capacity, nil on failure.


Number _player:SetPowerSuitPowerBombMaxAmmo(amount)
Description

Sets power bomb ammo capacity.

Arguments

1. Number amount Power bomb ammo capacity to set.

Returns

1. Number Power bomb ammo capacity, nil on failure.



Credits

Team

WLKRE - Programming, Testing, Source Particle Effects

Contributors

TonyBoi - Multiplayer Beta Testing
Dopey - Beta Testing, Particle Effects Adviser
SLAUGH7ER - Optimization Adviser
Impulse - Porting Adviser

Copyright

Retro Studios - Original Assets
Nintendo - Copyright Owner

Special Thanks

Star1x
Chistogo
Shoax
Kieran Vax'ilian

Notice of Non-Affiliation and Disclaimer

Metroid Prime SWEP is a passion project recreation of the original Metroid Prime character controller for Garry's Mod. It is not affiliated, associated, authorized, endorsed by, or in any way officially connected to Nintendo, or any of its subsidiaries or its affiliates.

The names Metroid Prime as well as related names, marks, emblems and images are registered trademarks of their respective owners.

Analytics

Steam Views Steam Release Date Steam Update Date
Start: November 2022 End: October 2023 Hours: ~800 hours Lines: ~15,500 lines

About

Metroid Prime SWEP is a passion project recreation of the original Metroid Prime character controller for Garry's Mod.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages