@name Explosive Multi Puck
@inputs Disable
@outputs Mul F:vector Explode Alive Zenith Home Kill Event Self
@persist Explode InRange Explode1 Event Counted Count Self
interval(20)
gSetGroup("EMP")

#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")
TargEnt = gGetNum("TargEnt")
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)

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())

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 (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!
SelfVel = entity():vel()
SelfPos = entity():pos()
T = 0.015 M = 402 K = 10 ThrK = 50
Dx = X - SelfPos:x() Dy=Y - SelfPos:y() Dz = Z - SelfPos:z()
Fx = -M / T / ThrK * (Dx * K - SelfVel:x())
Fy = -M / T / ThrK * (Dy * K - SelfVel:y())
Fz = -M / T / ThrK * (Dz * K - SelfVel:z())
F = vec(Fx,Fy,Fz)
Mul = sqrt(Fx^2 + Fy^2 + Fz^2)
#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)
}
