Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Created April 23, 2014 17:05
Show Gist options
  • Save CapsAdmin/11223728 to your computer and use it in GitHub Desktop.
Save CapsAdmin/11223728 to your computer and use it in GitHub Desktop.
-- meta
local Player = FindMetaTable("Player")
intDefaultPlayerSpeed = 210
intDefaultSlowSpeed = 30
function Player:SlowDown(intTime)
self.SlowDownTimes = self.SlowDownTimes or {}
self.SlowTime = CurTime() + intTime
end
function Player:SetMoveSpeed(intAmount)
self.MoveSpeed = intDefaultPlayerSpeed
self.MoveSpeed = math.Clamp(intAmount or self.MoveSpeed, 0, 1000)
self:SetWalkSpeed(math.Clamp(self.MoveSpeed, 0, 1000))
self:SetRunSpeed(math.Clamp(self.MoveSpeed, 0, 1000))
end
hook.Add("PlayerSpawn", "PlayerSpawn_Movement", function(ply)
ply:SetMoveSpeed()
end)
end
-- animation
do
hook.Add("KeyPress", "walk", function(ply, key)
if key == IN_WALK and ply:GetSlot( "slot_offhand" ) and ply:GetSlot( "slot_primaryweapon" ) and ply:GetActiveWeapon().WeaponTable.HoldType == "pistol" then
ply:SetLuaAnimation( "shield_idle" )
end
end)
hook.Add("KeyRelease", "walk", function(ply, key)
if key == IN_WALK and ply:GetSlot( "slot_offhand" ) and ply:GetSlot( "slot_primaryweapon" ) then
ply:ResetLuaAnimation( "shield_lower" )
ply:ResetLuaAnimation( "shield_idle", 1 )
end
end)
end
do -- move hook
local mult = 0.1
local function isWalk( ply, move )
if move:KeyDown(IN_WALK) or (ply.SlowTime and ply.SlowTime > CurTime()) then
return true
else
return false
end
end
hook.Add("Move", "PlayerSlowdown", function(ply, move)
local fwd = move:GetForwardSpeed()
local sid = move:GetSideSpeed()
if isWalk( ply, move ) then
if fwd>0 then
local szx = -ply:GetMaxSpeed() * -mult
if fwd>szx then
move:SetForwardSpeed(szx)
end
end
if fwd<0 then
local szg = -ply:GetMaxSpeed() * mult
if fwd<szg then
move:SetForwardSpeed(szg)
end
end
if sid>0 then
local sidszg = -ply:GetMaxSpeed() * -mult
if sid>sidszg then
move:SetSideSpeed(sidszg)
end
end
if sid<0 then
local sidszgh = -ply:GetMaxSpeed() * mult
if sid<sidszgh then
move:SetSideSpeed(sidszgh)
end
end
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment