Garry's Mod Wiki

GM:SetupMove

GM:SetupMove( Player ply, CMoveData mv, CUserCmd cmd )
This hook is predicted. This means that in singleplayer, it will not be called in the Client realm.

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.

Arguments

1 Player ply
The player whose movement we are about to process
2 CMoveData mv
The move data to override/use
3 CUserCmd cmd
The command data

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 )

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)

Page Links


Special Pages


Wikis

?

Render Time: 39ms

Session 0
DB GetPage 3
Generate Html 15
SaveChanges 7
Render Body 0
Render Sidebar 12