@name Loud Music [##AMMUT##]
@model models/hunter/misc/sphere025x025.mdl
@inputs V:vector
@persist PortO PortB Active [PortalPlaceSound PortalExitSound]:string
@persist H1:entity Blast Shoot Dist Boom Mouse2 Hull 
@persist Q:vector Bum Nose Flame T Ready Use AutoAim Ee:entity
@persist Idle Ent:entity
if(first()){
Ent:setMaterial("models/props/cs_office/snowmana")
Ent:setColor(239,232,232,255)
Ent:setTrails(7, 25.6, 5, "none", Ent:getColor(), 255)
}
Chip = entity()
    PortalPlaceSound="weapons/physcannon/energy_bounce1.wav"
    PortalExitSound="weapons/physcannon/energy_bounce2.wav"
    PortO=123456
    PortB=234567
holoCreate(0)
holoModel(0,"models/hunter/misc/sphere025x025.mdl")
holoScale(0,vec(1.1,1.1,1.1))
holoColor(0,vec(255,255,255))
holoPos(0,Chip:pos()+vec(0,0,0))
holoMaterial(0,"models/alyx/emptool_glow")
holoParent(0,Chip)


soundPlay(1,0,"")
soundVolume(1,99999)

    E=entity()
    O=owner()
if(tickClk()){
    ##############################
    if(->V){
        Target=V
    }else{
        if(!O:keyUse()){
        Target=O:shootPos()+vec(0,0,100) # Above the owner's head.
    }elseif(O:keyUse()){
    Target=O:aimPos()+vec(0,0,50) # Above where the owner is looking.
}
}
    E:applyForce(((Target-E:pos())*10-E:vel())*E:mass()) #<-- makes E go to Target
    ##############################
}elseif(first()){
    E=entity()
    O=owner()
    runOnTick(1)
}

                #STABILISE
                TarQ = quat(O:eyeAngles()+ang(90,0,90)) #Calculate quaternion for target orientation
                CurQ = quat(E) #Calculate current orientation quaternion
                
                #TarQ/CurQ is a quaternion representing the rotation that will rotate the object from current orientation to the target one.
                Z = TarQ/CurQ
                
                #applyTorque() works on intrinsic vectors! Get the rotation vector and transform it.
                EP=E:pos()
                TTV = E:toLocal(rotationVector(Z)+EP)
                #Alternatively, can use "V = transpose(matrix(E))*rotationVector(Q)"
                
                #Apply torque. angVelVector() works like a delta term.
                #Factors 150 and 12 can be adjusted to achieve best effect.
                E:applyTorque((150*TTV - 12*E:angVelVector())*E:inertia())

interval(10)
if(first()|duped()){
    PortalPlaceSound="weapons/physcannon/energy_bounce1.wav"
    PortalExitSound="weapons/physcannon/energy_bounce2.wav"
    PortO=123456
    PortB=234567
    holoCreate(PortO)
    holoModel(PortO,"hqtorus2")
    holoColor(PortO,vec(255,100,0))
    holoScale(PortO,vec(7,4,1))
   # holoMaterial(PortO,"models/debug/debugwhite")
    holoCreate(PortB)
    holoModel(PortB,"hqtorus2")
    holoColor(PortB,vec(0,50,200))
    holoScale(PortB,vec(7,4,1))
   # holoMaterial(PortB,"models/debug/debugwhite")
    holoCreate(12)
    holoModel(12,"plane")
    holoScale(12,vec(8,4,1))
    holoMaterial(12,"models/effects/portalrift_sheet")
    holoAng(12,entity():angles()+ang(0,0,0))
    holoCreate(13)
    holoModel(13,"plane")
    holoScale(13,vec(8,4,1))
   holoMaterial(13,"models/effects/portalrift_sheet")
    holoAng(13,entity():angles()+ang(0,0,0))
    holoPos(12,entity():pos()+vec(0,0,1))
    holoPos(13,entity():pos()+vec(0,0,1))
    holoParent(12,PortO)
    holoParent(13,PortB)
    Active=0
    holoAlpha(PortO,0)
    holoAlpha(PortB,0)
    holoAlpha(12,0)
     holoAlpha(13,0)

    Base=450
    Base2=451
    Mid1=452
    Mid2=453
    Mid3=454
    Mid4=455
    Mid5=456
    Mid6=457
    End11=458
    End21=459
    End31=460
    End12=461
    End22=462
    End32=463
    End13=464
    End23=465
    End33=466
    End4=467
    End5=468
    End6=469
    BaseEnt=holoCreate(Base)
    #holoModel(Base,"hqicosphere2")
    #holoPos(Base,entity():pos()+vec(0,0,30))
    #holoScaleUnits(Base,vec(7,13,8))
    #holoClipEnabled(Base,1)
     Mid1Ent=holoCreate(Mid1)

Base2Ent=holoCreate(Base2)
    holoAng(Base2,BaseEnt:angles()+ang(180,0,-10))
    holoModel(Base2,"dome")
    holoPos(Base2,BaseEnt:toWorld(vec(0,-10,-1)))
    holoScaleUnits(Base2,vec(7,10,8))
    
  #  holoCreate(End11)
   # holoScaleUnits(End11,vec(0.5,0.5,5))
   # holoPos(End11,Mid1Ent:toWorld(vec(0,3,1)))
   # holoAng(End11,Mid1Ent:toWorld(ang(0,0,-45)))
   # holoColor(End11,vec(20,20,30))
    
   # holoCreate(End21)
    #holoScaleUnits(End21,vec(0.4,0.4,5))
   # holoPos(End21,Mid1Ent:toWorld(vec(0,4.4,4.2)))
   # holoAng(End21,Mid1Ent:toWorld(ang(0,0,0)))
   # holoColor(End21,vec(20,20,30))
    
    holoCreate(End31)
    holoModel(End31,"tetra")
    holoScaleUnits(End31,vec(1,1,4))
    holoPos(End31,Mid1Ent:toWorld(vec(0,4,7)))
    holoAng(End31,Mid1Ent:toWorld(ang(0,0,45)))
    holoColor(End31,vec(20,20,30))
    
      holoCreate(End32)
    holoModel(End32,"tetra")
    holoScaleUnits(End32,vec(1,1,4))
    holoPos(End32,Mid1Ent:toWorld(vec(0,6,9):rotate(0,115,0)))
    holoAng(End32,Mid1Ent:toWorld(ang(0,115,45)))
    holoColor(End32,vec(20,20,30))
    
    holoCreate(End13)
    holoScaleUnits(End13,vec(0.5,0.5,5))
    holoPos(End13,Mid1Ent:toWorld(vec(0,5,3):rotate(0,-115,0)))
    holoAng(End13,Mid1Ent:toWorld(ang(0,-115,-45)))
    holoColor(End13,vec(20,20,30))
      }
    holoPos(450,owner():attachmentPos("anim_attachment_rh"))
    holoAng(450,owner():attachmentAng("anim_attachment_rh"))
    holoPos(450,holoEntity(450):toWorld(vec(9.4,0,3)))
    holoAng(450,holoEntity(450):toWorld(ang(-12,70,0)))
    holoParentAttachment(450,owner(),"anim_attachment_rh")
    for(I=450,469){
        holoAlpha(I,0)
    }
#}
if((owner():weapon():type()=="weapon_physcannon")){
    for(X=450,469){
        holoAlpha(X,255)
    }
    owner():weapon():setMaterial("Models/effects/vol_light001")
}
else{
    for(I=450,469){
        holoAlpha(I,0)
    }
}
soundPitch(1,200)
if(Active){
    R1=rangerOffset(40,holoEntity(PortO):pos(),(vec(0,0,1)):rotate(holoEntity(PortO):angles()))
    R2=rangerOffset(40,holoEntity(PortB):pos(),(vec(0,0,1)):rotate(holoEntity(PortB):angles()))
    if(R1:hit()&R1:entity()){
        if(R1:entity():owner()==owner()){
            R1:entity():applyForce((-R1:entity():vel()):rotate(holoEntity(PortB):angles())*R1:entity():mass()*1.1)
        }

      
        Ar1=R1:entity():getConstraints()
        for(I=1,Ar1:count()){
         
        }
    }
    if(R2:hit()&R2:entity()){
        if(R2:entity():owner()==owner()){
            R2:entity():applyForce((-R2:entity():vel()):rotate(holoEntity(PortB):angles())*R2:entity():mass()*1.1)
        }
    

     
        Ar2=R2:entity():getConstraints()
        for(B=1,Ar2:count()){
         
        }
    }
}
if(owner():weapon():type()=="weapon_crowbar"){
    if(changed(owner():keyAttack1())&owner():keyAttack1()&owner():aimEntity():getColor()!=vec(1,1,1)){
        holoUnparent(PortO)
        holoPos(PortO,owner():aimPos())
        holoAng(PortO,owner():aimNormal():toAngle()+ang(90,0,0))
        holoEntity(PortO):soundPlay(1,0,PortalPlaceSound)
        Active=1
        if(owner():aimEntity()!=noentity()){
            holoParent(PortO,owner():aimEntity())
        }
        holoAlpha(PortO,255)
        holoAlpha(12,255)
    }
    if(changed(owner():keyAttack2())&owner():keyAttack2()&owner():aimEntity():getColor()!=vec(1,1,1)){
        holoUnparent(PortB)
        holoPos(PortB,owner():aimPos())
        holoAng(PortB,owner():aimNormal():toAngle()+ang(90,0,0))
        holoEntity(PortO):soundPlay(1,0,PortalPlaceSound)
        Active=1
        if(owner():aimEntity()!=noentity()){
            holoParent(PortB,owner():aimEntity())
        }
        holoAlpha(PortB,255)
        holoAlpha(13,255)
    }
}
if(owner():keyUse()&owner():keyAttack1()&owner():keyAttack2()&owner():weapon():type()=="weapon_physcannon"){
    Active=0
    holoAlpha(PortO,0)
    holoAlpha(PortB,0)
    holoAlpha(12,0)
    holoAlpha(13,0)
}

