@name LightCycle #Version 1.01
#Made by Mr.Trikorder
@persist Mode Ea:angle Ed Ev Ey Rf:ranger Rb:ranger Front:vector Back:vector Steuer I Tyaw Kp1 Kd1 Kp2 Kd2 Kpa Kda
It=entity():isWeldedTo()
if(first()){
    runOnLast(1)
    if(It:type()!="prop_vehicle_prisoner_pod"){
        print("LightCycle only works with the Prisoner Pod")
        selfDestruct()
    }
    else{
        DT=20
        runOnTick(DT)
        Kp1=10000
        Kd1=Kp1*20/DT
        Kp2=60000
        Kd2=Kp2*20/DT
        Kpa=15000
        Kda=Kpa*20/DT
        Pos=It:pos()-It:up()*-32-It:right()*-13
        Ang=It:angles():rotateAroundAxis(It:forward(),-67)
        For=Ang:forward()
        Up=Ang:up()
        Ri=Ang:right()
        Mode=0
        It:setAlpha(0)
        It:setMass(500)
        entity():setAlpha(0)
        Black = vec(16,16,16)
        Chrome = vec(91,91,91)
        Light = vec(0,127,255)
        It:setColor(Light)
        I=0
        Tyaw=0
        Steuer=0
        #rod
        holoCreate(1,Pos+For*32+Up*8+Ri*18,vec(0.2,0.2,1),Ang:rotateAroundAxis(For,90),Black)
        holoParent(1,It)
        holoModel(1,"hqcylinder")
        holoMaterial(1,"models/debug/debugwhite")
        holoAlpha(1,255)
        holoCreate(2,Pos+For*32+Up*8+Ri*-18,vec(0.2,0.2,1),Ang:rotateAroundAxis(For,-90),Black)
        holoParent(2,It)
        holoModel(2,"hqcylinder")
        holoMaterial(2,"models/debug/debugwhite")
        holoAlpha(2,255)
        holoCreate(101,Pos+For*40+Ri*6,vec(0.2,0.2,1),Ang+ang(0,0,90),Light)
        holoParent(101,It)
        holoModel(101,"torus3")
        holoMaterial(101,"BakonGuy/BlankWhite")
        holoAlpha(101,255)
        holoCreate(102,Pos+For*40+Ri*-6,vec(0.2,0.2,1),Ang+ang(0,0,90),Light)
        holoParent(102,It)
        holoModel(102,"torus3")
        holoMaterial(102,"BakonGuy/BlankWhite")
        holoAlpha(102,255)
        holoCreate(103,Pos,vec(1,0.1,1),Ang:rotateAroundAxis(Up,-45):rotateAroundAxis(Ri,203),Light)
        holoParent(103,It)
        holoModel(103,"plane")
        holoMaterial(103,"BakonGuy/BlankWhite")
        holoAlpha(103,255)
        holoCreate(104,Pos,vec(1,0.1,1),Ang:rotateAroundAxis(Up,45):rotateAroundAxis(Ri,203),Light)
        holoParent(104,It)
        holoModel(104,"plane")
        holoMaterial(104,"BakonGuy/BlankWhite")
        holoAlpha(104,255)
        #frontwheel
        holoCreate(10,Pos+For*40,vec(3,3,10),Ang+ang(0,0,90),Black)
        holoParent(10,It)
        holoModel(10,"hqtorus2")
        holoMaterial(10,"models/debug/debugwhite")
        holoAlpha(10,0)
        holoCreate(11,Pos+For*40,vec(2.3,2.3,9),Ang+ang(0,0,90),Chrome)
        holoParent(11,It)
        holoModel(11,"hqtorus2")
        holoMaterial(11,"models/debug/debugwhite")
        holoAlpha(11,0)
        holoCreate(12,Pos+For*33+Up*9,vec(0.5,2.1,0.5),Ang:rotateAroundAxis(Ri,-15),Chrome)
        holoParent(12,It)
        holoModel(12,"prism")
        holoMaterial(12,"models/debug/debugwhite")
        holoAlpha(12,0)
        holoCreate(110,Pos+For*40,vec(2.5,2.5,9),Ang+ang(0,0,90),Light)
        holoParent(110,It)
        holoModel(110,"torus3")
        holoMaterial(110,"BakonGuy/BlankWhite")
        holoAlpha(110,0)
        #motor
        holoCreate(20,Pos+Up*-10+For*3,vec(1,1.57,4.5),Ang:rotateAroundAxis(Ri,83),Black)
        holoParent(20,It)
        holoModel(20,"hqcylinder")
        holoMaterial(20,"models/debug/debugwhite")
        holoAlpha(20,0)       
        holoCreate(21,Pos,vec(2.7,2.3,4),Ang:rotateAroundAxis(Ri,90),Black)
        holoParent(21,It)
        holoModel(21,"hqcone")
        holoMaterial(21,"models/debug/debugwhite")
        holoAlpha(21,0)
        holoCreate(22,Pos+Up*13+For*18,vec(4.1,2,1.1),Ang:rotateAroundAxis(Ri,20),Black)
        holoParent(22,It)
        holoModel(22,"hqicosphere2")
        holoMaterial(22,"models/debug/debugwhite")
        holoAlpha(22,0)
        holoCreate(120,Pos+For*10+Ri*7.1+Up*-4.8,vec(3,0.7,1),Ang:rotateAroundAxis(For,80):rotateAroundAxis(Up,-9):rotateAroundAxis(Ri,-10),Light)
        holoParent(120,It)
        holoModel(120,"plane")
        holoMaterial(120,"BakonGuy/BlankWhite")
        holoAlpha(120,0)
        holoCreate(121,Pos+For*10+Ri*-7.1+Up*-4.8,vec(3,0.7,1),Ang:rotateAroundAxis(For,-80):rotateAroundAxis(Up,9):rotateAroundAxis(Ri,-10),Light)
        holoParent(121,It)
        holoModel(121,"plane")
        holoMaterial(121,"BakonGuy/BlankWhite")
        holoAlpha(121,0)
        #casing
        holoCreate(30,Pos+For*-9,vec(2.5,2.2,2.5),Ang:rotateAroundAxis(Ri,-90),Black)
        holoParent(30,It)
        holoModel(30,"hqcone")
        holoMaterial(30,"models/debug/debugwhite")
        holoAlpha(30,0)
        holoCreate(31,Pos+For*-25+Up*15,vec(2,1.5,4.3),Ang:rotateAroundAxis(Ri,90),Black)
        holoParent(31,It)
        holoModel(31,"prism")
        holoMaterial(31,"models/debug/debugwhite")
        holoAlpha(31,0)
        holoCreate(130,Pos+For*-5.7,vec(1.05,0.91,0.1),Ang:rotateAroundAxis(Ri,90),Light)
        holoParent(130,It)
        holoModel(130,"hqcylinder")
        holoMaterial(130,"BakonGuy/BlankWhite")
        holoAlpha(130,0)
        holoCreate(131,Pos+For*-10+Up*5+Ri*5.5,vec(1.45,0.15,1),Ang:rotateAroundAxis(Ri,17):rotateAroundAxis(For,135):rotateAroundAxis(Up,33),Light)
        holoParent(131,It)
        holoModel(131,"plane")
        holoMaterial(131,"BakonGuy/BlankWhite")
        holoAlpha(131,0)
        holoCreate(132,Pos+For*-10+Up*5+Ri*-5.5,vec(1.45,0.15,1),Ang:rotateAroundAxis(Ri,17):rotateAroundAxis(For,-135):rotateAroundAxis(Up,-33),Light)
        holoParent(132,It)
        holoModel(132,"plane")
        holoMaterial(132,"BakonGuy/BlankWhite")
        holoAlpha(132,0)
        holoCreate(133,Pos+For*-16.85+Up*22.95+Ri*4,vec(3,0.05,1),Ang:rotateAroundAxis(Ri,13.1),Light)
        holoParent(133,It)
        holoModel(133,"plane")
        holoMaterial(133,"BakonGuy/BlankWhite")
        holoAlpha(133,0)
        holoCreate(134,Pos+For*-16.85+Up*22.95+Ri*-4,vec(3,0.05,1),Ang:rotateAroundAxis(Ri,13.1),Light)
        holoParent(134,It)
        holoModel(134,"plane")
        holoMaterial(134,"BakonGuy/BlankWhite")
        holoAlpha(134,0)
        holoCreate(135,Pos+For*-12+Up*15,vec(0.25,1.54,0.52),Ang:rotateAroundAxis(Ri,90),Light)
        holoParent(135,It)
        holoModel(135,"prism")
        holoMaterial(135,"BakonGuy/BlankWhite")
        holoAlpha(135,0)
        #backwheel
        holoCreate(40,Pos+For*-40,vec(3,3,10),Ang+ang(0,0,90),Black)
        holoParent(40,It)
        holoModel(40,"hqtorus2")
        holoMaterial(40,"models/debug/debugwhite")
        holoAlpha(40,0)
        holoCreate(41,Pos+For*-40,vec(2.3,2.3,9),Ang+ang(0,0,90),Chrome)
        holoParent(41,It)
        holoModel(41,"hqtorus2")
        holoMaterial(41,"models/debug/debugwhite")
        holoAlpha(41,0)
        holoCreate(42,Pos+For*-37.7+Up*2.3,vec(2,1,1.2),Ang:rotateAroundAxis(Ri,135),Chrome)
        holoParent(42,It)
        holoModel(42,"prism")
        holoMaterial(42,"models/debug/debugwhite")
        holoAlpha(42,0)
        holoCreate(140,Pos+For*-40,vec(2.5,2.5,9),Ang+ang(0,0,90),Light)
        holoParent(140,It)
        holoModel(140,"torus3")
        holoMaterial(140,"BakonGuy/BlankWhite")
        holoAlpha(140,0)
        holoCreate(141,Pos+For*-40+Up*0,vec(3.04,3.04,1),Ang+ang(0,0,90),Light)
        holoParent(141,It)
        holoModel(141,"torus3")
        holoMaterial(141,"BakonGuy/BlankWhite")
        holoAlpha(141,0)
        print("LightCycle ready")
        print("Type '-[color]' while close to the LightCycle to choose a color, e.g.: -blue")
    }
}
rangerPersist(1)
rangerHitWater(1)
rangerFilter(It)
if(Mode==7){#positioning rod
    Pos=It:pos()
    Ang=It:angles():rotateAroundAxis(It:up(),90):rotateAroundAxis(It:forward(),-I*3)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40
    Back=Pos-For*40
    holoPos(3,Pos+Ri*(45-I*3)+For*2)
    holoPos(4,Pos+Ri*(45-I*3)+For*-2)
    holoPos(1,Pos+Ri*(45-I*3)+For*6)
    holoPos(2,Pos+Ri*(45-I*3)+For*-6)
    Rb=rangerOffset(25,Pos,vec(0,0,-1))
    Ea=angnorm(ang(0,Tyaw,0)-Ang)
    Ed=10-Rb:distance()+11*I/15
    It:applyAngForce(ang(Ea:pitch()*Kp2+$Ea:pitch()*Kd2,Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp2+$Ea:roll()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100-For*(It:vel():dot(For))*100)
    if(I==0){
        Mode=0
    }
    else{I--}
}
if(Mode==6){#retract rod
    Pos=It:pos()+(It:up()*32+It:right()*13)*I/10
    Ang=It:angles():rotateAroundAxis(It:forward(),-67)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40*I/10
    Back=Pos-For*40*I/10
    holoPos(101,Pos+For*(40)+Ri*(2+4*I/10))
    holoScale(101,vec(0.2+2.85*I/10,0.2+2.3*I/10,1))
    holoAng(101,Ang+ang(0,0,90))
    holoPos(102,Pos+For*(40)+Ri*-(2+4*I/10))
    holoScale(102,vec(0.2+2.85*I/10,0.2+2.3*I/10,1))
    holoAng(102,Ang+ang(0,0,90))
    holoPos(1,Pos+For*(40)+Up*8*I/10+Ri*(6+12*I/10))
    holoAng(1,Ang:rotateAroundAxis(For,90-I/10):rotateAroundAxis(Up,-15*I/10))
    holoPos(2,Pos+For*(40)+Up*8*I/10+Ri*-(6+12*I/10))
    holoAng(2,Ang:rotateAroundAxis(For,-90+I/10):rotateAroundAxis(Up,15*I/10))
    soundPitch(1,100+I*6)
    Rf=rangerOffset(25,Front,vec(0,0,-1))
    Rb=rangerOffset(25,Back,vec(0,0,-1))
    Ea=angnorm(ang((asin((Rb:position():z()-Rf:position():z())/80)-22)*I/40-Ang:pitch(),Tyaw-Ang:yaw(),-Ang:roll()))
    Ed=21-(Rf:distance()+Rb:distance())/2
    Ev=0-It:vel():dot(For)
    It:applyAngForce(ang(Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp1+$Ea:roll()*Kd1,Ea:pitch()*Kp2+$Ea:pitch()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100+For*Ev*50)
    if(I==0){
        Tyaw=angnorm(Tyaw+90)
        soundStop(1)
        Mode=7
        I=15
    }
    else{I--}
}
if(Mode==5){#dematerialize LightCycle
    Pos=It:pos()+It:up()*32+It:right()*13
    Ang=It:angles():rotateAroundAxis(It:forward(),-67)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40
    Back=Pos-For*40
    holoAlpha(10,I*16)
    holoAlpha(11,I*16)
    holoAlpha(12,I*16)
    holoAlpha(110,I*16)
    holoAlpha(20,I*16)
    holoAlpha(21,I*16)
    holoAlpha(22,I*16)
    holoAlpha(120,I*16)
    holoAlpha(121,I*16)
    holoAlpha(122,I*16)
    holoAlpha(30,I*16)
    holoAlpha(31,I*16)
    holoAlpha(130,I*161)
    holoAlpha(131,I*16)
    holoAlpha(132,I*16)
    holoAlpha(133,I*16)
    holoAlpha(134,I*16)
    holoAlpha(135,I*16)
    holoAlpha(40,I*161)
    holoAlpha(41,I*161)
    holoAlpha(42,I*16)
    holoAlpha(140,I*16)
    holoAlpha(141,I*16)
    holoAlpha(103,I*16)
    holoAlpha(104,I*16)
    soundPitch(1,190+I*6)
    Rf=rangerOffset(25,Front,vec(0,0,-1))
    Rb=rangerOffset(25,Back,vec(0,0,-1))
    Ea=angnorm(ang(asin((Rb:position():z()-Rf:position():z())/80)-Ang:pitch(),Tyaw-Ang:yaw(),-Ang:roll()))
    Ed=21-(Rf:distance()+Rb:distance())/2
    Ev=0-It:vel():dot(For)
    It:applyAngForce(ang(Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp1+$Ea:roll()*Kd1,Ea:pitch()*Kp2+$Ea:pitch()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100+For*Ev*50)
    if(I==0){
        holoScale(103,vec(1,0.1,1))
        holoAng(103,Ang:rotateAroundAxis(Up,-45):rotateAroundAxis(Ri,203))
        holoScale(104,vec(1,0.1,1))
        holoAng(104,Ang:rotateAroundAxis(Up,45):rotateAroundAxis(Ri,203))
        I=10
        Mode=6
    }
    else{I--}
}
if(Mode==4){#drive
    if(It:driver():keyAttack2()&!It:driver():keyAttack1()&Steuer<60){Steuer++}
    if(It:driver():keyAttack1()&!It:driver():keyAttack2()&Steuer>-60){Steuer--}
    if(!It:driver():keyAttack2()&Steuer>0){Steuer--}
    if(!It:driver():keyAttack1()&Steuer<0){Steuer++}
    Pos=It:pos()+It:up()*32+It:right()*13
    Ang=It:angles():rotateAroundAxis(It:forward(),-67)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40
    Back=Pos-For*40
    Rf=rangerOffset(22,Front,vec(0,0,-1))
    Rb=rangerOffset(22,Back,vec(0,0,-1))
    Ea=angnorm(ang(asin((Rb:position():z()-Rf:position():z())/80)-Ang:pitch(),0,Steuer*0.75-Ang:roll()))
    Ed=21-(Rf:distance()+Rb:distance())/2
    Ev=1000-It:vel():dot(For)
    Ey=($Front-$Back):dot(Ri)
    It:applyAngForce(ang(Ey*Kd2-Steuer*2000,Ea:roll()*Kp1+$Ea:roll()*Kd1,Ea:pitch()*Kp2+$Ea:pitch()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100+For*Ev*50)
    soundPitch(1,250-Ev/4)
    if(I<10){I++}
    if(Ev>=500&I==10){
        It:ejectPod()
        soundPitch(1,150)
        It:soundPlay(1,0,"weapons/explode1.wav")
    }
    if(!It:driver()){
        Tyaw=Ang:yaw()
        It:removeTrails()
        Mode=5
        Steuer=0
        I=15
    }
}
if(Mode==3){#materialize LightCycle
    Pos=It:pos()+It:up()*32+It:right()*13
    Ang=It:angles():rotateAroundAxis(It:forward(),-67)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40
    Back=Pos-For*40
    holoAlpha(10,clamp(I,1,16)*16-1)
    holoAlpha(11,clamp(I,1,16)*16-1)
    holoAlpha(12,clamp(I,1,16)*16-1)
    holoAlpha(110,clamp(I-8,1,16)*16-1)
    holoAlpha(20,clamp(I-8,1,16)*16-1)
    holoAlpha(21,clamp(I-8,1,16)*16-1)
    holoAlpha(22,clamp(I-8,1,16)*16-1)
    holoAlpha(120,clamp(I-16,1,16)*16-1)
    holoAlpha(121,clamp(I-16,1,16)*16-1)
    holoAlpha(122,clamp(I-16,1,16)*16-1)
    holoAlpha(30,clamp(I-16,1,16)*16-1)
    holoAlpha(31,clamp(I-16,1,16)*16-1)
    holoAlpha(130,clamp(I-24,1,16)*16-1)
    holoAlpha(131,clamp(I-24,1,16)*16-1)
    holoAlpha(132,clamp(I-24,1,16)*16-1)
    holoAlpha(133,clamp(I-24,1,16)*16-1)
    holoAlpha(134,clamp(I-24,1,16)*16-1)
    holoAlpha(135,clamp(I-24,1,16)*16-1)
    holoAlpha(40,clamp(I-24,1,16)*16-1)
    holoAlpha(41,clamp(I-24,1,16)*16-1)
    holoAlpha(42,clamp(I-24,1,16)*16-1)
    holoAlpha(140,clamp(I-32,1,16)*16-1)
    holoAlpha(141,clamp(I-32,1,16)*16-1)
    holoAlpha(103,clamp(I-32,1,16)*16-1)
    holoAlpha(104,clamp(I-32,1,16)*16-1)
    soundPitch(1,100+I*3)
    Rf=rangerOffset(25,Front,vec(0,0,-1))
    Rb=rangerOffset(25,Back,vec(0,0,-1))
    Ea=angnorm(ang(asin((Rb:position():z()-Rf:position():z())/80)-Ang:pitch(),Tyaw-Ang:yaw(),-Ang:roll()))
    Ed=21-(Rf:distance()+Rb:distance())/2
    Ev=0-It:vel():dot(For)
    It:applyAngForce(ang(Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp1+$Ea:roll()*Kd1,Ea:pitch()*Kp2+$Ea:pitch()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100+For*Ev*50)
    if(I==48){
        It:setTrails(128,128,20,"trails/laser",It:getColor(),255)
        I=0
        Mode=4
    }
    else{I++}
}
if(Mode==2){#deploy rod
    Pos=It:pos()+(It:up()*32+It:right()*13)*I/50
    Ang=It:angles():rotateAroundAxis(It:forward(),-67)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40*I/50
    Back=Pos-For*40*I/50
    holoPos(101,Pos+For*(90-I)+Ri*(2+4*I/50))
    holoScale(101,vec(0.2+2.85*I/50,0.2+2.3*I/50,1))
    holoAng(101,Ang+ang(0,0,90))
    holoPos(102,Pos+For*(90-I)+Ri*-(2+4*I/50))
    holoScale(102,vec(0.2+2.85*I/50,0.2+2.3*I/50,1))
    holoAng(102,Ang+ang(0,0,90))
    holoPos(1,Pos+For*(90-58*I/50)+Up*8*I/50+Ri*(6+12*I/50))
    holoAng(1,Ang:rotateAroundAxis(For,90-I/10):rotateAroundAxis(Up,-15*I/50))
    holoPos(2,Pos+For*(90-58*I/50)+Up*8*I/50+Ri*-(6+12*I/50))
    holoAng(2,Ang:rotateAroundAxis(For,-95+I/10):rotateAroundAxis(Up,15*I/50))
    soundPitch(1,100+I*2)
    Rf=rangerOffset(25,Front,vec(0,0,-1))
    Rb=rangerOffset(25,Back,vec(0,0,-1))
    Ea=angnorm(ang((asin((Rb:position():z()-Rf:position():z())/80)-22)*I/200-Ang:pitch(),Tyaw-Ang:yaw(),-Ang:roll()))
    Ed=21-(Rf:distance()+Rb:distance())/2
    Ev=0-It:vel():dot(For)
    It:applyAngForce(ang(Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp1+$Ea:roll()*Kd1,Ea:pitch()*Kp2+$Ea:pitch()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100+For*Ev*50)
    if(I==50){
        I=1
        Mode=3
        holoPos(103,Pos+For*33+Up*23.5+Ri*-1.06)
        holoAng(103,Ang:rotateAroundAxis(Up,45):rotateAroundAxis(Ri,10))
        holoScale(103,vec(0.05,0.3,1))
        holoPos(104,Pos+For*33+Up*23.5+Ri*1.06)
        holoAng(104,Ang:rotateAroundAxis(Up,-45):rotateAroundAxis(Ri,10))
        holoScale(104,vec(0.05,0.3,1))
    }
    else{I++}
}
if(Mode==1){#positioning rod & driver
    Pos=It:pos()
    Ang=It:angles():rotateAroundAxis(It:up(),90):rotateAroundAxis(It:forward(),-I)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40
    Back=Pos-For*40
    holoPos(101,Pos+Ri*(45+I)+For*2)
    holoPos(102,Pos+Ri*(45+I)+For*-2)
    holoPos(1,Pos+Ri*(45+I)+For*6)
    holoPos(2,Pos+Ri*(45+I)+For*-6)
    Rb=rangerOffset(25,Pos,vec(0,0,-1))
    Ea=angnorm(ang(0,Tyaw,0)-Ang)
    Ed=10-Rb:distance()+11*I/45
    It:applyAngForce(ang(Ea:pitch()*Kp2+$Ea:pitch()*Kd2,Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp2+$Ea:roll()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100-For*(It:vel():dot(For))*100)
    if(I==45){
        Tyaw=angnorm(Tyaw-90)
        I=0
        Mode=2
        It:soundPlay(1,0,"ambient/atmosphere/undercity_loop1.wav")
        soundVolume(1,0.2)
    }
    else{I++}
}
if(Mode==0){#idle
    runOnChat(1)
    Pos=It:pos()
    Ang=It:angles():rotateAroundAxis(It:up(),90)
    For=Ang:forward()
    Up=Ang:up()
    Ri=Ang:right()
    Front=Pos+For*40
    Back=Pos-For*40
    findByClass("player")
    if(findClipToSphere(Pos,100)){
        Player=findClosest(Pos)
        holoPos(103,Pos+Up*(32+I/4)+Ri*10+For*-3.9)
        holoPos(104,Pos+Up*(32+I/4)+Ri*10+For*3.9)
        holoAlpha(103,I*4)
        holoAlpha(104,I*4)
        I++
        if(I==64){I=0}
        if(Steuer<10){Steuer++}
        Tyaw=angnorm((Pos-Player:pos()):toAngle():yaw()-90)
        if(Player:lastSaid():sub(1,1)=="-"&chatClk(Player)){
            Color=Player:lastSaid():sub(2,Player:lastSaid():length()):lower()
            if(Color=="red"){Light=vec(255,0,0)}
            if(Color=="orange"){Light=vec(255,127,0)}
            if(Color=="yellow"){Light=vec(255,255,0)}
            if(Color=="green"){Light=vec(0,255,0)}
            if(Color=="teal"){Light=vec(0,255,255)}
            if(Color=="blue"){Light=vec(0,127,255)}
            if(Color=="purple"){Light=vec(127,0,255)}
            if(Color=="pink"){Light=vec(255,0,255)}
            if(Color=="white"){Light=vec(255,255,255)}
            if(Color=="black"){Light=vec(0,0,0)}
            if(Color=="random"){Light=vec(random(255),random(255),random(255))}
            if(Color=="party"){Light=vec(random(255),random(255),random(255))}
            if(Color=="red"|Color=="orange"|Color=="yellow"|Color=="green"|Color=="teal"|Color=="blue"|Color=="purple"|Color=="pink"|Color=="white"|Color=="black"|Color=="random"|Color=="party"){
                It:setColor(Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(101,Light)
                holoColor(102,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(103,Light)
                holoColor(104,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(110,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(120,Light)
                holoColor(121,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(130,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(131,Light)
                holoColor(132,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(133,Light)
                holoColor(134,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(135,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(140,Light)
                if(Color=="party"){Light=vec(random(255),random(255),random(255))}
                holoColor(141,Light)
            }
        }
    }
    else{
        holoAlpha(103,0)
        holoAlpha(104,0)
        I=0
        if(Steuer>0){Steuer--}
    }
    holoPos(101,Pos+Up*Steuer*4+For*2)
    holoPos(102,Pos+Up*Steuer*4+For*-2)
    holoPos(1,Pos+Up*Steuer*4+For*6)
    holoPos(2,Pos+Up*Steuer*4+For*-6)
    Rb=rangerOffset(25,Pos,vec(0,0,-1))
    Ea=angnorm(ang(0,Tyaw,0)-Ang)
    Ed=10-Rb:distance()
    It:applyAngForce(ang(Ea:pitch()*Kp2+$Ea:pitch()*Kd2,Ea:yaw()*Kp1+$Ea:yaw()*Kd1,Ea:roll()*Kp2+$Ea:roll()*Kd2))
    It:applyForce(vec(0,0,Ed*Kpa+$Ed*Kda)-Ri*(It:vel():dot(Ri))*100-For*(It:vel():dot(For))*100)
    if(It:driver()){
        It:printDriver("Mouse1 - Left")
        It:printDriver("Mouse2 - Right")
        Mode=1
        holoAlpha(103,0)
        holoAlpha(104,0)
        I=0
        Steuer=0
        Tyaw=angnorm(Tyaw+180)
        runOnChat(0)
    }
}
if(last()){
    holoDeleteAll()
    soundStop(1)
    soundPurge()
    selfDestructAll()
}
