Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Custom set walkspeed script-- Created by SupahMarioX with references from Garry's Mod wiki-- Left Alt is, by default, the walk key, so we have to accomodate players who rebinded their walk key-- to still be able to use this using the IN_WALK enumeration.-- We'll also add a server ConVar to be able to enable and disable the function of the script.--------------------------------------------------------------------------- So how the fuck do I use this script? ------------------------------------------------------------------------------------------ Player:SetAltWalkSpeed( <VALUE> ) ------------------------------- Set actual walk speed ------------------------------------------------------------------------------------------------ Player:SetAltCrouchedWalkSpeed( <VALUE> ) ------------------------ Set crouched custom walk speed ---------------------------------------------------------------------------------- Player:SetAltPlayerSpeed( <WALK_VALUE>, <CROUCH_VALUE> ) -------- Basically does above functions but in one function ---------------------------------------------------------------------- ConVars
- CreateConVar( "sv_walkspeed_enabled", "1", FCVAR_REPLICATED, "Enable custom walk speed control" )
- CreateConVar( "sv_walkspeed_restrict_stand", "1", FCVAR_REPLICATED, "Clamp custom stand walk speed value to normal walk speed" )
- CreateConVar( "sv_walkspeed_restrict_crouch", "1", FCVAR_REPLICATED, "Clamp custom crouch walk speed value to normal walk speed" )
- CreateConVar( "sv_walkspeed_stand_init_val", "100", FCVAR_REPLICATED, "Initial custom stand walk speed value set for each player on spawn" )
- CreateConVar( "sv_walkspeed_crouch_init_val", "30", FCVAR_REPLICATED, "Initial custom crouch walk speed value set for each player on spawn" )
- -- Default values (based on Sandbox gamemode); change if neededlocal walkSpeed, runSpeed, crouchSpeed = 200, 400, 60-- Get player metatablelocal ply = FindMetaTable( "Player" )
- -- Setting custom STAND walk speedfunction ply:SetAltWalkSpeed( value )if SERVER then-- Ensure that custom stand walk speed doesn't exceed normal walk speed to accidentally increase speed, unless disabled by ConVar
- self._WalkSpeed = GetConVar( "sv_walkspeed_restrict_stand" ):GetBool() and value > ( self:GetWalkSpeed() or walkSpeed ) and ( self:GetWalkSpeed() or walkSpeed ) or value
- net.Start( "CustomPlayerWalkSpeed_NW_UpdateWalkSpeed" )
- net.WriteFloat( self._WalkSpeed )
- net.Send( self )
- elseif CLIENT then-- We say fuck-you to the client because the speed should be altered serversideendend-- Setting custom CROUCH walk speedfunction ply:SetAltCrouchedWalkSpeed( value )if SERVER then-- Ensure that custom crouch walk speed doesn't exceed normal crouch walk speed to accidentally increase speed, unless disabled by ConVar
- self._CrouchWalkSpeed = GetConVar( "sv_walkspeed_restrict_crouch" ):GetBool() and value > crouchSpeed and crouchSpeed or value
- net.Start( "CustomPlayerWalkSpeed_NW_UpdateCrouchSpeed" )
- net.WriteFloat( self._CrouchWalkSpeed )
- net.Send( self )
- elseif CLIENT then-- meh, you get itendend-- Setting custom player speed; convenience function I guessfunction ply:SetAltPlayerSpeed( walk, crouch )
- self:SetAltWalkSpeed( walk )
- self:SetAltCrouchedWalkSpeed( crouch )
- end-- Server stuff hereif SERVER then-- durr
- util.AddNetworkString( "CustomPlayerWalkSpeed_NW_UpdateWalkSpeed" )
- util.AddNetworkString( "CustomPlayerWalkSpeed_NW_UpdateCrouchSpeed" )
- util.AddNetworkString( "CustomPlayerWalkSpeed_NW_PlayerSpawn" )
- -- Initialize custom walkspeed variable
- hook.Add( "PlayerSpawn", "CustomPlayerWalkSpeed_SV_PlayerSpawn", function( ply )local walk, crouch = GetConVar( "sv_walkspeed_stand_init_val" ):GetFloat(), GetConVar( "sv_walkspeed_crouch_init_val" ):GetFloat()
- -- Set individual player's custom walk/crouch speed
- ply:SetAltPlayerSpeed( walk, crouch )
- -- Current workaround for unknown error in initializing clientside speed variables on multiplayer
- timer.Simple( 1, function()
- net.Start( "CustomPlayerWalkSpeed_NW_PlayerSpawn" )
- net.WriteFloat( walk )
- net.WriteFloat( crouch )
- net.Send( ply )
- end )
- end )
- end-- Client stuff hereif CLIENT then-- Receive serverside player custom stand walk speed packet
- net.Receive( "CustomPlayerWalkSpeed_NW_UpdateWalkSpeed", function( len )
- LocalPlayer()._WalkSpeed = net.ReadFloat()
- end )
- -- Receive serverside player custom crouch walk speed packet
- net.Receive( "CustomPlayerWalkSpeed_NW_UpdateCrouchSpeed", function( len )
- LocalPlayer()._CrouchWalkSpeed = net.ReadFloat()
- end )
- -- Receive initialization packet
- net.Receive( "CustomPlayerWalkSpeed_NW_PlayerSpawn", function( len )local ply = LocalPlayer()
- ifnot ply._WalkSpeed andnot ply._CrouchWalkSpeed then
- ply._WalkSpeed = net.ReadFloat()
- ply._CrouchWalkSpeed = net.ReadFloat()
- endend )
- end-- Setup the custom walk speed control in SetupMove
- hook.Add( "SetupMove", "CustomPlayerWalkSpeed_SH_SetupMove", function( ply, mv, cmd )-- ConVar boolean checkifnot GetConVar( "sv_walkspeed_enabled" ):GetBool() thenreturnend-- If walk key is down and not holding the sprint key at the same timeif mv:KeyDown( IN_WALK ) andnot mv:KeyDown( IN_SPEED ) then-- We should consider the speed of ducking/crouching while walkingif mv:KeyDown( IN_DUCK ) then
- mv:SetMaxClientSpeed( ply._CrouchWalkSpeed )
- else
- mv:SetMaxClientSpeed( ply._WalkSpeed )
- endendend )
- -- Actually perform the action when holding down the walk button
- hook.Add( "Move", "CustomPlayerWalkSpeed_SH_Move", function( ply, mv )ifnot GetConVar( "sv_walkspeed_enabled" ):GetBool() thenreturnendif mv:KeyDown( IN_WALK ) andnot mv:KeyDown( IN_SPEED ) then-- We should consider the speed of ducking/crouching while walkingif mv:KeyDown( IN_DUCK ) then
- mv:SetMaxSpeed( ply._CrouchWalkSpeed )
- else
- mv:SetMaxSpeed( ply._WalkSpeed )
- mv:SetMaxClientSpeed( ply._WalkSpeed )
- endendend )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement