@name UFO
@persist A RotateSpeed RotateSpeedLimit LightRay MoveMultX MoveMultY MoveMultZ MoveMultXLimit MoveMultYLimit MoveMultZLimit Manual
@persist [Color]:vector
@persist [E Light Chair Driver Target BringTaget]:entity
@persist [Lights]:array
@persist [R RLand1 RLand2 RLand3 RLand4]:ranger

if (duped()|dupefinished()) {
    selfDestruct()
    selfDestructAll()
}
interval(100)
if (first()) {
    entity():setAlpha(0)
    entity():setPos(entity():pos()-vec(0,0,100))
    RotateSpeedLimit=40
    MoveMultXLimit=150
    MoveMultYLimit=150
    MoveMultZLimit=100
    
    function clip(ID:number, N:number, Length:number, ANG:angle) {
        holoClipEnabled( ID, N , 1 )
        holoClip( ID , N , vec( Length , 0 , 0 ):rotate( ANG ) , vec( 1 , 0 , 0 ):rotate( ANG ) , 0)
    }
    
    Color=hsv2rgb(vec(random(0,360),1,1))
    holoCreate(1,entity():toWorld(vec(0,0,100)))
    holoModel(1,"hq_sphere")
    holoScale(1,vec(30,30,5))
    holoAng(1,ang())
    holoColor(1,vec(100,100,100))
    E=holoEntity(1)
    clip(1,1,-27,ang(90,0,0))
    clip(1,2,-31,ang(-90,0,0))
    
    holoCreate(2,E:toWorld(vec(0,0,-10)))
    holoModel(2,"hq_torus_thick")
    holoScale(2,vec(40,40,10))
    holoAng(2,ang())
    holoColor(2,vec(80,80,80))
    holoParent(2,1)
    
    holoCreate(3,E:toWorld(vec(0,0,-10)))
    holoModel(3,"hq_torus_thin")
    holoScale(3,vec(42,42,8))
    holoAng(3,ang())
    holoColor(3,vec(20,20,20))
    holoParent(3,1)
    
    holoCreate(4,E:toWorld(vec(0,0,15)))
    holoModel(4,"hq_hdome_thin")
    holoScale(4,vec(15,15,10))
    holoAng(4,ang())
    holoColor(4,vec4(Color,100))
    holoParent(4,1)
    holoDisableShading(4,1)
    
    for (I=1,12) {
        holoCreate(I+4)
        holoPos(I+4,E:toWorld(vec(sin(I*30)*150,cos(I*30)*150,15)))
        holoModel(I+4,"hq_dome")
        holoColor(I+4,Color)
        holoAng(I+4,ang())
        holoDisableShading(I+4,1)
        holoParent(I+4,3)
        
    }
    
    for (I=1,12) {
        holoCreate(I+16)
        holoPos(I+16,E:toWorld(vec(sin(I*30)*200,cos(I*30)*200,-24)))
        holoModel(I+16,"hq_torus_thick")
        holoColor(I+16,Color)
        holoAng(I+16,ang())
        holoScale(I+16,vec(3,3,1))
        holoDisableShading(I+16,1)
        holoParent(I+16,2)
        holoEntity(I+16):setTrails(120,0,1,"trails/laser",Color,255)
        #E2powered things
        #[holoEntity(I+16):drawSprite("sprites/light_glow02",holoEntity(I+16):pos(),Color,255,150,150)
        lightCreate(I,holoEntity(I+16):pos())
        lightColor(I,Color)
        lightParent(I,holoEntity(I+16))]#
        
    }
    
    holoCreate(29,E:toWorld(vec(0,0,15.1)))
    holoModel(29,"hq_tube_thin")
    holoScale(29,vec(14,14,2))
    holoAng(29,ang())
    holoColor(29,vec(100,100,100))
    holoParent(29,1)
    
    holoCreate(30,E:toWorld(vec(0,0,1)))
    holoModel(30,"hq_cylinder")
    holoScale(30,vec(13.8,13.8,0.3))
    holoAng(30,ang())
    holoColor(30,vec(100,100,100))
    holoParent(30,1)
    
    holoCreate(31,E:toWorld(vec(0,0,-26.5)))
    holoModel(31,"hq_hdome_thin")
    holoScale(31,vec(16,16,4))
    holoColor(31,Color)
    holoAng(31,ang())
    holoParent(31,1)
    
    holoCreate(32,E:toWorld(vec(0,0,30)))
    holoModel(32,"models/effects/vol_light128x512.mdl")
    holoColor(32,Color)
    holoAlpha(32,0)
    holoAng(32,ang())
    holoScale(32,vec())
    holoParent(32,1)
    
    holoCreate(33)
    holoAng(33,ang())
    holoAlpha(33,0)
    holoParent(33,1)
    
    holoCreate(34,E:toWorld(vec(100,0,-50)))
    holoAng(34,E:toWorld(ang()))
    holoModel(34,"models/Mechanics/robotics/foot.mdl")
    holoColor(34,Color)
    holoMaterial(34,"models/debug/debugwhite")
    holoParent(34,1)
    
    holoCreate(35,E:toWorld(vec(-100,0,-50)))
    holoAng(35,E:toWorld(ang(0,180,0)))
    holoModel(35,"models/Mechanics/robotics/foot.mdl")
    holoColor(35,Color)
    holoMaterial(35,"models/debug/debugwhite")
    holoParent(35,1)
    
    holoCreate(36,E:toWorld(vec(0,100,-50)))
    holoAng(36,E:toWorld(ang(0,90,0)))
    holoModel(36,"models/Mechanics/robotics/foot.mdl")
    holoColor(36,Color)
    holoMaterial(36,"models/debug/debugwhite")
    holoParent(36,1)
    
    holoCreate(37,E:toWorld(vec(0,-100,-50)))
    holoAng(37,E:toWorld(ang(0,-90,0)))
    holoModel(37,"models/Mechanics/robotics/foot.mdl")
    holoColor(37,Color)
    holoMaterial(37,"models/debug/debugwhite")
    holoParent(37,1)
    
    holoCreate(0,holoEntity(30):pos())
    holoAlpha(0,0)
    holoParent(0,30)
    
    A=31
    
    #Light=holoEntity(30):drawSprite("sprites/light_glow01",holoEntity(30):pos()-vec(0,0,20),Color,0,500,500)
    #[lightCreate(1,holoEntity(31):pos())
    lightColor(1,Color)
    lightDistance(1,1500)
    lightParent(1,holoEntity(31))]#
    
    #soudns
    E:soundPlay("Work",0,"ambient/tones/garage.wav")
    holoEntity(33):soundPlay("LightRay",0,"ambient/machines/combine_shield_loop3.wav")
    soundPitch("LightRay",200)
    soundVolume("LightRay",0)
    holoEntity(31):soundPlay("LightRay2",0,"ambient/machines/combine_shield_loop3.wav")
    soundPitch("LightRay2",200)
    soundVolume("LightRay2",0)
    
    findIncludePlayerProps(owner())
    findByClass("prop_vehicle_prisoner_pod")
    Chair=findClosest(entity():pos())
    if (!Chair) {
        printColor(Color,"[KlyaniX_UFO]",vec(255,255,255)," : ",Color*0.8,"Please spawn Airboat seat first please!")
        selfDestruct()
    }
    Chair:setPos(E:pos())
    Chair:setAng(E:angles()-ang(0,90,0))
    Chair:setAlpha(0)
    noCollideAll(Chair,1)
    timer("parent",100)
    findClearBlackList()
    findClearWhiteList()
    #BringTaget=owner()
    Manual=1
}
holoAng(0,ang())
if (clk("parent")) {
    Chair:parentTo(holoEntity(0))
    printColor(Color,"[KlyaniX_UFO]",vec(255,255,255)," : ",Color*0.8,"Here we go! ;)")
}
holoAng(2,holoEntity(2):toWorld(ang(0,RotateSpeed+((MoveMultX/MoveMultXLimit+MoveMultY/MoveMultYLimit+MoveMultZ/MoveMultZLimit)/3)*25,0)))
soundPitch("Work",RotateSpeed/RotateSpeedLimit*65+(MoveMultX/MoveMultXLimit+MoveMultY/MoveMultYLimit+MoveMultZ/MoveMultZLimit)*20)
Driver=Chair:driver()
if (Manual) {
    if (Driver) {
        if (RotateSpeed<RotateSpeedLimit) {
            RotateSpeed=clamp(RotateSpeed+0.5,0,RotateSpeedLimit)
        } else {
            if (RotateSpeed==RotateSpeedLimit) {
                holoAlpha(34,0)
                holoAlpha(35,0)
                holoAlpha(36,0)
                holoAlpha(37,0)
            }
            holoAng(1,Driver:eyeAngles():setPitch(clamp(Driver:eyeAngles():pitch(),-60,60)))
            if (Driver:keyForward()) {
                if (Driver:keySprint()|E:angles():pitch()<-45) {
                    MoveMultX=clamp(MoveMultX+15,-MoveMultXLimit,MoveMultXLimit*2)
                } else {
                    if (MoveMultX<MoveMultXLimit) {
                        MoveMultX=clamp(MoveMultX+15,-MoveMultXLimit,MoveMultXLimit)
                    } else {
                        MoveMultX=clamp(MoveMultX-15,-MoveMultXLimit,MoveMultXLimit*2)
                    }
                }
            } elseif (Driver:keyBack()) {
                MoveMultX=clamp(MoveMultX-15,-MoveMultXLimit,MoveMultXLimit)
            }
            if (Driver:keyRight()) {
                MoveMultY=clamp(MoveMultY+15,-MoveMultYLimit,MoveMultYLimit)
            } elseif (Driver:keyLeft()) {
                MoveMultY=clamp(MoveMultY-15,-MoveMultYLimit,MoveMultYLimit)
            }
            if (Driver:keyJump()) {
                MoveMultZ=clamp(MoveMultZ+15,-MoveMultZLimit,MoveMultZLimit)
            } elseif (Driver:keyWalk()) {
                MoveMultZ=clamp(MoveMultZ-15,-MoveMultZLimit,MoveMultZLimit)
            }
            if (Driver:keyAttack1()&&changed(Driver:keyAttack1())) {
                if (LightRay) {
                    LightRay=0
                } else {
                    LightRay=1
                }
            }   
        } 
    } else {
        rangerFilter(players())
        RLand1=rangerOffset(200,E:toWorld(vec(100,0,-80)),vec(0,0,-1))
        rangerFilter(players())
        RLand2=rangerOffset(200,E:toWorld(vec(-100,0,-80)),vec(0,0,-1))
            rangerFilter(players())
        RLand3=rangerOffset(200,E:toWorld(vec(0,100,-80)),vec(0,0,-1))
            rangerFilter(players())
        RLand4=rangerOffset(200,E:toWorld(vec(0,-100,-80)),vec(0,0,-1))
        if (RLand1:hit()&RLand2:hit()&RLand3:hit()&RLand4:hit()) {
            holoPos(1,(RLand1:pos()+RLand2:pos()+RLand3:pos()+RLand4:pos())/4+vec(0,0,100))
            holoAng(1,ang())
            
            holoAlpha(34,255)
            holoAlpha(35,255)
            holoAlpha(36,255)
            holoAlpha(37,255)
            
            holoPos(34,RLand1:pos()+vec(0,0,16))
            holoPos(35,RLand2:pos()+vec(0,0,16))
            holoPos(36,RLand3:pos()+vec(0,0,16))
            holoPos(37,RLand4:pos()+vec(0,0,16))
    
            if (RotateSpeed>0) {
                RotateSpeed=clamp(RotateSpeed-2,0,RotateSpeedLimit)
            }
        } else {
            if (RotateSpeed<RotateSpeedLimit) {
                RotateSpeed=clamp(RotateSpeed+0.5,0,RotateSpeedLimit)
            }
        }
    }
    ######
    if (!Driver:keyForward()&!Driver:keyBack()) {
        if (MoveMultX>0) {
            MoveMultX=clamp(MoveMultX-25,0,MoveMultXLimit)
        } elseif (MoveMultX<0) {
            MoveMultX=clamp(MoveMultX+25,-MoveMultXLimit,0)
        }
    }
    if (!Driver:keyRight()&!Driver:keyLeft()) {
        if (MoveMultY>0) {
            MoveMultY=clamp(MoveMultY-25,0,MoveMultYLimit)
        } elseif (MoveMultY<0) {
            MoveMultY=clamp(MoveMultY+25,-MoveMultYLimit,0)
        }
    }
    if (!Driver:keyJump()&!Driver:keyWalk()) {
        if (MoveMultZ>0) {
            MoveMultZ=clamp(MoveMultZ-25,0,MoveMultZLimit)
        } elseif (MoveMultZ<0) {
            MoveMultZ=clamp(MoveMultZ+25,-MoveMultZLimit,0)
        }
    }
    holoPos(1,E:pos()+holoEntity(1):forward()*MoveMultX+holoEntity(1):right()*MoveMultY+holoEntity(1):up()*MoveMultZ)
    ######
} else {
#[ NOT REALISED THINGS
if (RotateSpeed<RotateSpeedLimit) {
        RotateSpeed=clamp(RotateSpeed+0.5,0,RotateSpeedLimit)
    } else {
        if (RotateSpeed==RotateSpeedLimit) {
            holoAlpha(34,0)
            holoAlpha(35,0)
            holoAlpha(36,0)
            holoAlpha(37,0)
        }
        if (BringTaget) {
            if (E:pos():z()<1405) {
                holoPos(1,E:pos()+holoEntity(1):up()*15)
                #MoveMultZ=clamp(MoveMultZ+15,-MoveMultZLimit,MoveMultZLimit)
            } elseif (E:pos():z()>1425) {
                holoPos(1,E:pos()-holoEntity(1):up()*15)
                #MoveMultZ=clamp(MoveMultZ-15,-MoveMultZLimit,MoveMultZLimit)
            } else {
                holoAng(1,(E:pos()-BringTaget:pos()):toAngle():setPitch(0))
                if (E:pos():x()<BringTaget:pos():x()-5) {
                    holoPos(1,E:pos()+holoEntity(1):forward()*15)
                    #MoveMultX=clamp(MoveMultX+15,-MoveMultXLimit,MoveMultXLimit)
                } elseif (E:pos():x()>BringTaget:pos():x()+5) {
                    holoPos(1,E:pos()-holoEntity(1):forward()*15)
                    #MoveMultX=clamp(MoveMultX-15,-MoveMultXLimit,MoveMultXLimit)
                }
            }
        }
    }
    #holoPos(1,E:pos()+holoEntity(1):forward()*MoveMultX+holoEntity(1):right()*MoveMultY+holoEntity(1):up()*MoveMultZ)
]#
}
if (LightRay) {
    if (A>26) {
        Light:setAlpha(((31-A)/5)*255)
        A=clamp(A-0.1,26,31)
        clip(1,2,-A,ang(-90,0,0))
    } else {
        if (!Target) {
            R=rangerOffset(10^15,holoEntity(31):pos(),-holoEntity(31):up())
            findIncludeClass("player")
            findInSphere(R:pos(),10)
            if (find()) {
                if (BringTaget) {
                    if (find()==BringTaget) {
                        Target=BringTaget
                    }
                } else {
                    Target=find()
                }
            }
        }
        holoScale(32,vec(1,1,holoEntity(31):pos():distance(holoEntity(33):pos())/450))
    }
    if (Target) {
        if ((holoEntity(33):pos():z()-holoEntity(31):pos():z())<-50) {
            holoPos(33,vec(holoEntity(31):pos():x(),holoEntity(31):pos():y(),holoEntity(33):pos():z()+5))
        } elseif ((holoEntity(33):pos():z()-holoEntity(31):pos():z())>-45) {
            holoPos(33,vec(holoEntity(31):pos():x(),holoEntity(31):pos():y(),holoEntity(33):pos():z()-5))
        } else {
            holoPos(33,vec(holoEntity(31):pos():x(),holoEntity(31):pos():y(),holoEntity(33):pos():z()))
        }
        Target:setPos(holoEntity(33):pos())
    } else {
        R=rangerOffset(10^15,holoEntity(31):pos(),-holoEntity(31):up())
        holoPos(33,R:pos())
    }
} else {
    if (Target) {
        Target=noentity()
    }
    if (A<31) {
        #Light:setAlpha(((31-A)/5)*255)
        holoAlpha(32,0)
        holoDisableShading(31,0)
        A=clamp(A+0.1,26,31)
        clip(1,2,-A,ang(-90,0,0))
        soundVolume("LightRay",0)
        soundVolume("LightRay2",0)
    }
}
if (A==26&&changed(A==26)) {
        #[if (!Light) {
            Light=holoEntity(30):drawSprite("sprites/light_glow01",holoEntity(30):pos()-vec(0,0,20),Color,0,500,500)
        }]#
        holoAlpha(32,255)
        holoDisableShading(31,1)
        soundVolume("LightRay",1)
        soundVolume("LightRay2",1)
        soundStop("LightRayOn")
        holoEntity(33):soundPlay("LightRayOn",3,"ambient/outro/advisorattack03.wav")
        soundStop("LightRayOn2")
        holoEntity(31):soundPlay("LightRayOn2",3,"ambient/outro/advisorattack03.wav")
    }
