• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

destroyed at the same time.

Status
Not open for further replies.
Level 3
Joined
Mar 29, 2011
Messages
38
The ideal is:
I have 4 stones, each can be destroyed with just one hit.
When a stone is destroyed, it will respawn after 1 second.
When all 4 stones is destroyed at the same time (before any stone can respawn), the stone stop respawning, and spawn a boss.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
  • Spawn Boss
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Stone
    • Actions
      • Set stonesDied = (stonesDied + 1)
      • Wait 1.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • stonesDied Less than 4
        • Then - Actions
          • Set stonesDied = (stonesDied - 1)
          • Set tempLoc = (Position of (Triggering unit))
          • Unit - Create 1 Stone for Player 2 (Blue) at tempLoc facing 0.00 degrees
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • bossSpawned Equal to False
            • Then - Actions
              • Game - Display to (All players) the text: Boss Spawns!
              • Set bossSpawned = True
              • Set tempLoc = (Center of BossSpawnRegion)
              • Unit - Create 1 Boss for Player 2 (Blue) at tempLoc facing 0.00 degrees
            • Else - Actions
      • Custom script: call RemoveLocation(udg_tempLoc)
That should do it.

Variables:
- tempLoc, point variable
- stonesDied, integer variable
- bossSpawned, boolean variable
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Can't you use the condition
  • Conditions
    • (Number of living Stones units owned by Player 2 (Blue)) Less than 4
instead of creating a variable and making more conditions/action?

Well, let me get a bit technical here.
The first thing you should notice is that that condition uses a unit group (memory leak, unless fixed).

The second thing is that it converts to something like this:
JASS:
function CountUnitsInGroupEnum takes nothing returns nothing
    set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction

function CountUnitsInGroup takes group g returns integer
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupCountUnits = 0
    call ForGroup(g, function CountUnitsInGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_groupCountUnits
endfunction

function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, r, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsInRectAll takes rect r returns group
    return GetUnitsInRectMatching(r, null)
endfunction

function Trig_SomeTrigger_Conditions takes nothing returns boolean
    if ( not ( CountUnitsInGroup(GetUnitsInRectAll(SomeRect)) == 4 ) ) then
        return false
    endif
    return true
endfunction
A single line of GUI, converting into pure chaos.

Of course this isn't a fully functional script (I just copy/pasted, nothing else), BUT: it is the actual size of the script when converted.
So concerning efficiency and functionality, using an integer to count the stones is way better.

I also advise you use integers to count units whenever possible (e.g.: when making MUI spells, you add units to a unit group so you can easily loop through them. If you have an integer that counts the number of units in that group, then you do not have to use that condition to see if the loop-trigger should be turned off or not).

Edit: just for comparison, here's the script with integers (only the required functions for the integers).
JASS:
function Trig_Melee_Initialization_Func003C takes nothing returns boolean
    if ( not ( udg_stonesDied == 4 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Melee_Initialization_Actions takes nothing returns nothing
    set udg_stonesDied = ( udg_stonesDied + 1 )
    call TriggerSleepAction( 1.00 )
    if ( Trig_Melee_Initialization_Func003C() ) then
        set udg_stonesDied = ( udg_stonesDied - 1 )
    else
    endif
endfunction
 
Status
Not open for further replies.
Top