API Globals - StyledStrike/gmod-glide GitHub Wiki

This page lists all constants and functions that are accessible from the Glide global table.

Constants

Shared Glide.MAX_SEATS

Returns the max. amount of seats that Vehicle:CreateSeat will allow.


Shared Glide.MAX_EXPLOSION_DISTANCE

When explosions happen, the network event will only be transmitted to clients that are nearby (closer than this constant). This does not apply to the attacker, who will always see explostions that they are responsible for.


Shared Glide.EXPLOSION_TYPE

Used on SERVERGlide.CreateExplosion and CLIENTGlide.CreateExplosion.

Key Value Description
Glide.EXPLOSION_TYPE.MISSILE 0 Default explosion, can be heard from very far away.
Glide.EXPLOSION_TYPE.VEHICLE 1 A larger version of Glide.EXPLOSION_TYPE.MISSILE, plays a metalic-like sound.
Glide.EXPLOSION_TYPE.TURRET 2 A small explosion, plays a very short sound, meant to happen in quick succession.

Shared Glide.VEHICLE_TYPE

These are values returned from Vehicle.VehicleType. It hints the type of vehicle that you're dealing with.

Key Value Description
Glide.VEHICLE_TYPE.UNDEFINED 0 This vehicle uses base_glide as the base class, or has not defined a type.
Glide.VEHICLE_TYPE.CAR 1 This vehicle uses base_glide_car as the base, or has defined itself as a car.
Glide.VEHICLE_TYPE.MOTORCYCLE 2 This vehicle uses base_glide_motorcycle as the base, or has defined itself as a motorcycle.
Glide.VEHICLE_TYPE.HELICOPTER 3 This vehicle uses base_glide_heli as the base, or has defined itself as a helicopter.
Glide.VEHICLE_TYPE.PLANE 4 This vehicle uses base_glide_plane as the base, or has defined itself as a plane.
Glide.VEHICLE_TYPE.TANK 5 This vehicle uses base_glide_tank as the base, or has defined itself as a tank.

Shared Glide.DANGER_TYPE

Used on SERVER Glide.SendMissileDanger to notify clients about incoming lock-on/missiles.

Key Value Description
Glide.DANGER_TYPE.LOCK_ON 1 The target player just got locked-on, plays 3 short bleeps.
Glide.DANGER_TYPE.MISSILE 2 The target player tracks the incoming missile, bleeps get shorter and shorter as the missile approaches.

Shared Glide.LOCKON_WHITELIST

A table containing class names as keys and true as values. Used by SERVER Glide.FindLockOnTarget to filter which entities can be locked-on.


Shared Glide.MOUSE_FLY_MODE

Used by the input system to handle mouse input while flying aircraft.

Key Value Description
Glide.MOUSE_FLY_MODE.AIM 0 Point-to-aim
Glide.MOUSE_FLY_MODE.DIRECT 1 Control movement directly
Glide.MOUSE_FLY_MODE.CAMERA 2 Free camera (Use keyboard only)

SERVER Glide.SURFACE_GRIP

A table containing surface material numbers as keys and numbers as values. These values are used by wheels to change the grip multiplier depending on which surface they are in contact with.


SERVER Glide.SURFACE_RESISTANCE

A table containing surface material numbers as keys and numbers as values. These values are used by wheels to slow down the vehicle depending on which surface they are in contact with.


Shared Glide.DEFAULT_HEADLIGHT_COLOR

Default color for headlights. Used by some of the default cars included in the base, on their Vehicle.LightSprites and Vehicle.Headlights entity variables.


CLIENT Glide.CAMERA_TYPE

Vehicle camera types. Used to return a value on CLIENT Vehicle:GetCameraType.

Key Value Description
Glide.CAMERA_TYPE.CAR 0 Orbit camera. Always stays upright. Shakes on high speeds.
Glide.CAMERA_TYPE.TURRET 1 Orbit camera. Always stays upright. Does not auto-center.
Glide.CAMERA_TYPE.AIRCRAFT 2 Orbit camera. Will rotate with the vehicle when using Glide.MOUSE_FLY_MODE.CAMERA.

CLIENT Glide.ROLL_MARK_SURFACES

A table containing surface material numbers as keys and true as values. Used by wheels to do tire roll marks on certain surfaces.


CLIENT Glide.WHEEL_SOUNDS

A table of tables, containing data about sound file paths for each surface material, for different situations (slipping sideways, slipping forwards, rolling slowly, and rolling fast).


CLIENT Glide.THEME_COLOR

A value containing the main theme color for Glide.

