@name Hovercraft
@inputs [Pod Cam]:wirelink 
@outputs Apply L1RD L2RD R1RD R2RD 
@persist Rotation LX Rang 
@trigger 
interval(15)

E = entity():isWeldedTo()

if (first() | dupefinished()) {
    holoCreate(1)
    holoModel(1,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(1,E:toWorld(vec(-32,18,-2)))
    holoAng(1,E:toWorld(ang(0,90,90)))
    holoScale(1,vec(0.5,0.5,0.8))
    holoParent(1,E)
    
    holoCreate(2)
    holoModel(2,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(2,E:toWorld(vec(-26,18,-2)))
    holoAng(2,E:toWorld(ang(0,90,90)))
    holoScale(2,vec(0.5,0.5,0.8))
    holoParent(2,E)
    
    holoCreate(3)
    holoModel(3,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(3,E:toWorld(vec(-20,18,-2)))
    holoAng(3,E:toWorld(ang(0,90,90)))
    holoScale(3,vec(0.5,0.5,0.8))
    holoParent(3,E)
    
    holoCreate(4)
    holoModel(4,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(4,E:toWorld(vec(-14,18,-2)))
    holoAng(4,E:toWorld(ang(0,90,90)))
    holoScale(4,vec(0.5,0.5,0.8))
    holoParent(4,E)
    
    holoCreate(5)
    holoModel(5,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(5,E:toWorld(vec(-8,18,-2)))
    holoAng(5,E:toWorld(ang(0,90,90)))
    holoScale(5,vec(0.5,0.5,0.8))
    holoParent(5,E)
    
    holoCreate(6)
    holoModel(6,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(6,E:toWorld(vec(-2,18,-2)))
    holoAng(6,E:toWorld(ang(0,90,90)))
    holoScale(6,vec(0.5,0.5,0.8))
    holoParent(6,E)
    
    holoCreate(7)
    holoModel(7,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(7,E:toWorld(vec(4,18,-2)))
    holoAng(7,E:toWorld(ang(0,90,90)))
    holoScale(7,vec(0.5,0.5,0.8))
    holoParent(7,E)
    
    holoCreate(8)
    holoModel(8,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(8,E:toWorld(vec(10,18,-2)))
    holoAng(8,E:toWorld(ang(0,90,90)))
    holoScale(8,vec(0.5,0.5,0.8))
    holoParent(8,E)
    
    holoCreate(9)
    holoModel(9,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(9,E:toWorld(vec(16,18,-2)))
    holoAng(9,E:toWorld(ang(0,90,90)))
    holoScale(9,vec(0.5,0.5,0.8))
    holoParent(9,E)
    
    holoCreate(10)
    holoModel(10,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(10,E:toWorld(vec(22,18,-2)))
    holoAng(10,E:toWorld(ang(0,90,90)))
    holoScale(10,vec(0.5,0.5,0.8))
    holoParent(10,E)
    
    holoCreate(11)
    holoModel(11,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(11,E:toWorld(vec(-30,-18,-2)))
    holoAng(11,E:toWorld(ang(0,90,90)))
    holoScale(11,vec(0.5,0.5,0.8))
    holoParent(11,E)
    
    holoCreate(12)
    holoModel(12,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(12,E:toWorld(vec(-24,-18,-2)))
    holoAng(12,E:toWorld(ang(0,90,90)))
    holoScale(12,vec(0.5,0.5,0.8))
    holoParent(12,E)
    
    holoCreate(13)
    holoModel(13,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(13,E:toWorld(vec(-18,-18,-2)))
    holoAng(13,E:toWorld(ang(0,90,90)))
    holoScale(13,vec(0.5,0.5,0.8))
    holoParent(13,E)
    
    holoCreate(14)
    holoModel(14,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(14,E:toWorld(vec(-12,-18,-2)))
    holoAng(14,E:toWorld(ang(0,90,90)))
    holoScale(14,vec(0.5,0.5,0.8))
    holoParent(14,E)
    
    holoCreate(15)
    holoModel(15,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(15,E:toWorld(vec(-6,-18,-2)))
    holoAng(15,E:toWorld(ang(0,90,90)))
    holoScale(15,vec(0.5,0.5,0.8))
    holoParent(15,E)
    
    holoCreate(16)
    holoModel(16,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(16,E:toWorld(vec(0,-18,-2)))
    holoAng(16,E:toWorld(ang(0,90,90)))
    holoScale(16,vec(0.5,0.5,0.8))
    holoParent(16,E)
    
    holoCreate(17)
    holoModel(17,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(17,E:toWorld(vec(6,-18,-2)))
    holoAng(17,E:toWorld(ang(0,90,90)))
    holoScale(17,vec(0.5,0.5,0.8))
    holoParent(17,E)
    
    holoCreate(18)
    holoModel(18,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(18,E:toWorld(vec(12,-18,-2)))
    holoAng(18,E:toWorld(ang(0,90,90)))
    holoScale(18,vec(0.5,0.5,0.8))
    holoParent(18,E)
    
    holoCreate(19)
    holoModel(19,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(19,E:toWorld(vec(18,-18,-2)))
    holoAng(19,E:toWorld(ang(0,90,90)))
    holoScale(19,vec(0.5,0.5,0.8))
    holoParent(19,E)
    
    holoCreate(20)
    holoModel(20,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(20,E:toWorld(vec(24,-18,-2)))
    holoAng(20,E:toWorld(ang(0,90,90)))
    holoScale(20,vec(0.5,0.5,0.8))
    holoParent(20,E)
    
    holoCreate(21)
    holoModel(21,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(21,E:toWorld(vec(36,0,-2)))
    holoAng(21,E:toWorld(ang(0,0,90)))
    holoScale(21,vec(0.5,0.5,0.8))
    holoParent(21,E)
    
    holoCreate(22)
    holoModel(22,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(22,E:toWorld(vec(36,6,-2)))
    holoAng(22,E:toWorld(ang(0,0,90)))
    holoScale(22,vec(0.5,0.5,0.8))
    holoParent(22,E)
    
    holoCreate(23)
    holoModel(23,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(23,E:toWorld(vec(36,-6,-2)))
    holoAng(23,E:toWorld(ang(0,0,90)))
    holoScale(23,vec(0.5,0.5,0.8))
    holoParent(23,E)
    
    holoCreate(24)
    holoModel(24,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(24,E:toWorld(vec(36,12,-2)))
    holoAng(24,E:toWorld(ang(0,0,90)))
    holoScale(24,vec(0.5,0.5,0.8))
    holoParent(24,E)
    
    holoCreate(25)
    holoModel(25,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(25,E:toWorld(vec(-36,0,-2)))
    holoAng(25,E:toWorld(ang(0,0,90)))
    holoScale(25,vec(0.5,0.5,0.8))
    holoParent(25,E)
    
    holoCreate(26)
    holoModel(26,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(26,E:toWorld(vec(-36,6,-2)))
    holoAng(26,E:toWorld(ang(0,0,90)))
    holoScale(26,vec(0.5,0.5,0.8))
    holoParent(26,E)
    
    holoCreate(27)
    holoModel(27,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(27,E:toWorld(vec(-36,-6,-2)))
    holoAng(27,E:toWorld(ang(0,0,90)))
    holoScale(27,vec(0.5,0.5,0.8))
    holoParent(27,E)
    
    holoCreate(28)
    holoModel(28,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(28,E:toWorld(vec(-36,12,-2)))
    holoAng(28,E:toWorld(ang(0,0,90)))
    holoScale(28,vec(0.5,0.5,0.8))
    holoParent(28,E)
    
    holoCreate(29)
    holoModel(29,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(29,E:toWorld(vec(39,-9,-2)))
    holoAng(29,E:toWorld(ang(0,-45,90)))
    holoScale(29,vec(0.5,0.5,2))
    holoParent(29,E)
    
    holoCreate(30)
    holoModel(30,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(30,E:toWorld(vec(-39,-9,-2)))
    holoAng(30,E:toWorld(ang(0,45,90)))
    holoScale(30,vec(0.5,0.5,2))
    holoParent(30,E)
    
    holoCreate(31)
    holoModel(31,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(31,E:toWorld(vec(27,21,-2)))
    holoAng(31,E:toWorld(ang(0,45,90)))
    holoScale(31,vec(0.5,0.5,2))
    holoParent(31,E)
    
    holoCreate(32)
    holoModel(32,"models/props_phx/wheels/magnetic_medium.mdl")
    holoPos(32,E:toWorld(vec(-27,21,-2)))
    holoAng(32,E:toWorld(ang(0,-45,90)))
    holoScale(32,vec(0.5,0.5,2))
    holoParent(32,E)
    
    for (I = 1,32) {
        holoClipEnabled(I,1,1)
        holoClip(I,vec(0,1,0),vec(0,-1,0),0)
    }
    
    E:setMass(1000)
    
    holoCreate(100)
    holoPos(100,E:toWorld(vec(0,0,0)))
    holoAng(100,E:toWorld(ang(0,180,0)))
    holoAlpha(100,0)
    holoParent(100,E)
    
    holoCreate(200)
    holoPos(200,holoEntity(100):toWorld(vec(-30,0,40)))
    holoAlpha(200,0)
    holoParent(200,1)
    
    Offset = holoEntity(200):pos()
    Self = holoEntity(200)
    Cam["Parent", entity] = Self
    Cam["Position", vector] = Offset
    
    holoCreate(300)
    holoCreate(400)
    holoCreate(500)
    holoCreate(600)
}

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local Active = Driver:isPlayer()
local W = Driver:keyForward()
local A = Driver:keyLeft()
local S = Driver:keyBack()
local D = Driver:keyRight()
local Space = Driver:keyJump()
local Shift = Driver:keySprint()
local M1 = Driver:keyAttack1()
local M2 = Driver:keyAttack2()
Cam["Activated",number] = Active

if (Space) {Height = 75} else {Height = 30}

RF = array(E)

rangerFilter(RF) L1R = rangerOffset(70,E:pos()+E:right()*30-E:forward()*50,-E:up())
rangerFilter(RF) L2R = rangerOffset(70,E:pos()-E:right()*30-E:forward()*50,-E:up())

rangerFilter(RF) R1R = rangerOffset(70,E:pos()+E:right()*30+E:forward()*50,-E:up())
rangerFilter(RF) R2R = rangerOffset(70,E:pos()-E:right()*30+E:forward()*50,-E:up())

holoPos(300,L1R:pos())
holoPos(400,L2R:pos())
holoPos(500,R1R:pos())
holoPos(600,R2R:pos())

L1RD = L1R:distance()
L2RD = L2R:distance()
R1RD = R1R:distance()
R2RD = R2R:distance()

Added = (L1RD+L2RD+R1RD+R2RD)/4

if (Active) {
    rangerFilter(E)
    rangerFilter(Seat)
    Ranger = rangerOffset(32768,Seat:pos(),Seat:toLocalAxis(Driver:eye()))
    Yaw = (Ranger:pos() - E:pos()):toAngle():yaw()
    Angle = ang((R1RD+R2RD)-(L1RD+L2RD),Yaw - 180,(L1RD+R1RD)-(R2RD+L2RD))
}

if (Added < Height) {
    Diff = Height - Added
    E:applyForce((vec(0,0,Diff * 25) - E:vel()) * E:mass() + E:forward() * (S-W) * E:mass() * 150 * (3 + Shift))
    E:applyAngForce((E:toLocal(Angle)*200 - E:angVel()*20) * shiftL(ang(E:inertia())))
}
