Advertisement
Ialmdev5DLL

noclip_cl

May 2nd, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. // SpiritWalk by RabidToaster
  2. // Original concept by RabidToaster + Devenger
  3.  
  4. local SW = {}
  5.  
  6. SW.Enabled = false
  7. SW.ViewOrigin = Vector( 0, 0, 0 )
  8. SW.ViewAngle = Angle( 0, 0, 0 )
  9. SW.Velocity = Vector( 0, 0, 0 )
  10.  
  11. function SW.CalcView( ply, origin, angles, fov )
  12. if ( !SW.Enabled ) then return end
  13. if ( SW.SetView ) then
  14. SW.ViewOrigin = origin
  15. SW.ViewAngle = angles
  16.  
  17. SW.SetView = false
  18. end
  19. return { origin = SW.ViewOrigin, angles = SW.ViewAngle }
  20. end
  21. hook.Add( "CalcView", "SpiritWalk", SW.CalcView )
  22.  
  23. function SW.CreateMove( cmd )
  24. if ( !SW.Enabled ) then return end
  25.  
  26. // Add and reduce the old velocity.
  27. local time = FrameTime()
  28. SW.ViewOrigin = SW.ViewOrigin + ( SW.Velocity * time )
  29. SW.Velocity = SW.Velocity * 0.95
  30.  
  31. // Rotate the view when the mouse is moved.
  32. local sensitivity = 0.022
  33. SW.ViewAngle.p = math.Clamp( SW.ViewAngle.p + ( cmd:GetMouseY() * sensitivity ), -89, 89 )
  34. SW.ViewAngle.y = SW.ViewAngle.y + ( cmd:GetMouseX() * -1 * sensitivity )
  35.  
  36. // What direction we're going to move in.
  37. local add = Vector( 0, 0, 0 )
  38. local ang = SW.ViewAngle
  39. if ( cmd:KeyDown( IN_FORWARD ) ) then add = add + ang:Forward() end
  40. if ( cmd:KeyDown( IN_BACK ) ) then add = add - ang:Forward() end
  41. if ( cmd:KeyDown( IN_MOVERIGHT ) ) then add = add + ang:Right() end
  42. if ( cmd:KeyDown( IN_MOVELEFT ) ) then add = add - ang:Right() end
  43. if ( cmd:KeyDown( IN_JUMP ) ) then add = add + ang:Up() end
  44. if ( cmd:KeyDown( IN_DUCK ) ) then add = add - ang:Up() end
  45.  
  46. // Speed.
  47. add = add:GetNormal() * time * 500
  48. if ( cmd:KeyDown( IN_SPEED ) ) then add = add * 2 end
  49.  
  50. SW.Velocity = SW.Velocity + add
  51.  
  52. // This stops us looking around crazily while spiritwalking.
  53. if ( SW.LockView == true ) then
  54. SW.LockView = cmd:GetViewAngles()
  55. end
  56. if ( SW.LockView ) then
  57. cmd:SetViewAngles( SW.LockView )
  58. end
  59.  
  60. // This stops us moving while spiritwalking.
  61. cmd:SetForwardMove( 0 )
  62. cmd:SetSideMove( 0 )
  63. cmd:SetUpMove( 0 )
  64. end
  65. hook.Add( "CreateMove", "SpiritWalk", SW.CreateMove )
  66.  
  67. function SW.Toggle()
  68. SW.Enabled = !SW.Enabled
  69. SW.LockView = SW.Enabled
  70. SW.SetView = true
  71.  
  72. local status = { [ true ] = "ON", [ false ] = "OFF" }
  73. print( "SpiritWalk " .. status[ SW.Enabled ] )
  74. end
  75. concommand.Add( "sw_toggle", SW.Toggle )
  76.  
  77. concommand.Add( "sw_pos", function() print( SW.ViewOrigin ) end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement