@name Div&Tox
@inputs Pod:wirelink 
@persist Pos:vector Ang:angle 
@outputs 
runOnTick(1)

if (first() | dupefinished()) {
    Pos = entity():isWeldedTo():pos()
    Ang = entity():isWeldedTo():angles()
    
    function angle ang(V1:vector,V2:vector) {
        return (V2-V1):toAngle()
    }
    
    function number ang(V1:vector2,V2:vector2) {
        return (V2-V1):toAngle()
    }
    
    function number swivel(A:number,B:number) {
        local C1=(B+(360-A))%360
        local C2=C1-360
        return abs(C1)<abs(C2) ? C1 : C2
    }
    
    function angle swivel(A:angle,B:angle) {
        return ang(
            swivel(A:pitch(),B:pitch()),
            swivel(A:yaw(),B:yaw()),
            swivel(A:roll(),B:roll())
        )
    }
    
    function number entity:rotat(Ang:angle,Speed:normal) {
        This:applyAngForce((swivel(This:angles(),Ang) - This:angVel()) * This:mass())
        return 1
    }
    
    function number entity:rotat(Ang:angle) {
        This:rotat(Ang,1)
        return 1
    }
    
    function number entity:move(Vec:vector,Speed:normal) {
        This:applyForce(((Vec-This:pos())-This:vel())*This:mass()*Speed)
        return 1
    }
    
    function number entity:move(Vec:vector) {
        This:move(Vec,1)
        return 1
    }
    
    function number entity:moveNoReset(Vec:vector,Speed:normal,Slowdown:normal) {
        This:applyForce(((Vec-This:pos()-This:vel()*Slowdown))*This:mass()*Speed)
        return 1
    }
    
    holoCreate(1)
    holoModel(1,"hq_cone")
    holoAng(1,entity():isWeldedTo():toWorld(ang(0,0,90)))
    holoScale(1,vec(0.5,0.5,0.5))
    holoParent(1,entity():isWeldedTo())
}

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local W = Driver:keyForward()
local A = Driver:keyLeft()
local S = Driver:keyBack()
local D = Driver:keyRight()
local R = Driver:keyReload()
local Mouse1 = Driver:keyAttack1()
local Mouse2 = Driver:keyAttack2()
local Space = Driver:keyJump()
local Shift = Driver:keySprint()
local Alt = Driver:keyWalk()
local Active = Driver:isPlayer()
local PodEnt = entity():isWeldedTo()

Pos+=
    (
        (W ? PodEnt:right() : vec()) +
        (S ? PodEnt:right()*-1 : vec()) +
        (Space ? PodEnt:up() : vec()) +
        (Shift ? PodEnt:up()*-1 : vec())
    ) * 7
    
Ang+=
    (
        (A ? ang(0,1,0) : ang()) +
        (D ? ang(0,1,0)*-1  : ang())
    ) * 2
    
PodEnt:move(Pos)
PodEnt:rotat(Ang)
