Class

From GMod Wiki

Jump to: navigation, search
G Button.png Go to:
Fretta Articles
Structure
Name Class
Available On: NewerShared.png
Description:
A class structure is used by the Fretta Game Base to design classes which players can then select, or you can set, based on their team.

Members

Type Name Description
Type name description
String DisplayName This is the name of the class, for display purposes.
Integer WalkSpeed This is the walk speed of the class (without shift).
Float CrouchWalkSpeed This is the amount that the walk speed is multiplied by while crouching.
Integer RunSpeed This is the sprinting speed of the class (with shift).
Float DuckSpeed This is the speed that the class moves from standing to crouching (in seconds).
Integer JumpPower This is the jump power of the class (default: 160).
String PlayerModel This is the player model that is set for this class.
Boolean DrawTeamRing Whether or not colored team rings are displayed under players with this class.
Boolean DrawViewModel Whether or not a player's weapon appears in the first person view using this class.
Integer MaxHealth This is the maximum health of a player with this class.
Integer StartHealth This is how much health the player spawns with.
Integer StartArmor This is the amount of armor a player spawns with.
Boolean DropWeaponOnDie Whether or not a player's weapon gets dropped upon death.
Boolean TeammateNoCollide Whether or not a player should be able to walk through his teammates.
Boolean AvoidPlayers Push players that are able to walk through this player away.
Boolean Selectable When false, this class cannot be chosen from the select class menu.
Boolean FullRotation Allow the player's model to rotate completely with their view (i.e. looking 90 degrees up will rotate your player model 90 degrees).
Boolean DisableFootsteps Will disable or enable footstep sounds.
String Base The name of the base class to derive from.
Function Loadout This is called when the player is given their equipment.
Function OnSpawn This is called when the player respawns.
Function OnDeath This is called when the player dies.
Function Think This is called in the Think hook.
Function Move This is called whenever the player moves and can be used to create a fancy movement system.
Function OnKeyPress This is called when a player presses a key.
Function OnKeyRelease This is called when a player releases a key.
Function ShouldDrawLocalPlayer If you return true the local player will be visible, you'll see your own body.
Function CalcView This is called in the CalcView hook, use it to move the view camera around.
Function InputMouseApply Unknown
Function Footstep You can use this to make custom footstep sounds.

Example

DescriptionA basic Class file.
Used onNewerShared.png
Code
 
local CLASS = {} // This defines the class's table. We need it to enter the following values
CLASS.DisplayName	= "My Class"
CLASS.WalkSpeed 	= 400
CLASS.CrouchedWalkSpeed = 0.2
CLASS.RunSpeed		= 600
CLASS.DuckSpeed		= 0.2
CLASS.JumpPower		= 200
CLASS.PlayerModel	= "models/player/swat.mdl"
CLASS.DrawTeamRing	= true
CLASS.DrawViewModel	= true
CLASS.MaxHealth		= 100
CLASS.StartHealth	= 100
CLASS.StartArmor	= 0
CLASS.DropWeaponOnDie	= false
CLASS.TeammateNoCollide = true
CLASS.AvoidPlayers	= true
CLASS.Selectable	= true
CLASS.FullRotation	= false
CLASS.DisableFootsteps	= false
CLASS.Base		= "BaseClass"
 
function CLASS:Loadout( pl )
	pl:GiveAmmo( 255, "Pistol", true )
	pl:Give( "weapon_pistol" )
end
 
function CLASS:OnSpawn( pl )
end
 
function CLASS:OnDeath( pl, attacker, damageinfo )
end
 
function CLASS:Think( pl )
end
 
function CLASS:Move( pl, mv )
end
 
function CLASS:OnKeyPress( pl, key )
end
 
function CLASS:OnKeyRelease( pl, key )
end
 
function CLASS:ShouldDrawLocalPlayer( pl )
	return false
end
 
function CLASS:CalcView( pl, pos, ang, fov )
end
 
function CLASS:InputMouseApply( pl, cmd, x, y, angle )
end
 
function Class:Footstep( ply, pos, foot, sound, volume, rf )
end
 
player_class.Register( "MyClass", CLASS ) // This registers your class. The first argument is the reference name, the second is the class's table (that we defined before)
 
OutputN/A

Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox