• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

help...

Status
Not open for further replies.
Level 6
Joined
Oct 25, 2018
Messages
108
Hello, I need help with a map, in which I am creating waves of enemies. It happens that too many creeps accumulate to the point that it becomes impossible to play ... is there any way to put a limit of units for each wave? that is to say if every one minute I create 10 creeps, that attack a specific zone, having 40 creeps on the map, they will no longer be produced?
 

~El

Level 17
Joined
Jun 13, 2016
Messages
556
Here's a very trivial example of how you could do this. The condition is the primary part.

  • Melee Initialization
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
      • (Number of units in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Rifleman))) Less than 10
    • Actions
      • Unit - Create 1 Rifleman for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing degrees
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Hello, I need help with a map, in which I am creating waves of enemies. It happens that too many creeps accumulate to the point that it becomes impossible to play ... is there any way to put a limit of units for each wave? that is to say if every one minute I create 10 creeps, that attack a specific zone, having 40 creeps on the map, they will no longer be produced?
Yes there is a way.

Most simple would be to use food. One can then have a conditional test in the spawn trigger to check if current food is less than the produced food and only if so create the units.

Instead of food, like in the case that already has another use, one could use an integer variable.

Here's a very trivial example of how you could do this. The condition is the primary part.
Leaks a group, so not a good idea to use that trigger.
 
Level 6
Joined
Oct 25, 2018
Messages
108
Here's a very trivial example of how you could do this. The condition is the primary part.

  • Melee Initialization
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
      • (Number of units in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Rifleman))) Less than 10
    • Actions
      • Unit - Create 1 Rifleman for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing degrees

Is that an integer condition or multiple conditions?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
but I suggest that one, then the group object gets destroyed.
Problem is it leaks a handle ID due to the local declared local agent variable reference counter leak on return bug.

Here is the function showing the leak.
JASS:
function CountLivingPlayerUnitsOfTypeId takes integer unitId,player whichPlayer returns integer
    local group g
    local integer matchedCount
    set g = CreateGroup()
    set bj_livingPlayerUnitsTypeId = unitId
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterLivingPlayerUnitsOfTypeId)
    set matchedCount = CountUnitsInGroup(g)
    call DestroyGroup(g)
    return matchedCount
endfunction

This may eventually be fixed but until then here is a leak free version.
JASS:
function CountLivingPlayerUnitsOfTypeIdNoleak takes integer unitId,player whichPlayer returns integer
    local group g
    local integer matchedCount
    set g = CreateGroup()
    set bj_livingPlayerUnitsTypeId = unitId
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterLivingPlayerUnitsOfTypeId)
    set matchedCount = CountUnitsInGroup(g)
    call DestroyGroup(g)
    set g = null
    return matchedCount
endfunction
 
Actually there is a native doing the counting, but not ported to GUI.
JASS:
constant native GetPlayerTypedUnitCount takes player whichPlayer, string unitName, boolean includeIncomplete, boolean includeUpgrades returns integer

one uses it that way
JASS:
call GetPlayerTypedUnitCount (Player(0), UnitId2String('hfoo'),false,true)
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
one uses it that way
The native is not doing the counting in GUI as I posted above. If it was there would not be any problems.

Still the food method might be the most easy as long as food is not used for other things. Especially if interacting with many different unit types it would allow one to more simply regulate them.
 
Status
Not open for further replies.
Top