Advertisement
KimonK

Untitled

Apr 5th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. -- 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
  2. CreateConVar( "sv_walkspeed_enabled", "1", FCVAR_REPLICATED, "Enable custom walk speed control" )
  3. CreateConVar( "sv_walkspeed_restrict_stand", "1", FCVAR_REPLICATED, "Clamp custom stand walk speed value to normal walk speed" )
  4. CreateConVar( "sv_walkspeed_restrict_crouch", "1", FCVAR_REPLICATED, "Clamp custom crouch walk speed value to normal walk speed" )
  5. CreateConVar( "sv_walkspeed_stand_init_val", "100", FCVAR_REPLICATED, "Initial custom stand walk speed value set for each player on spawn" )
  6. CreateConVar( "sv_walkspeed_crouch_init_val", "30", FCVAR_REPLICATED, "Initial custom crouch walk speed value set for each player on spawn" )
  7.  
  8. -- Default values (based on Sandbox gamemode); change if neededlocal walkSpeed, runSpeed, crouchSpeed = 200, 400, 60-- Get player metatablelocal ply = FindMetaTable( "Player" )
  9.  
  10. -- 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
  11. self._WalkSpeed = GetConVar( "sv_walkspeed_restrict_stand" ):GetBool() and value > ( self:GetWalkSpeed() or walkSpeed ) and ( self:GetWalkSpeed() or walkSpeed ) or value
  12. net.Start( "CustomPlayerWalkSpeed_NW_UpdateWalkSpeed" )
  13. net.WriteFloat( self._WalkSpeed )
  14. net.Send( self )
  15. 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
  16. self._CrouchWalkSpeed = GetConVar( "sv_walkspeed_restrict_crouch" ):GetBool() and value > crouchSpeed and crouchSpeed or value
  17. net.Start( "CustomPlayerWalkSpeed_NW_UpdateCrouchSpeed" )
  18. net.WriteFloat( self._CrouchWalkSpeed )
  19. net.Send( self )
  20. elseif CLIENT then-- meh, you get itendend-- Setting custom player speed; convenience function I guessfunction ply:SetAltPlayerSpeed( walk, crouch )
  21.  
  22. self:SetAltWalkSpeed( walk )
  23. self:SetAltCrouchedWalkSpeed( crouch )
  24.  
  25. end-- Server stuff hereif SERVER then-- durr
  26. util.AddNetworkString( "CustomPlayerWalkSpeed_NW_UpdateWalkSpeed" )
  27. util.AddNetworkString( "CustomPlayerWalkSpeed_NW_UpdateCrouchSpeed" )
  28. util.AddNetworkString( "CustomPlayerWalkSpeed_NW_PlayerSpawn" )
  29.  
  30. -- Initialize custom walkspeed variable
  31. 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()
  32. -- Set individual player's custom walk/crouch speed
  33. ply:SetAltPlayerSpeed( walk, crouch )
  34.  
  35. -- Current workaround for unknown error in initializing clientside speed variables on multiplayer
  36. timer.Simple( 1, function()
  37.  
  38. net.Start( "CustomPlayerWalkSpeed_NW_PlayerSpawn" )
  39. net.WriteFloat( walk )
  40. net.WriteFloat( crouch )
  41. net.Send( ply )
  42.  
  43. end )
  44.  
  45. end )
  46.  
  47. end-- Client stuff hereif CLIENT then-- Receive serverside player custom stand walk speed packet
  48. net.Receive( "CustomPlayerWalkSpeed_NW_UpdateWalkSpeed", function( len )
  49.  
  50. LocalPlayer()._WalkSpeed = net.ReadFloat()
  51.  
  52. end )
  53.  
  54. -- Receive serverside player custom crouch walk speed packet
  55. net.Receive( "CustomPlayerWalkSpeed_NW_UpdateCrouchSpeed", function( len )
  56.  
  57. LocalPlayer()._CrouchWalkSpeed = net.ReadFloat()
  58.  
  59. end )
  60.  
  61. -- Receive initialization packet
  62. net.Receive( "CustomPlayerWalkSpeed_NW_PlayerSpawn", function( len )local ply = LocalPlayer()
  63. ifnot ply._WalkSpeed andnot ply._CrouchWalkSpeed then
  64. ply._WalkSpeed = net.ReadFloat()
  65. ply._CrouchWalkSpeed = net.ReadFloat()
  66. endend )
  67.  
  68. end-- Setup the custom walk speed control in SetupMove
  69. 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
  70. mv:SetMaxClientSpeed( ply._CrouchWalkSpeed )
  71. else
  72. mv:SetMaxClientSpeed( ply._WalkSpeed )
  73. endendend )
  74.  
  75. -- Actually perform the action when holding down the walk button
  76. 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
  77. mv:SetMaxSpeed( ply._CrouchWalkSpeed )
  78. else
  79. mv:SetMaxSpeed( ply._WalkSpeed )
  80. mv:SetMaxClientSpeed( ply._WalkSpeed )
  81. endendend )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement