API Globals - StyledStrike/gmod-glide GitHub Wiki
This page lists all constants and functions that are accessible from the Glide
global table.
Constants
Glide.MAX_SEATS
Returns the max. amount of seats that Vehicle:CreateSeat
will allow.
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.
Glide.EXPLOSION_TYPE
Used on Glide.CreateExplosion
and Glide.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. |
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. |
Glide.DANGER_TYPE
Used on
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. |
Glide.LOCKON_WHITELIST
A table containing class names as keys and true
as values. Used by
Glide.FindLockOnTarget
to filter which entities can be locked-on.
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) |
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.
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.
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.
Glide.CAMERA_TYPE
Vehicle camera types. Used to return a value on
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 . |
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.
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).
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
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" )
Glide.PrintDev( string str, varargs ... )
Same as
Glide.Print
, but only prints if the developer
console variable is set to 1 or greater.
boolean = Glide.GetDevMode()
This is a convenience function to check if the developer
console variable is greater than 0
.
Glide.GetLanguageText( string phrase )
This is a wrapper for language.GetPhrase
, adding glide.
at the start of the phrase you want to lookup.
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.
boolean = Glide.IsUnderWater( Vector pos )
Checks if a position is under water.
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.
boolean = Glide.IsAircraft( Entity vehicle )
Checks the vehicle's VehicleType
, returns true
if it's an plane or helicopter.
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.
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.
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.
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.
Glide.FilterEntityCopyTable( table data, table nwFields, table entFields )
Filters keys from a EntityCopyData table that was given by ENTITY: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.
Glide.PreEntityCopy( Entity ent )
Used by many dupeable Glide entities on ENTITY: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.
Glide.PostEntityPaste( Player ply, Entity ent, table createdEntities )
Used by many dupeable Glide entities on ENTITY: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.
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.
boolean = Glide.CanSpawnVehicle( Player ply )
Checks if the target ply
has not reached the Glide vehicle limit yet.
Entity = Glide.VehicleFactory( Player ply, table data )
Used by Glide vehicles on duplicator.RegisterEntityClass
.
It makes sure the duplicator system (or just spawning vehicles via the Spawn Menu) follows the limits from Glide.CanSpawnVehicle
before creating a vehicle entity and returning
it.
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.
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.
boolean = Glide.CanEnterLockedVehicle( Player ply, Entity vehicle )
Checks if a player can enter a locked vehicle.
Glide.SwitchSeat( Player ply, number seatIndex )
If ply
is in a Glide vehicle, switch them to the target seatIndex
, if it's empty.
table = Glide.GetNearbyPlayers( Vector pos, number radius )
Finds and returns all human players near a certain position.
Vector = Glide.GetCameraAimPos()
Returns the position where the local player's Glide camera is aiming at.
IMaterial = Glide.GetCachedIcon( string path )
Caches and returns a material created from the given image file path
.
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.
Glide.DrawWeaponSelection( string name, string icon )
Draw a "weapon selection" indicator on the screen. icon
is a path to a image file.
string = Glide.GetVehicleIcon( Glide.VEHICLE_TYPE vehicleType )
Given a vehicle type, returns the icon image file path for it.
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.
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
.
Glide.DrawLightSprite( Vector pos, Vector dir, number size, Color color )
Draw a sprite meant to represent lights.
Glide.EngineStream = Glide.CreateEngineStream( Entity parent )
Creates and returns a new EngineStream.
Glide.RangedFeature = Glide.CreateRangedFeature( Entity ent, number distance, number bias )
Creates and returns a new RangedFeature.
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.
Glide.Notify( table params )
Shows a notification using Glide's notification system. Check this page for more information.
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.
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
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.
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.
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
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" )
.
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.
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.
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
.
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
} )
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.
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.
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.
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 Glide.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
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.
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.
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 aGetHasTarget
function, then it will be tracked as long as that function returnstrue
.
Glide.SendViewPunch( Player target, number force )
Apply a camera view punch to the target's Glide camera, if it is active.
Ragdolls
Glide.StoreSpawnInfo( Player ply )
Stores necessary data to respawn a player later, so it can restore health, armor and inventory.
Glide.RestoreSpawnInfo( Player ply, function restoreCallback )
Restores health, armor and inventory previously stored with Glide.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.
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 Glide.UnRagdollPlayer
after that time has passed.
Glide.UnRagdollPlayer( Player ply, function restoreCallback )
If the player is still ragdolled, stops spectating the ragdoll, removes it, respawns the player and then calls Glide.RestoreSpawnInfo
.
restoreCallback
is an optional function that will run after the player has "finished" respawning/restoring weapons.