SHOW:
|
|
- or go back to the newest paste.
| 1 | - | if CLIENT then |
| 1 | + | -- meta |
| 2 | - | function CustomPlayerBindPress(pl, bind, wasin) |
| 2 | + | local Player = FindMetaTable("Player")
|
| 3 | - | if bind == "+walk" then |
| 3 | + | |
| 4 | - | pl.Walk = wasin |
| 4 | + | intDefaultPlayerSpeed = 210 |
| 5 | - | net.Start( "c2s_GoWalk" ) |
| 5 | + | intDefaultSlowSpeed = 30 |
| 6 | - | net.WriteBit( pl.Walk ) |
| 6 | + | |
| 7 | - | net.SendToServer() |
| 7 | + | function Player:SlowDown(intTime) |
| 8 | self.SlowDownTimes = self.SlowDownTimes or {}
| |
| 9 | self.SlowTime = CurTime() + intTime | |
| 10 | end | |
| 11 | - | hook.Add("PlayerBindPress", "CustomPlayerBindPress", CustomPlayerBindPress)
|
| 11 | + | |
| 12 | function Player:SetMoveSpeed(intAmount) | |
| 13 | self.MoveSpeed = intDefaultPlayerSpeed | |
| 14 | - | if SERVER then |
| 14 | + | self.MoveSpeed = math.Clamp(intAmount or self.MoveSpeed, 0, 1000) |
| 15 | - | util.AddNetworkString( "c2s_GoWalk" ); |
| 15 | + | self:SetWalkSpeed(math.Clamp(self.MoveSpeed, 0, 1000)) |
| 16 | - | net.Receive( "c2s_GoWalk", function( len, ply ) |
| 16 | + | self:SetRunSpeed(math.Clamp(self.MoveSpeed, 0, 1000)) |
| 17 | end | |
| 18 | - | ply.Walk = net.ReadBit() |
| 18 | + | |
| 19 | - | if ply.Walk == 1 then |
| 19 | + | |
| 20 | - | ply.Walk = true |
| 20 | + | hook.Add("PlayerSpawn", "PlayerSpawn_Movement", function(ply)
|
| 21 | - | else |
| 21 | + | ply:SetMoveSpeed() |
| 22 | - | ply.Walk = false |
| 22 | + | |
| 23 | end | |
| 24 | ||
| 25 | - | if ply.Walk then |
| 25 | + | -- animation |
| 26 | - | if ply:GetSlot( "slot_offhand" ) and ply:GetSlot( "slot_primaryweapon" ) and ply:GetActiveWeapon().WeaponTable.HoldType == "pistol" then |
| 26 | + | do |
| 27 | - | ply:SetLuaAnimation( "shield_idle" ) |
| 27 | + | hook.Add("KeyPress", "walk", function(ply, key)
|
| 28 | if key == IN_WALK and ply:GetSlot( "slot_offhand" ) and ply:GetSlot( "slot_primaryweapon" ) and ply:GetActiveWeapon().WeaponTable.HoldType == "pistol" then | |
| 29 | - | elseif !ply.Walk then |
| 29 | + | ply:SetLuaAnimation( "shield_idle" ) |
| 30 | - | if ply:GetSlot( "slot_offhand" ) and ply:GetSlot( "slot_primaryweapon" ) then |
| 30 | + | |
| 31 | - | ply:ResetLuaAnimation( "shield_lower" ) |
| 31 | + | |
| 32 | - | ply:ResetLuaAnimation( "shield_idle", 1 ) |
| 32 | + | |
| 33 | hook.Add("KeyRelease", "walk", function(ply, key)
| |
| 34 | if key == IN_WALK and ply:GetSlot( "slot_offhand" ) and ply:GetSlot( "slot_primaryweapon" ) then | |
| 35 | - | -- ply.IsSlowingDown = false |
| 35 | + | ply:ResetLuaAnimation( "shield_lower" ) |
| 36 | - | -- ply:SlowDown( .001 ) |
| 36 | + | ply:ResetLuaAnimation( "shield_idle", 1 ) |
| 37 | end | |
| 38 | end) | |
| 39 | end | |
| 40 | ||
| 41 | do -- move hook | |
| 42 | - | local Player = FindMetaTable("Player")
|
| 42 | + | local mult = 0.1 |
| 43 | local function isWalk( ply ) | |
| 44 | - | intDefaultPlayerSpeed = 210 |
| 44 | + | if ply:KeyDown(IN_WALK) or ( ply.SlowTime and ply.SlowTime > CurTime() )) then |
| 45 | - | intDefaultSlowSpeed = 30 |
| 45 | + | |
| 46 | else | |
| 47 | - | function Player:SetMoveSpeed(intAmount) |
| 47 | + | return false |
| 48 | - | self.MoveSpeed = intDefaultPlayerSpeed |
| 48 | + | |
| 49 | - | self.MoveSpeed = math.Clamp(intAmount or self.MoveSpeed, 0, 1000) |
| 49 | + | |
| 50 | - | self:SetWalkSpeed(math.Clamp(self.MoveSpeed, 0, 1000)) |
| 50 | + | |
| 51 | - | self:SetRunSpeed(math.Clamp(self.MoveSpeed, 0, 1000)) |
| 51 | + | hook.Add("Move", "PlayerSlowdown", function(ply, move)
|
| 52 | ||
| 53 | local fwd = move:GetForwardSpeed() | |
| 54 | - | local mult = 0.1 |
| 54 | + | local sid = move:GetSideSpeed() |
| 55 | - | local function isWalk( player ) |
| 55 | + | |
| 56 | - | if ((player.Walk) or ( player.SlowTime and player.SlowTime > CurTime() )) then |
| 56 | + | if isWalk( ply ) then |
| 57 | - | return true |
| 57 | + | |
| 58 | - | else |
| 58 | + | if fwd>0 then |
| 59 | - | return false |
| 59 | + | local szx = -ply:GetMaxSpeed() * -mult |
| 60 | ||
| 61 | if fwd>szx then | |
| 62 | move:SetForwardSpeed(szx) | |
| 63 | - | function Player:SlowDown(intTime) |
| 63 | + | end |
| 64 | - | self.SlowDownTimes = self.SlowDownTimes or {}
|
| 64 | + | |
| 65 | - | self.SlowTime = CurTime() + intTime |
| 65 | + | |
| 66 | - | if SERVER then |
| 66 | + | if fwd<0 then |
| 67 | - | umsg.Start( "slowBdcst" ) |
| 67 | + | local szg = -ply:GetMaxSpeed() * mult |
| 68 | - | umsg.Entity( self ) |
| 68 | + | |
| 69 | - | umsg.Float( intTime ) |
| 69 | + | if fwd<szg then |
| 70 | - | umsg.End() |
| 70 | + | move:SetForwardSpeed(szg) |
| 71 | end | |
| 72 | ||
| 73 | end | |
| 74 | ||
| 75 | - | if CLIENT then |
| 75 | + | if sid>0 then |
| 76 | - | usermessage.Hook( "slowBdcst", function( um ) |
| 76 | + | local sidszg = -ply:GetMaxSpeed() * -mult |
| 77 | - | local ply = um:ReadEntity() |
| 77 | + | |
| 78 | - | local int = um:ReadFloat() |
| 78 | + | if sid>sidszg then |
| 79 | - | ply.SlowTime = CurTime() + int + .1 |
| 79 | + | move:SetSideSpeed(sidszg) |
| 80 | end | |
| 81 | end | |
| 82 | ||
| 83 | - | hook.Add("PlayerSpawn", "PlayerSpawn_Movement", function(ply)
|
| 83 | + | if sid<0 then |
| 84 | - | ply:SetMoveSpeed() |
| 84 | + | local sidszgh = -ply:GetMaxSpeed() * mult |
| 85 | - | end) |
| 85 | + | |
| 86 | if sid<sidszgh then | |
| 87 | - | hook.Add("Move", "Ironsightslowdownins", function(pl, move)
|
| 87 | + | move:SetSideSpeed(sidszgh) |
| 88 | end | |
| 89 | - | local fwd = move:GetForwardSpeed() |
| 89 | + | end |
| 90 | - | local sid = move:GetSideSpeed() |
| 90 | + | |
| 91 | - | if fwd>0 then |
| 91 | + | |
| 92 | - | if isWalk( pl ) then |
| 92 | + | |
| 93 | - | local szx = -pl:GetMaxSpeed() * -mult |
| 93 | + | end |