@name Airboat Tank! 2.0
@persist [E I J M Max R T Q Z]:number [V S]:entity [B Y H Hit W]:array [C Gravity]:vector
if(dsClk()){
    if(dsClk("DroneDamage")){
        if(dsGetEntity()==V){
            V:applyOffsetForce(vec(0,0,1)*V:mass()*150,V:pos()+V:right()*(random()>0.5 ? 10 : -10))
            TempCheck=1
            J-=randint(5,10)
        }
    }
    if(dsClk("TankDamage")){
        TempVec=dsGetVector()
        TempD=V:pos():distance(TempVec)
        if(TempD<300){
            V:applyOffsetForce(V:mass()*(V:pos()-TempVec)*(300-TempD)*0.01,TempVec)
            TempCheck=1
            J-=floor((300-TempD)/6)
        }
    }
    if(dsClk("NukeDamage")){
        TempVec=dsGetVector()
        TempD=V:pos():distance(TempVec)
        if(TempD<1000){
            V:applyOffsetForce(V:mass()*(V:pos()-TempVec)*(1000-TempD)*0.01,TempVec)
            TempCheck=1
            J-=ceil((1000-TempD)*0.2)
        }
    }
}elseif(tickClk()){
    if(J>0){
        T--
        R--
        if(T>0){
            holoAlpha(12,T*5.1)
            holoScale(12,vec(1.2,1.2,10-(T/5)))
        }else{
            holoAlpha(12,0)
            holoScale(12,vec(1.2,1.2,0))
        }
        D=V:driver()
        if(D){
            TempAng=ang(0,D:eyeAngles():yaw()+90,clamp(D:eyeAngles():pitch()+90,50,96))
            holoAng(10,TempAng)
            if(Z){
                if(!D:keyAttack1()){
                    Z=0
                }
            }elseif(D:keyAttack1()){
                Z=1
                if(R<=0){
                    T=50
                    R=150
                    G=S:pos()
                    TempHolo=holoCreate(-I,G,vec(1,1,1),ang(),vec(10,10,10),"hqicosphere2")
                    Y[I,vector]=TempAng:up()*E
                    H[I,number]=100
                    Hit[I,number]=1
                    W[I,number]=0
                    TempHolo:setTrails(10,0,1,"trails/smoke",vec(),255)
                    B[I,entity]=TempHolo
                    holoMaterial(-I,"models/shiny")
                    if(Max<M){
                        Max++
                    }
                    S:soundPlay("Shooting"+I,0,"^weapons/explode4.wav")
                    I++
                    if(I>M){
                        I=1
                    }
                }
            }
        }else{
            holoAng(10,V:angles()-ang(0,0,90))
            T=0
            for(X=1,Q){
                TempP=entity(Q)
                if(TempP){
                    if(TempP:weapon():type()=="weapon_crowbar"){
                        if(TempP:keyAttack1()){
                            if(TempP:aimEntity()==V){
                                if(TempP:shootPos():distance(TempP:aimPos())<=75){
                                    J=clamp(J+0.1,0,100)
                                    TempCheck=1
                                }
                            }
                        }
                    }
                }
            }
        }
        for(X=1,Max){
            TempNum=W[X,number]
            if(TempNum){
                if(TempNum>100){
                    holoClipEnabled(-X,0)
                    holoDelete(-X)
                    B[X,entity]:setTrails(10,0,1,"trails/smoke",vec(),0)
                    W[X,number]=0
                }else{
                    TempNum=TempNum+1
                    TempNum2=sin(TempNum*0.9)*50
                    TempNum3=cos(TempNum*0.9)
                    holoScale(-X,vec(TempNum2,TempNum2,TempNum2))
                    holoAlpha(-X,TempNum3*255)
                    holoAng(-X,ang(TempNum*6,TempNum2*10,TempNum*2))
                    W[X,number]=TempNum
                }
            }elseif(Hit[X,number]){
                TempPos=B[X,entity]:pos()
                TempVec=(Y[X,vector]-Gravity)*0.999
                TempR=rangerOffset(TempPos,TempPos+TempVec)
                if(TempR:hit()&TempR:entity()!=V){
                    Hit[X,number]=0
                    holoClip(-X,TempR:position(),TempR:hitNormal(),1)
                    holoClipEnabled(-X,1)
                    holoMaterial(-X,"models/effects/splode_sheet")
                    holoColor(-X,vec(255,255,255))
                    TempHoloEnt=B[X,entity]
                    dsSend("TankDamage","SGCombatSystem",2,TempR:position())
                    TempHoloEnt:soundPlay("Splosion"+I,0,"^weapons/explode2.wav")
                    soundVolume("Splosion"+I,10)
                    W[X,number]=1
                }else{
                    holoPos(-X,TempPos+TempVec)
                    Y[X,vector]=TempVec
                }
            }
        }
    }else{
        T++
        Temp=sin(T)
        TempC=cos(T)*255
        TempV=vec(14,14,14)+vec(Temp,Temp,Temp)*36
        TempA=ang(Temp*50,TempC*30,T*80)
        holoScale(1,TempV)
        holoScale(2,-TempV)
        holoAlpha(1,TempC)
        holoAlpha(2,TempC)
        holoAng(1,TempA)
        holoAng(2,-TempA)
        if(T>=90){
            selfDestructAll()
        }
    }
}elseif(first()){
    Chip=entity()
    if(Chip:isWeldedTo():model()=="models/airboat.mdl"){
        V=Chip:isWeldedTo()
        if(V:isVehicle()){
            if(V:owner()==owner()){
                TempCol=V:getColor()
                if(TempCol:x()==255){
                    TempNumG=TempCol:y()
                    if(TempNumG==TempCol:z()){
                        J=TempNumG/2.55
                        V:setAlpha(0)
                    }else{
                        J=100
                        V:setColor(255,255,255,0)
                    }
                }else{
                    J=100
                    V:setColor(255,255,255,0)
                }
                I=1
                E=60
                Gravity=vec(0,0,0.75)
                Chip:setAlpha(0)
                V:setAlpha(0)
                runOnTick(1)
                runOnLast(1)
                C=vec(25,150,25)
                A=V:angles()
                A2=ang(A:roll(),A:yaw(),-A:pitch())
                P=V:pos()
                F=ang(45,90,0):forward()
                holoCreate(1,P+vec(0,0,18):rotate(A),vec(5,10,2.5),A,C,"cube")
                holoCreate(2,P+vec(42,0,15):rotate(A),vec(2,11,3),A,C,"cube")
                holoCreate(3,P+vec(-42,0,15):rotate(A),vec(2,11,3),A,C,"cube")
                holoCreate(4,P+vec(42,66,15):rotate(A),vec(2,2.14,2.14),A+ang(0,0,45),C,"cube")
                holoClip(4,vec(),F,0)
                holoClipEnabled(4,1)
                holoCreate(5,P+vec(-42,66,15):rotate(A),vec(2,2.14,2.14),A+ang(0,0,45),C,"cube")
                holoClip(5,vec(),F,0)
                holoCreate(6,P+vec(42,-66,15):rotate(A),vec(2,2.14,2.14),A+ang(0,0,45),C,"cube")
                holoClip(6,vec(),-F,0)
                holoClipEnabled(6,1)
                holoCreate(7,P+vec(-42,-66,15):rotate(A),vec(2,2.14,2.14),A+ang(0,0,45),C,"cube")
                holoClip(7,vec(),-F,0)
                holoClipEnabled(7,1)
                holoCreate(8,P+vec(0,0,45):rotate(A),vec(6,6,3.5),A,C,"hqcylinder2")
                holoClip(8,vec(0,0,15),vec(0,0,-1),0)
                holoClipEnabled(8,1)
                holoCreate(9,P+vec(0,0,58):rotate(A),vec(6,6,3),A,C,"hqicosphere2")
                holoCreate(10,P+vec(0,0,48):rotate(A),vec(1,1,20),A+ang(0,0,90),C,"hqcylinder2")
                holoClip(10,vec(),vec(0,0,1),0)
                holoClipEnabled(10,1)
                for(X=1,10){
                    holoParent(X,V)
                    holoMaterial(X,"models/props_c17/FurnitureMetal001a")
                }
                S=holoCreate(11,P+vec(0,-126,48):rotate(A),vec(1.3,1.3,1),A+ang(0,0,90),C,"hqcylinder2")
                holoMaterial(11,"models/props_c17/FurnitureMetal001a")
                holoCreate(12,P+vec(0,-132,48):rotate(A),vec(1.2,1.2,10),A+ang(0,0,90),vec(255,255,255),"hqicosphere2")
                holoMaterial(12,"models/props_foliage/tree_deciduous_01a_trunk")
                holoClip(12,vec(),A:up(),0)
                holoClipEnabled(12,1)
                holoAlpha(12,0)
                for(X=11,12){
                    holoParent(X,10)
                }
                M=max(holoRemainingSpawns(),5)
                dsJoinGroup("SGCombatSystem")
                dsSetScope(2)
                Q=maxPlayers()
                TempCheck=1
            }else{
                printColor(vec(255,255,255)," -[ ",vec(255,0,0),"You must own the airboat",vec(255,255,255)," ]-")
                selfDestruct()
            }
        }else{
            printColor(vec(255,255,255)," -[ ",vec(255,0,0),"Spawn the airboat from 'Vehicles' not 'Props'",vec(255,255,255)," ]-")
            selfDestruct()
        }
    }else{
        printColor(vec(255,255,255)," -[ ",vec(255,0,0),"Requires an Airboat",vec(255,255,255)," ]-")
        selfDestruct()
    }
}elseif(last()){
    holoDeleteAll()
    V:setAlpha(255)
}
if(TempCheck){
    TempCheck=0
    if(J>0){
        TempC=sin(J*0.9)
        for(X=1,11){
            holoColor(X,C*TempC)
        }
        TempC=J*2.55
        V:setColor(255,TempC,TempC)
    }else{
        V:setColor(255,0,0,0)
        holoDeleteAll()
        V:killPod()
        V:lockPod(1)
        V:soundPlay("Splosion"+I,0,"^weapons/explode2.wav")
        dsLeaveGroup("SGCombatSystem")
        T=0
        for(X=1,2){
            holoCreate(X,V:pos(),vec(),ang(),vec(255,255,255),"hqicosphere2")
            holoMaterial(X,"models/effects/splode_sheet")
        }
    }
}
