GM:SetupMove

From Garry's Mod
Jump to: navigation, search
 GM:SetupMove( )

Contents

Description

SetupMove is called before the engine process movements. This allows us to override the players movement.

NOTE This hook is predicted. This means that in singleplayer, it will not be called in the Client realm.

Arguments

Player ply

The player whose movement we are about to process

Arguments

CMoveData mv

The move data to override/use

Arguments

CUserCmd cmd

The command data

Examples

Example

Make drowning even more entertaining:

hook.Add( "SetupMove", "Drowning:HandleWaterInLungs", function( ply, mv, cmd )
	if ( ply:WaterLevel() > 2 ) then
		mv:SetUpSpeed( -100 )
		cmd:SetUpMove( -100 )
	end
end )


Examples

Example

Disable the player's ability to jump by removing a key from CMoveData:

local CMoveData = FindMetaTable("CMoveData")

function CMoveData:RemoveKeys(keys)
	-- Using bitwise operations to clear the key bits.
	local newbuttons = bit.band(self:GetButtons(), bit.bnot(keys))
	self:SetButtons(newbuttons)
end

hook.Add("SetupMove", "Disable Jumping", function(ply, mvd, cmd)
	if mvd:KeyDown(IN_JUMP) then
		mvd:RemoveKeys(IN_JUMP)
	end
end)


Personal tools
Navigation