Help with destroying excess units when compiling.

Started by bluebolt, October 30, 2017, 10:54:28 PM

Previous topic - Next topic

bluebolt

SO my code used to have a nasty habit of making the beam this creates go into a weird position. The test I sued used a -1 for default particle UID(listed under target). I replaced it with a 1 and it works now, but I don't think it's the best way to go about with deleting the beam when no particle exists, when I hit compile. Looking at the top part. And yes i started making this code several months ago PRPL
And sorry I'm not in a habit of commenting all over the place... working on it though xd
# --Beam-- 12/23/2016 2:33:12 PM

$Duration:5
$R:255
$G:255
$B:255
$target:1
$x:0
$y:0
$low:155
#possable weapon sounds: Weapon::28,29,31,5,6,9,12,13,14 Retro:7,8,9,18 Misc: 10,12,17,19,25
once
Self ->beam
1 ->timer
1 ->timerUp
endonce

@follow
if(<-target ParticleExists)

else
Self 0 DestroyUnit
endif
@animate
:follow
"Misc12" .7 PlaySoundWithVolume
<-target GetParticlePosition ->py ->px
<-py <-y sub <-px <-x sub atan2 ->targetAngle
<-px ->beam.UnitPixelCoordX
<-py ->beam.UnitPixelCoordY
Self "main" <-x <-y <-px <-py Distance 12 div 1 SetImageScale
Self "anim" <-x <-y <-px <-py Distance 12 div 1 SetImageScale
Self "main" <-targetAngle SetImageRotation
Self "anim" <-targetAngle SetImageRotation
Self "main" "Ships" SetImageLayer
Self "main" 3 SetImageOrder
Self "main" <-x <-px sub 2 div <-y <-py sub 2 div -0.025 SetImagePosition
Self "anim" <-x <-px sub 2 div <-y <-py sub 2 div -0.025 SetImagePosition
:animate #should make the background beam part fluctuate in size
#5 <-Duration div || find how much the scale should change per frame
Self "anim" .6 <-Duration div(asFloat) <-timer mul .8 add SetImageScaleY #.6 is the default value, or minimum scale
if(<-timer <-Duration gte)
0 ->timerUp
else
if(<-timer 0 lte)
1 ->timerUp
endif
endif
if(<-timerUp)
<-timer 1 add ->timer
else
<-timer 1 sub ->timer
endif
:awake
0 OperateWhilePaused

And the actual turret itself
# --Beam Turret-- 12/23/2016 11:22:30 AM
$range:120
$isEnemy:0
$reload:3
$damage:1
$cooldown:0 #also initial delay
$affectedByMire:1 #0 if not on land/on unmirable land, reduces cpu usage(probabbly not needed)
$Uwidth:5 #cells
$Uheight:5 #cells

once
0 ->OVERMIREcreated
Self "main" "Custom0" SetImage
Self "main" "Ships" SetImageLayer
Self "main" 1 SetImageOrder
Self "main" 1.5 1.5 SetImageScale
-1 ->beam
-1 ->target
endonce
CurrentPixelCoords ->y ->x
@isMired
if(<-IsMired 0 eq)
if(<-cooldown 0 eq)
if(<-targeting)
if(<-target GetParticlePosition <-x <-y Distance <-range gt)
0 ->targeting
<-beam 0 DestroyUnit
-1 ->beam
endif
endif
if(<-targeting eq0)
@findTarget
endif
if(<-target -1 neq)
1 ->targeting

if(<-target ParticleExists)

<-target getParticlePosition ->py ->px
<-py <-y sub <-px <-x sub atan2 ->targetAngle
if(<-beam -1 eq)
"PRPLCORE" 0 0 CreateUnit ->beam
<-px ->beam.UnitPixelCoordX
<-py ->beam.UnitPixelCoordY
<-beam "Beam.prpl" AddScriptToUnit
<-beam "Beam.prpl" "Duration" 5 SetScriptVar

<-beam "Beam.prpl" "target" <-target SetScriptVar
<-beam "Beam.prpl" "x" <-x SetScriptVar
<-beam "Beam.prpl" "y" <-y SetScriptVar