⚠ Warning: Some UI panels may modify the alpha value of this color. If you use it directly to draw things, they might appear transparent or invisible. Change the color's alpha value before using it, or copy the RGB values to a separate Color instance if necessary.

Functions

For the purposes of organization, functions are grouped into these categories:

Utilities

Shared Glide.Print( string str, varargs ... )

Prints a message to console, prefixed by a blue [Glide] tag. Allows for formatting strings as well.

Glide.Print( "I've got %i items from the %s marketplace.", 3, "Steam" )

Shared Glide.PrintDev( string str, varargs ... )

Same as Shared Glide.Print, but only prints if the developer console variable is set to 1 or greater.


Shared boolean = Glide.GetDevMode()

This is a convenience function to check if the developer console variable is greater than 0.


CLIENT Glide.GetLanguageText( string phrase )

This is a wrapper for language.GetPhrase, adding glide. at the start of the phrase you want to lookup.


CLIENT Vector, Angle = Glide.GetLocalViewLocation()

Get the cached position/angle of the local player's last rendered view. Unlike calling EyePos or EyeAngles, this can be called at any point without being affected by render.RenderView. It will always return what the local player sees on their screen.


Shared boolean = Glide.IsUnderWater( Vector pos )

Checks if a position is under water.


Shared boolean = Glide.HasBaseClass( Entity ent, string class )

Checks if a certain entity is a children of another entity class, no matter how deep it sits on the inheritance chain.


Shared boolean = Glide.IsAircraft( Entity vehicle )

Checks the vehicle's VehicleType, returns true if it's an plane or helicopter.


Shared Glide.HideEntity( Entity ent, boolean hide )

Hides an entity without using SetNoDraw. SetNoDraw can cause the entity to not exist on Entity:GetChildren clientside, so use this when you need to hide wheels, seats, or other parts of the vehicle.


Shared number = Glide.ExpDecay( number a, number b, number decay, number dt )

If you ever need Gmod's Lerp function, use this instead. Lerp is not consistent on different framerates/tickrates.


Shared number = Glide.ExpDecayAngle( number a, number b, number decay, number dt )

Same as Glide.ExpDecay, but works with numbers between 0 and 360, wrapping when necessary.


SERVER Glide.ClampForce( Vector force )

Ensures that the force is within the range of a float and engine limits, to prevent crashes when applying it. Returns nothing since it modifies the force Vector instance itself.


SERVER Glide.FilterEntityCopyTable( table data, table nwFields, table entFields )

Filters keys from a EntityCopyData table that was given by SERVERENTITY:OnEntityCopyTableFinish.

Only the required key-values, desired network variables (using the nwFields) and desired entity variables (using entFields) will be kept on the data table.


SERVER Glide.PreEntityCopy( Entity ent )

Used by many dupeable Glide entities on SERVERENTITY:PreEntityCopy, to allow saving Wiremod connections to other entities.

⚠ Warning: This function is used internally. Although you can use it, only do so if you know what you're doing.


SERVER Glide.PostEntityPaste( Player ply, Entity ent, table createdEntities )

Used by many dupeable Glide entities on SERVERENTITY:PostEntityPaste, to allow restoring Wiremod connections to other entities.

⚠ Warning: This function is used internally. Although you can use it, only do so if you know what you're doing.


SERVER traction = Glide.TractionRamp( number slipAngle, number sideTractionMaxAng, number sideTractionMax, number sideTractionMin )

Used by Glide wheels to calculate the sideways traction force depending on the slipAngle.

For more details, see the this page.


SERVER boolean = Glide.CanSpawnVehicle( Player ply )

Checks if the target ply has not reached the Glide vehicle limit yet.


SERVER Entity = Glide.VehicleFactory( Player ply, table data )

Used by Glide vehicles on SERVERduplicator.RegisterEntityClass.

It makes sure the duplicator system (or just spawning vehicles via the Spawn Menu) follows the limits from SERVERGlide.CanSpawnVehicle before creating a vehicle entity and returning it.


SERVER boolean = Glide.CanLockVehicle( Player ply, Entity vehicle )

Check if a player can lock the vehicle's doors by either being it's creator or being a CPPI friend of the creator.


SERVER boolean = Glide.CanLockVehicle( Player ply, Entity vehicle )

Check if a player can lock the vehicle's doors by either being it's creator or being a CPPI friend (prop protection buddy) of the creator.


SERVER boolean = Glide.CanEnterLockedVehicle( Player ply, Entity vehicle )

Checks if a player can enter a locked vehicle.


SERVER Glide.SwitchSeat( Player ply, number seatIndex )

If ply is in a Glide vehicle, switch them to the target seatIndex, if it's empty.


