Make Enemies Respawn

Started by Atrex, April 30, 2014, 06:44:49 PM

Previous topic - Next topic

Atrex

This script will make enemy structures within the specified range of the CRPL tower respawn when killed. All enemies will create an emitter on death, and you can set the power and interval of this emitter. SpawnRange controls how far from the dead unit the new one can spawn. Also, this script will not work well with moving enemies. If anything moves, the script will think it was destroyed.
# NewRespawn.crpl
# Created on: 4/29/2014 7:08:45 PM
# ------------------------------------------
$boostNumChance:0.2
$power:25
$interval:10
$range:200
$spawnRange:20

once
GetEnemyUnitsInRange(CurrentCoords <-range) ->total
CreateList ->enemies
<-enemies AppendStackToList
CreateList ->enemyX
CreateList ->enemyY
<-enemies GetListCount 0 do
<-enemyX <-enemies I GetListElement CONST_COORDX GetUnitAttribute AppendToList
<-enemyY <-enemies I GetListElement CONST_COORDY GetUnitAttribute AppendToList
loop
endonce
<-enemies GetListCount 0 do
<-enemyX I GetListElement <-enemyY I GetListElement GetUnitAt GetUnitType "POWERZONE" eq if
  CreateUnit("EMITTER" RandCoordsInRange(<-enemyX I GetListElement <-enemyY I GetListElement <-spawnRange)) ->child
  SetScriptVar(<-child 0 "productionInterval" <-interval)
  SetScriptVar(<-child 0 "productionAmt" <-power 1000000 mul)
  <-enemies I <-child SetListElement
  <-enemyX I <-child CONST_COORDX GetUnitAttribute SetListElement
  <-enemyY I <-child CONST_COORDY GetUnitAttribute SetListElement
  randfloat <-boostNumChance lt if
     CreateUnit("EMITTER" RandCoordsInRange(CurrentCoords <-spawnRange)) ->child
     SetScriptVar(<-child 0 "productionInterval" <-interval)
     SetScriptVar(<-child 0 "productionAmt" <-power 1000000 mul)
     <-enemies <-child AppendToList
     <-enemyX <-child CONST_COORDX GetUnitAttribute AppendToList
     <-enemyY <-child CONST_COORDY GetUnitAttribute AppendToList
  endif
endif
loop

Michionlion

One should use the [code] tags to encase CRPL.  Otherwise, looks cool.[/code]
"Remember kids, the only difference between science and messing around is writing it down."
                                                                                                                         - Adam Savage

My website
My CW1, and CW2 maps!

ZackNAttack

Quote from: Atrex on April 30, 2014, 06:44:49 PM
This script will make enemy structures within the specified range of the CRPL tower respawn when killed. All enemies will create an emitter on death, and you can set the power and interval of this emitter. SpawnRange controls how far from the dead unit the new one can spawn. Also, this script will not work well with moving enemies. If anything moves, the script will think it was destroyed.
# NewRespawn.crpl
# Created on: 4/29/2014 7:08:45 PM
# ------------------------------------------
$boostNumChance:0.2
$power:25
$interval:10
$range:200
$spawnRange:20

once
GetEnemyUnitsInRange(CurrentCoords <-range) ->total
CreateList ->enemies
<-enemies AppendStackToList
CreateList ->enemyX
CreateList ->enemyY
<-enemies GetListCount 0 do
<-enemyX <-enemies I GetListElement CONST_COORDX GetUnitAttribute AppendToList
<-enemyY <-enemies I GetListElement CONST_COORDY GetUnitAttribute AppendToList
loop
endonce
<-enemies GetListCount 0 do
<-enemyX I GetListElement <-enemyY I GetListElement GetUnitAt GetUnitType "POWERZONE" eq if
  CreateUnit("EMITTER" RandCoordsInRange(<-enemyX I GetListElement <-enemyY I GetListElement <-spawnRange)) ->child
  SetScriptVar(<-child 0 "productionInterval" <-interval)
  SetScriptVar(<-child 0 "productionAmt" <-power 1000000 mul)
  <-enemies I <-child SetListElement
  <-enemyX I <-child CONST_COORDX GetUnitAttribute SetListElement
  <-enemyY I <-child CONST_COORDY GetUnitAttribute SetListElement
  randfloat <-boostNumChance lt if
     CreateUnit("EMITTER" RandCoordsInRange(CurrentCoords <-spawnRange)) ->child
     SetScriptVar(<-child 0 "productionInterval" <-interval)
     SetScriptVar(<-child 0 "productionAmt" <-power 1000000 mul)
     <-enemies <-child AppendToList
     <-enemyX <-child CONST_COORDX GetUnitAttribute AppendToList
     <-enemyY <-child CONST_COORDY GetUnitAttribute AppendToList
  endif
endif
loop

To fix the moving error, use :destroyed
Zack on cw3

Lost in Nowhere

The only thing is is that :destroyed is only called when the tower with the script is destroyed, so that wouldn't work...
Don't die! :)

Annonymus

To fix the problem with moving enemies the script of the moving unit would have to be modified, either by using :destroyed or by telling the re-spawner it's alive every time it moves.
If a topic started by me is in the wrong place feel free to move it at anytime.

Mikoz

Don't save CONST_COORDX and CONST_COORDY to separate lists. If you use list of unit ID's to receive them each time, then it will work with moving units as well.
Or just check CONST_ISDESTROYED instead of position.