GM/SetupMove

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Added link to Game Movement)
m
 
Line 42: Line 42:
 
hook.Add("SetupMove", "Disable Jumping", function(ply, mvd, cmd)
 
hook.Add("SetupMove", "Disable Jumping", function(ply, mvd, cmd)
 
if mvd:KeyDown(IN_JUMP) then
 
if mvd:KeyDown(IN_JUMP) then
mvd:RemoveKeys(IN_JUMP)
+
mvd:RemoveKey(IN_JUMP)
 
end
 
end
 
end)
 
end)
 
}}
 
}}

Latest revision as of 00:53, 8 January 2020

 GM:SetupMove( )

Contents

Description

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

See Game Movement for an explanation on the move system.

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:RemoveKey(IN_JUMP)
	end
end)


Personal tools
Navigation