VXP

spirithack.lua

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