SERVER table = Glide.GetNearbyPlayers( Vector pos, number radius )

Finds and returns all human players near a certain position.


CLIENT Vector = Glide.GetCameraAimPos()

Returns the position where the local player's Glide camera is aiming at.


CLIENT IMaterial = Glide.GetCachedIcon( string path )

Caches and returns a material created from the given image file path.


CLIENT Glide.DrawWeaponCrosshair( number x, number y, string icon, number size, Color color )

Draw a weapon crosshair. icon is a path to a image file. size is relative to the screen resolution.


CLIENT Glide.DrawWeaponSelection( string name, string icon )

Draw a "weapon selection" indicator on the screen. icon is a path to a image file.


CLIENT string = Glide.GetVehicleIcon( Glide.VEHICLE_TYPE vehicleType )

Given a vehicle type, returns the icon image file path for it.


CLIENT Glide.DrawHealthBar( number x, number y, number w, number h, number health, string icon )

Draw a health bar, as can be seen when aiming at a Glide vehicle.

health is a value between 0 and 1.

icon is a optional path to a image file.


CLIENT Glide.DrawVehicleHealth( number x, number y, number w, number h, Glide.VEHICLE_TYPE vehicleType, number chassisHealth, number engineHealth )

Draw chassis and engine health bars, as can be seen when using the Vehicle Repair SWEP.

chassisHealth and engineHealth are values between 0 and 1.

CLIENT Glide.DrawLightSprite( Vector pos, Vector dir, number size, Color color )

Draw a sprite meant to represent lights.


CLIENT Glide.EngineStream = Glide.CreateEngineStream( Entity parent )

Creates and returns a new EngineStream.


CLIENT Glide.RangedFeature = Glide.CreateRangedFeature( Entity ent, number distance, number bias )

Creates and returns a new RangedFeature.


CLIENT Glide.UpdateFonts()

⚠ Warning: This function is used internally. Although you can use it, only do so if you know what you're doing.

Recreates all fonts used by Glide. This is called automatically when the screen resolution changes.


CLIENT Glide.Notify( table params )

Shows a notification using Glide's notification system. Check this page for more information.


CLIENT Glide.ShowTip( string text, string icon )

Shows a one-time notification using Glide's notification system.

icon is a path to a image file.

Note: One-time means that, if you call this function with the same text, it will only show once until the player rejoins the server/reloads the map.


CLIENT Glide.ShowKeyTip( string text, number key, string icon )

Shows a one-time key bind notification using Glide's notification system. Converts the key code to a friendly name.

text must contain a %s so this function can tell where to put the key.

key must be a KEY or MOUSE code.

icon is a path to a image file.

Note: One-time means that, if you call this function with the same text and key, it will only show once until the player rejoins the server/reloads the map.

Input

SERVER Glide.SetupPlayerInput( Player ply, table data )

⚠ Warning: This function is used internally. Although you can use it, only do so if you know what you're doing.

Validate and set the input action binds for a specific player.


SERVER Glide.ActivateInput( Player ply, Vehicle vehicle, number seatIndex )

⚠ Warning: This function is used internally. Although you can use it, only do so if you know what you're doing.

Starts listening to input events from this player, then forward those inputs to the specified vehicle as long as it exists.


SERVER Glide.DeactivateInput( Player ply )

⚠ Warning: This function is used internally. Although you can use it, only do so if you know what you're doing.

Stop listening to input events from this player.

Weaponry

SERVER Entity = Glide.GetClosestFlare( Vector pos, Vector dir, number radius )

Try to find the closest flare entity ahead of dir, within the specified radius. This is faster than finding flares manually with ents.FindByClass( "glide_flare" ).


SERVER Entity = Glide.CreateTurret( Entity vehicle, Vector offset, Angle angles )

Creates a glide_vehicle_turret with the relative offset and angles, and add that weapon to the vehicle's turretCount.

For more details about vehicle turrets, see this page.


SERVER Entity = Glide.FireMissile( Vector origin, Angle angle, Player attacker, Entity parent, Entity target )

Creates a glide_missile, and sets the specified attacker as the player who fired it.

The missile will ignore collisions with parent.

The target is a optional entity for the missile to follow.


SERVER Entity = Glide.FireProjectile( Vector origin, Angle angle, Player attacker, Entity parent )

Creates a glide_projectile, and sets the specified attacker as the player who fired it.

The projectile will ignore collisions with parent.


SERVER Glide.FireBullet( table params, table traceFilter )

Fires a bullet given the specified values on the params table.

traceFilter is a optional table (similar to the filter parameter from the trace structure) that will be used to ignore entities on the bullet's trace.

Required parameters

Name Type Description
pos Vector Origin of the bullet
ang Angle Angle representing the direction of the bullet
attacker Player The player who fired the bullet

Optional parameters

Name Type Description
inflictor Entity The entity that fired the bullet
spread number How much can the bullet randomly stray away from ang?
length number Max. distance the bullet can travel
damage number Bullet damage
isExplosive boolean Is the bullet going to explode when it hits?
explosionRadius number If isExplosive is true, this sets the blast radius
scale number Size of the tracer effect
tracerColor Color Color of the tracer effect
shellDirection Vector If set, throw a shell towards this direction

Example

Fires a explosive bullet, from the eye position of the first player to join the server.

local ply = Entity( 1 )

Glide.FireBullet( {
    pos = ply:EyePos(),
    ang = ply:EyeAngles(),
    attacker = ply,
    isExplosive = true
}, {
    filter = ply -- Don't let the bullet trace hit this player
} )

SERVER Glide.CreateExplosion( Entity inflictor, Player attacker, Vector origin, number radius, number damage, Vector normal, Glide.EXPLOSION_TYPE explosionType )

Utility function to deal damage and send a explosion event to nearby players.

inflictor is required. If attacker is not set or invalid, inflictor will be used as the attacker instead.

You can find a list of types for explosionType here.


CLIENT Glide.CreateExplosion( Vector pos, Vector normal, Glide.EXPLOSION_TYPE explosionType )

Creates all the necessary particle and sound effects for an explosion, depending on the type.


SERVER boolean, number = Glide.CanLockOnEntity( Entity ent, Vector origin, Vector normal, number threshold, number maxDistance, Player attacker, boolean includeEmpty, table traceFilter )

Returns true if the target entity can be locked on from a starting position (origin) and direction (normal).

Part of that includes checking if the dot product between normal and the direction towards the target entity is larger than threshold. That dot product is also returned by this function.

attacker is the player who is trying to lock-on.

Set includeEmpty to true to include vehicles without a driver.

traceFilter is a optional table (similar to the filter parameter from the trace structure) that will be used to ignore entities when performing visibility checks.


SERVER boolean, number = Glide.FindLockOnTarget( Vector origin, Vector normal, number threshold, number maxDistance, Player attacker, table traceFilter, table entFilter )

Finds all entities that we can lock on with SERVERGlide.CanLockOnEntity, then returns which one has the largest dot product between normal and the direction towards it.

traceFilter is a optional table (similar to the filter parameter from the trace structure) that will be used to ignore entities when performing visibility checks.

entFilter is a optional array of entities to not consider as possible targets.

Networking

SERVER Glide.SendNotification( Player target, table data )

Sends and shows a notification message to the target(s). target can be either a player entity or a table of player entities.

data is a key-value table for properties of the notification (such as text, icon, sound, etc). You can find a list here.


SERVER Glide.SendLockOnDanger( Player target )

Let the target(s) know about a incoming lock-on. This currently has the effect of playing plays 3 short bleeps.


SERVER Glide.SendMissileDanger( Player target, Entity missile )

Let the target(s) know about a incoming missile. This makes the target player(s) track the missile entity and play shorter beeps as that missile gets closer.

Note: Although you can use any entity as the missile, that entity has to have a CLIENTGetHasTarget function, then it will be tracked as long as that function returns true.


SERVER Glide.SendViewPunch( Player target, number force )

Apply a camera view punch to the target's Glide camera, if it is active.

Ragdolls

SERVER Glide.StoreSpawnInfo( Player ply )

Stores necessary data to respawn a player later, so it can restore health, armor and inventory.


SERVER Glide.RestoreSpawnInfo( Player ply, function restoreCallback )

Restores health, armor and inventory previously stored with SERVERGlide.StoreSpawnInfo. Does nothing if there is no data from that function.

restoreCallback is an optional function that will run after the player has "finished" respawning/restoring weapons.


SERVER Glide.RagdollPlayer( Player ply, Vector velocity, number unragdollTime )

Creates a ragdoll at ply's position that matches the player's pose, makes the player spectate that ragdoll, and applies a velocity to the ragdoll.

unragdollTime is a optional number of seconds to automatically call SERVERGlide.UnRagdollPlayer after that time has passed.


SERVER Glide.UnRagdollPlayer( Player ply, function restoreCallback )

If the player is still ragdolled, stops spectating the ragdoll, removes it, respawns the player and then calls SERVERGlide.RestoreSpawnInfo.

restoreCallback is an optional function that will run after the player has "finished" respawning/restoring weapons.