@name Explosive Multi Puck
@inputs Disable
@outputs Explode Self
@persist Explode InRange Explode1 Event Counted Count Self K Xd Yd Zd P1 P2 P3
interval(1)
gSetGroup("EMP")
Self =3
#Pong Code
Ping1 = gGetNum("Ping1")
Ping2 = gGetNum("Ping2")
if (Ping1 | Ping2) {Pong = 1}
if (!Disable) {gSetNum("Pong",Pong)}
Count = gGetNum("Count")
if (!Counted) {Count += 1}
if (!Counted) {Counted = 1 Self = Count}
gSetNum("Count",Count)
#Pong Code End



BaseEnt = gGetNum("BaseEnt")
if (Self==1) {Chroma = vec(255,0,0)
setColor(Chroma:x(),Chroma:y(),Chroma:z())
TargEnt = gGetNum("TargEnt")

}
if (Self==2) {Chroma = vec(0,255,0)
setColor(Chroma:x(),Chroma:y(),Chroma:z())
TargEnt = gGetNum("TargEnt2")

}
if (Self==3) {Chroma = vec(0,0,255)
setColor(Chroma:x(),Chroma:y(),Chroma:z()) 
TargEnt = gGetNum("TargEnt3")

}
Active = gGetNum("Active")
Explode1 = gGetNum("Explode1")
MinDist = gGetNum("MinDist")

if (!Disable) {
Base = entity(BaseEnt):pos()
ZenX = Base:x() ZenY = Base:y() ZenZ = Base:z() +500
ZVec = vec(ZenX,ZenY,ZenZ)
RemZ = ZenZ + 1000 
RVec = vec(ZenX,ZenY,RemZ)
T1 = entity(TargEnt):pos() 
TX = T1:x() TY = T1:y() TZ = T1:z()

Distance = entity(TargEnt):pos():distance(entity():pos())
ZDist = ZVec:distance(entity():pos())
BDist = Base:distance(entity():pos())
RDist = RVec:distance(entity():pos())

Zenith = 20 > ZDist
Home = 100 > BDist

if (Home) {Event = 1}
if (Zenith) {Event = 2}
if (Event==1)  {Kill = 0 Zenith1 = 1}
if (Event==2)  {Kill = 1 Zenith1 = 0} 
if (TargEnt==0) {X = ZenX Y = ZenY Z = RemZ}
if (Zenith1) {X = ZenX Y = ZenY Z = ZenZ} elseif 
(Kill) {X = TX Y = TY Z = TZ}


if (Active) {

#This is the stuff that makes it fly! DO NOT TOUCH!
K=10
M=1

Xd = X-entity():pos():x()
Yd = Y-entity():pos():y()
Zd = Z-entity():pos():z()

P1 = (K*Xd-entity():vel():x())*M
P2 = (K*Yd-entity():vel():y())*M
P3 = (K*Zd-entity():vel():z())*M

applyForce(vec(P1,P2,P3))
#This is just controller stuff from here down Still working it out
if (Distance < MinDist) {InRange = 1} else {InRange = 0}
}
else {Mul = 0}
#Between Here and Start of Stuff the makes it fly is just controls
Explode = (InRange | Explode1)
}
