@name 4 Team CTF
#@inputs On1 On2 On3 On4 
#@inputs T1:entity T2:entity T3:entity T4:entity
#@inputs T1a T2a T3a T4a
#@outputs E1:entity E2:entity E3:entity E4:entity
#@outputs N1 N2 N3 N4 T1a T2a T3a T4a 
@outputs Blue:vector Red:vector Green:vector Yellow:vector
@persist 
@persist K Xd1 Yd1 Zd1 P1a P2a P3a N1 N2 N3 N4
@persist Xd2 Yd2 Zd2 P1b P2b P3b
@persist Xd3 Yd3 Zd3 P1c P2c P3c
@persist Xd4 Yd4 Zd4 P1d P2d P3d
@persist XYZ1:vector XYZ2:vector XYZ3:vector XYZ4:vector
interval(1)
gSetGroup("CTF")
Zoff = 100
Model = "models/Roller.mdl"
findInSphere(entity():pos(),100000)
findIncludePlayerProps(entity():owner())
findClipToModel(Model)
E1 = findResult(1)
E2 = findResult(2)
E3 = findResult(3)
E4 = findResult(4)
N1 = E1:id()
N2 = E2:id()
N3 = E3:id()
N4 = E4:id()
T1a = gDeleteNum("T1a")
T2a = gDeleteNum("T2a")
T3a = gDeleteNum("T3a")
T4a = gDeleteNum("T4a")
T1 = entity(T1a)
T2 = entity(T2a)
T3 = entity(T3a)
T4 = entity(T4a)
entity():setColor(0,255,255)
if (T1:id()!=0) {XYZ1 = T1:pos() On1 = 1} else {On1 = 0}
if (T2:id()!=0) {XYZ2 = T2:pos() On2 = 1} else {On2 = 0}
if (T3:id()!=0) {XYZ3 = T3:pos() On3 = 1} else {On3 = 0}
if (T4:id()!=0) {XYZ4 = T4:pos() On4 = 1} else {On4 = 0}

gSetNum("N1",N1)
gSetNum("N2",N2)
gSetNum("N3",N3)
gSetNum("N4",N4)


K=10

#green 65,163,0  Red 255,0,0 Blue 0,0,255 yellow 255,255,0
#Material is building_template010a
#model is roller mine "ragdoll" 
Material = "building_template010a"
if (On1) {
M1=entity(N1):mass()
Tar1 = entity(N1)
X1 = XYZ1:x()
Y1 = XYZ1:y()
Z1 = XYZ1:z()
Tar1:setColor(0,0,255)
Xd1 = X1-Tar1:pos():x()
Yd1 = Y1-Tar1:pos():y()
Zd1 = Z1-Tar1:pos():z()+Zoff

P1a = (K*Xd1-Tar1:vel():x())*M1
P2a = (K*Yd1-Tar1:vel():y())*M1
P3a = (K*Zd1-Tar1:vel():z())*M1
Tar1:applyForce(vec(P1a,P2a,P3a))
Tar1:setMaterial(Material)
}
if (On2) {
M2=entity(N2):mass()
Tar2 = entity(N2)
X2 = XYZ2:x()
Y2 = XYZ2:y()
Z2 = XYZ2:z()
Tar2:setColor(255,0,0)
Xd2 = X2-Tar2:pos():x()
Yd2 = Y2-Tar2:pos():y()
Zd2 = Z2-Tar2:pos():z()+Zoff

P1b = (K*Xd2-Tar2:vel():x())*M2
P2b = (K*Yd2-Tar2:vel():y())*M2
P3b = (K*Zd2-Tar2:vel():z())*M2
Tar2:applyForce(vec(P1b,P2b,P3b))
Tar2:setMaterial(Material)
}



if (On3) {

M3=entity(N3):mass()
Tar3 = entity(N3)
X3 = XYZ3:x()
Y3 = XYZ3:y()
Z3 = XYZ3:z()
Tar3:setColor(65,163,0)
Xd3 = X3-Tar3:pos():x()
Yd3 = Y3-Tar3:pos():y()
Zd3 = Z3-Tar3:pos():z()+Zoff

P1c = (K*Xd3-Tar3:vel():x())*M3
P2c = (K*Yd3-Tar3:vel():y())*M3
P3c = (K*Zd3-Tar3:vel():z())*M3
Tar3:applyForce(vec(P1c,P2c,P3c))
Tar3:setMaterial(Material)
}

if (On4) {

M4=entity(N4):mass()
Tar4 = entity(N4)
X4 = XYZ4:x()
Y4 = XYZ4:y()
Z4 = XYZ4:z()
Tar4:setColor(255,255,0)
Xd4 = X4-Tar4:pos():x()
Yd4 = Y4-Tar4:pos():y()
Zd4 = Z4-Tar4:pos():z()+Zoff

P1d = (K*Xd4-Tar4:vel():x())*M4
P2d = (K*Yd4-Tar4:vel():y())*M4
P3d = (K*Zd4-Tar4:vel():z())*M4
Tar4:applyForce(vec(P1d,P2d,P3d))
Tar4:setMaterial(Material)
}
