How to measure number of units?

Started by Clean0nion, October 29, 2013, 01:27:30 PM

Previous topic - Next topic

Clean0nion

Is there any way that I can measure the amount of a unit that a player has placed?

In context:
I want a spore tower to fire a number of spores that is four times the amount of reactors the player has placed.

knucracker

Something like this



if (<-fire)
   @GetUnitTypeCount("REACTOR") ->reactorCount
   #Do something based on reactorCount
endif

:GetUnitTypeCount
->unitType
0 ->count
do (GetUnitsInRange(0 0 9999) 0)
->unitUID
if (GetUnitType(<-unitUID) eq(<-unitType))
<-count add(1) ->count
endif
loop
<-count

MizInIA

Quote from: Clean0nion on October 29, 2013, 01:27:30 PM
I want a spore tower to fire a number of spores that is four times the amount of reactors the player has placed.

that is evil.  ;D

Lost in Nowhere

Quote from: MizInIA on October 30, 2013, 11:31:10 AM
Quote from: Clean0nion on October 29, 2013, 01:27:30 PM
I want a spore tower to fire a number of spores that is four times the amount of reactors the player has placed.

that is evil.  ;D

Doesn't that make it a good idea?
Don't die! :)

Clean0nion

Update: this plan won't work for spores. I now need them to fire an amount of spores that is the square of the number of the reactors.

Thanks, Virgil, for your script. I'll try to modify it but I don't even know what I'm doing with it or how to get it in the map.

Relli

#5
Quote from: Clean0nion on October 30, 2013, 06:08:36 PM
Update: this plan won't work for spores. I now need them to fire an amount of spores that is the square of the number of the reactors.

Thanks, Virgil, for your script. I'll try to modify it but I don't even know what I'm doing with it or how to get it in the map.

Edit: I should have read the other new posts before doing this. You already got your answer on getting your code into the game. I'll leave this up anyway, though. /EndEdit

As for getting that script into the game, go to the Projects section, create a world and go in, Edit Map, then in the Units tab there's a button called Scripts. In there, create a new script with whatever name you want, edit it (you may have to set this up the first time around), and then just copy/paste Virgil's code into it. It won't work right away though, because all he wrote is the code that counts reactors. It currently does nothing.

If you want or need, I can explain what all of the code he wrote does, and what other code you might need to make your spore tower work. Though in my opinion, it would be easier to talk this over in a faster chat. Don't want to clutter the topic with a bunch of short replies.

Lemme know if you want to try this, and how you'd want to go about it, if at all. I'll help however I can.

Clean0nion

Quote from: Riluna on October 30, 2013, 07:55:52 PM
Lemme know if you want to try this, and how you'd want to go about it, if at all. I'll help however I can.
Thanks for your offer. I've PMed you.

Lost in Nowhere

Quote from: Clean0nion on October 30, 2013, 06:08:36 PM
Update: this plan won't work for spores. I now need them to fire an amount of spores that is the square of the number of the reactors.

Thanks, Virgil, for your script. I'll try to modify it but I don't even know what I'm doing with it or how to get it in the map.

That wouldn't be too hard, just something like this:
if (<-fire)
   @GetUnitTypeCount("REACTOR") ->reactorCount
   <-reactorCount dup mul ->squaredReactorCount
   #Do something based on squaredReactorCount
endif

:GetUnitTypeCount
->unitType
0 ->count
do (GetUnitsInRange(0 0 9999) 0)
->unitUID
if (GetUnitType(<-unitUID) eq(<-unitType))
<-count add(1) ->count
endif
loop
<-count

It with spore-firing added in:
$Power:50 #Amount of creeper created
$Delay:1800
$FireDelay:6

#Code to determine what "fire" is

if (<-fire)
@GetUnitTypeCount("REACTOR") ->reactorCount
<-reactorCount dup mul ->squaredReactorCount
#Fire spores
<-Delay <-FireDelay <-squaredReactorCount mul sub Delay
<-squaredReactorCount 0 do
CurrentCoords RandUnitCoords <-Power 1 CreateSpore
<-FireDelay Delay
loop
endif


:GetUnitTypeCount
->unitType
0 ->count
do (GetUnitsInRange(0 0 9999) 0)
->unitUID
if (GetUnitType(<-unitUID) eq(<-unitType))
<-count add(1) ->count
endif
loop
<-count
Don't die! :)