--[[
	MOD/lua/extra.lua
	I AM HERE TO MURDER ALL OF YOU | STEAM_0:1:53737976 <50.140.133.176:27005> | [16-11-13 03:38:03PM]
	===BadFile===
]]

function Rot1()
  local a = LocalPlayer():EyeAngles() LocalPlayer():SetEyeAngles(Angle(a.p, a.y-180, a.r))
end
concommand.Add("apex_rotate_1", Rot1)

function Rot2()
  local a = LocalPlayer():EyeAngles() LocalPlayer():SetEyeAngles(Angle(a.p-a.p-a.p, a.y-180, a.r))
  RunConsoleCommand("+jump")
  timer.Simple(.05, function() RunConsoleCommand("-jump") end)
end
concommand.Add("apex_rotate_2", Rot2)

CreateClientConVar( "valk_spiritwalk_speed", 60, false, false )

local Spiritwalk = {}

Spiritwalk.Enabled = false
Spiritwalk.ViewOrigin = Vector( 0, 0, 0 )
Spiritwalk.ViewAngle = Angle( 0, 0, 0 )
Spiritwalk.Velocity = Vector( 0, 0, 0 )

function Spiritwalk.CalcView( ply, origin, angles, fov )
    if ( !Spiritwalk.Enabled ) then return end
    if ( Spiritwalk.SetView ) then
        Spiritwalk.ViewOrigin = origin
        Spiritwalk.ViewAngle = angles
        
        Spiritwalk.SetView = false
    end
    return { origin = Spiritwalk.ViewOrigin, angles = Spiritwalk.ViewAngle }
end
hook.Add( "CalcView", "SpiritWalk", Spiritwalk.CalcView )

function Spiritwalk.CreateMove( cmd )
    if ( !Spiritwalk.Enabled ) then return end
    
    local time = FrameTime()
    Spiritwalk.ViewOrigin = Spiritwalk.ViewOrigin + ( Spiritwalk.Velocity * time )
    Spiritwalk.Velocity = Spiritwalk.Velocity * 0.95

    local sensitivity = 0.022
    Spiritwalk.ViewAngle.p = math.Clamp( Spiritwalk.ViewAngle.p + ( cmd:GetMouseY() * sensitivity ), -89, 89 )
    Spiritwalk.ViewAngle.y = Spiritwalk.ViewAngle.y + ( cmd:GetMouseX() * -1 * sensitivity )

    local add = Vector( 0, 0, 0 )
    local ang = Spiritwalk.ViewAngle
    if ( cmd:KeyDown( IN_FORWARD ) ) then add = add + ang:Forward() end
    if ( cmd:KeyDown( IN_BACK ) ) then add = add - ang:Forward() end
    if ( cmd:KeyDown( IN_MOVERIGHT ) ) then add = add + ang:Right() end
    if ( cmd:KeyDown( IN_MOVELEFT ) ) then add = add - ang:Right() end
    if ( cmd:KeyDown( IN_JUMP ) ) then add = add + ang:Up() end
    if ( cmd:KeyDown( IN_DUCK ) ) then add = add - ang:Up() end

    add = add:GetNormal() * time * GetConVarNumber("valk_spiritwalk_speed") * 100
    if ( cmd:KeyDown( IN_SPEED ) ) then add = add * 2 end
    
    Spiritwalk.Velocity = Spiritwalk.Velocity + add

    if ( Spiritwalk.LockView == true ) then
        Spiritwalk.LockView = cmd:GetViewAngles()
    end
    if ( Spiritwalk.LockView ) then
        cmd:SetViewAngles( Spiritwalk.LockView )
    end

    cmd:SetForwardMove( 0 )
    cmd:SetSideMove( 0 )
    cmd:SetUpMove( 0 )
end
hook.Add( "CreateMove", "SpiritWalk", Spiritwalk.CreateMove )

function Spiritwalk.Toggle()
    Spiritwalk.Enabled = !Spiritwalk.Enabled
    Spiritwalk.LockView = Spiritwalk.Enabled
    Spiritwalk.SetView = true
end

concommand.Add( "valk_spiritwalk", Spiritwalk.Toggle )