<-beam "main" "Custom1" SetImage
<-beam "anim" "Custom2" SetImage
if(<-isEnemy 0 eq)
<-beam "anim" 0 255 255 255 SetImageColor
else
<-beam "anim" 255 0 0 255 SetImageColor
endif
<-beam "main" <-x <-y <-px <-py Distance 12 div 1 SetImageScale
<-beam "anim" <-x <-y <-px <-py Distance 12 div 1 SetImageScale
<-beam "main" <-targetAngle SetImageRotation
<-beam "anim" <-targetAngle SetImageRotation
<-beam "main" "Ships" SetImageLayer
<-beam "main" 3 SetImageOrder
<-beam "anim" "Ships" SetImageLayer
<-beam "anim" 1 SetImageOrder
<-beam "main" <-x <-px sub 2 div <-y <-py sub 2 div -0.025 SetImagePosition
<-beam "anim" <-x <-px sub 2 div <-y <-py sub 2 div -0.025 SetImagePosition
<-reload SetTimer0
endif
if(GetTimer0 eq0)
if(<-target.particleHealth <-damage gt)
<-target.particleHealth <-damage sub ->target.particlehealth

<-reload ->cooldown
else
if(<-target GetParticleHealth <-damage lte)
<-target 0 DestroyParticle
<-beam 0 DestroyUnit
-1 ->beam
-1 ->target
0 ->targeting
endif
endif
endif
else
<-beam 0 DestroyUnit
-1 ->beam
-1 ->target
0 ->targeting
endif
endif
else
<-cooldown 1 sub ->cooldown
endif
endif


:isMired
CurrentCoords ->Cy ->Cx
0 ->IsMired
Self GetUnitCoords ->UCoordy ->UCoordx
do(<-Uwidth 0)
i <-Uwidth 2 div 0 round sub ->UWidth #x value in relation to center(0,0)
do(<-Uheight 0)
i <-Uheight 2 div 0 round sub ->UHeight #y value in relation to center(0,0)
<-UCoordx <-UWidth add ->tempUCoordx
<-UCoordy <-UHeight add ->tempUCoordy
if(<-affectedByMire)
<-tempUCoordx <-tempUCoordy GetMire ->mire
if(<-isEnemy)
if(<-mire -1 eq)
1 ->IsMired
endif
else
if(<-mire 1 eq)
1 ->IsMired
endif
endif
endif
loop
loop

if(<-IsMired)
if(<-OVERMIREcreated eq0)
"PRPLCORE" <-Cx <-Cy 1 add CreateUnit ->OVERMIRE
<-OVERMIRE "main" "Custom0_256" SetImage
<-OVERMIRE "main" 3 3 SetImageScale
1 ->OVERMIREcreated
endif
if(<-beam -1 neq)
<-beam 0 DestroyUnit
-1 ->beam
endif
else
if(<-OVERMIREcreated)
<-OVERMIRE 0 DestroyUnit
0 ->OVERMIREcreated
endif
endif


:findTarget
CurrentPixelCoords ->y ->x
-1 ->target
if(<-isEnemy)
CurrentCoords <-range 1 0 GetParticlesInRange ->particles
<-range ->nearest
do(<-particles GetListCount 0)
<-particles[I] ->p
if(<-p GetParticlePosition <-x <-y Distance <-nearest lt)
<-p GetParticlePosition <-x <-y Distance ->nearest
endif
if(<-p GetParticlePosition <-x <-y Distance <-nearest eq)
<-p ->target
endif
loop
else
CurrentCoords <-range 1 1 GetParticlesInRange ->particles
<-range ->nearest
do(<-particles GetListCount 0)
<-particles[I] ->p
if(<-p GetParticlePosition <-x <-y Distance <-nearest lt)
<-p GetParticlePosition <-x <-y Distance ->nearest
endif
if(<-p GetParticlePosition <-x <-y Distance <-nearest eq)
<-p ->target
endif
loop
endif
Even YOU may survive an apocalypse! Fight back against the creeper today!

FOXX

The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS