• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] the IF for king of the hill?

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You will need to run an expensive group based operation every time a point is awarded for the easy approach so make sure you correctly destroy the group to prevent leaks.

The simplest approach is mutual exclusion. You have 2 boolean variables which start out false (each time you run you need to set them false). Then for each unit "on the hill" (fill a group with the units from the hill rect/rects (region in GUI) and pick them) you set them as follows.
1. Set if any unit from team 1 is on the hill (bool1 == true or owner of picked unit is in team 1 == true).
2. Set if any unit from team 2 is on the hill (bool2 == true or owner of picked unit is in team 2 == true).

Then after having applied that test to all units "on the hill" you check these boolean values and do the following depending on the case.
bool1 == true and bool2 == true: Both teams are on the hill, do nothing.
bool1 == true and bool2 == false: Team 1 owns the hill, give him a point.
bool1 == false and bool2 == true: Team 2 owns the hill, give him a point.
bool1 == false and bool2 == false: No one owns the hill? Maybe give point to last owner (keep track in variable).
 
great, thank you! :) and how about death? I mean, when a unit in the region dies, does this count as leave region?

EDIT: will it work this way?

  • king integer
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
      • (king <gen> contains (Revivable Hero)) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Race of (Triggering unit)) Equal to Orc
        • Then - Actions
          • Set king_horde = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Race of (Triggering unit)) Equal to Human
        • Then - Actions
          • Set king_alliance = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • king_alliance Equal to True
              • king_horde Equal to False
        • Then - Actions
          • Set king_ally_points = (king_ally_points + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • king_alliance Equal to True
              • king_horde Equal to False
        • Then - Actions
          • Set king_horde_points = (king_horde_points + 1)
        • Else - Actions
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
That trigger makes no sense as it has references to units like "Triggering Unit" which are not compatible with that event.

I still recommend doing the brute force approach where you fill a group with all units inside the hill rect (or rects if the hill is made of many) and then filtering the group unit by unit with those tests. You can add additional tests like "unit is alive" and things to make sure dead units do not count. Remember that any group object you make must be destroyed/recycled or it will leak.
 
hey how about this?
  • king integer
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in king <gen>) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (king <gen> contains Beastmaster) Equal to True
                      • (king <gen> contains Brewmaster) Equal to True
                      • (king <gen> contains Blademaster) Equal to True
                      • (king <gen> contains Shadow_Hunter) Equal to True
                      • (king <gen> contains Far_Seer) Equal to True
                      • (king <gen> contains Tauren_Chieftain) Equal to True
                • Then - Actions
                  • Set king_horde = True
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (king <gen> contains Archmage) Equal to True
                      • (king <gen> contains Blood_Mage) Equal to True
                      • (king <gen> contains Mountain_King) Equal to True
                      • (king <gen> contains Paladin) Equal to True
                      • (king <gen> contains Ranger) Equal to True
                      • (king <gen> contains Wizard) Equal to True
                • Then - Actions
                  • Set king_horde = True
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • (king <gen> contains Archmage) Equal to False
                      • (king <gen> contains Blood_Mage) Equal to False
                      • (king <gen> contains Mountain_King) Equal to False
                      • (king <gen> contains Paladin) Equal to False
                      • (king <gen> contains Ranger) Equal to False
                      • (king <gen> contains Wizard) Equal to False
                • Then - Actions
                  • Set king_alliance = False
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • (king <gen> contains Beastmaster) Equal to False
                      • (king <gen> contains Brewmaster) Equal to False
                      • (king <gen> contains Blademaster) Equal to False
                      • (king <gen> contains Shadow_Hunter) Equal to False
                      • (king <gen> contains Far_Seer) Equal to False
                      • (king <gen> contains Tauren_Chieftain) Equal to False
                • Then - Actions
                  • Set king_horde = False
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • king_alliance Equal to True
                      • king_horde Equal to False
                • Then - Actions
                  • Set king_ally_points = (king_ally_points + 1)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • king_alliance Equal to True
                      • king_horde Equal to False
                • Then - Actions
                  • Set king_horde_points = (king_horde_points + 1)
                • Else - Actions
            • Else - Actions
 
how about this @Dr Super Good ?

  • king integer
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and (((Matching unit) is A Hero) Equal to True))) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to King_alliance_in
      • Unit Group - Pick every unit in (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and (((Matching unit) is A Hero) Equal to True))) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to King_horde_in
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Number of units in King_alliance_in) Greater than 0
              • (Number of units in King_horde_in) Equal to 0
        • Then - Actions
          • Set king_ally_points = (king_ally_points + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Number of units in King_alliance_in) Equal to 0
              • (Number of units in King_horde_in) Greater than 0
        • Then - Actions
          • Set king_horde_points = (king_horde_points + 1)
        • Else - Actions
(I will remove unit not withing king with other trigger check)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
The following lines of GUI...
  • Unit Group - Pick every unit in (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and (((Matching unit) is A Hero) Equal to True))) and do (Actions)
  • Unit Group - Pick every unit in (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and (((Matching unit) is A Hero) Equal to True))) and do (Actions)
Each of them creates a unit group as a result of the "Units in..." function. This unit group is never removed resulting in a leak. Each time the trigger runs it creates a new unit group and the old one will sit in memory until the map session ends.

You need to assign the unit groups to a temporary unit group variable, use them in the "Pick every unit in..." action and then after the action destroy the group. The same temporary group variable can be used for both groups since it is accessed atomically and no nesting occurs.
 
So, I guess this is the final.
  • king integer
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Remove all units from King_alliance_in
      • Unit Group - Remove all units from King_horde_in
      • Set King_alliance_in = (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
      • Set King_horde_in = (Units in king <gen> matching (((Race of (Matching unit)) Equal to Orc) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Number of units in King_alliance_in) Greater than 0
              • (Number of units in King_horde_in) Equal to 0
        • Then - Actions
          • Set king_ally_points = (king_ally_points + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Number of units in King_alliance_in) Equal to 0
              • (Number of units in King_horde_in) Greater than 0
        • Then - Actions
          • Set king_horde_points = (king_horde_points + 1)
        • Else - Actions
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You still are leaking two groups. Unlike the JASS group filler natives which use an existing group, the GUI function makes a new group. As such these lines leak...
  • Set King_alliance_in = (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
  • Set King_horde_in = (Units in king <gen> matching (((Race of (Matching unit)) Equal to Orc) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
Since you are losing the reference to the existing group by replacing it with a new group before you remove it (which you never do).

As far as I am aware there is no action in GUI to destroy the group so you will have to use a line of custom script that calls this native...
JASS:
native DestroyGroup takes group whichGroup returns nothing
In your case the two lines will look like...
JASS:
call DestroyGroup(udg_King_alliance_in)
call DestroyGroup(udg_King_horde_in)
As they are custom script they are case sensitive and the variable references will not update automatically. Global variables used by GUI have the "udg_" prefix appended to them.

These lines should be placed where the current clear lines are (replaces them, it is pointless to clear a group that you are going to destroy) or at the end of the trigger (so the use of those variables is atomic, aka no persistency or nested usage).
 
Ok, Thanks :) Now function is finished?

  • king integer
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: native DestroyGroup takes group whichGroup returns nothing
      • Custom script: call DestroyGroup(udg_King_alliance_in)
      • Custom script: call DestroyGroup(udg_King_horde_in)
      • Set King_alliance_in = (Units in king <gen> matching (((Race of (Matching unit)) Equal to Human) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
      • Set King_horde_in = (Units in king <gen> matching (((Race of (Matching unit)) Equal to Orc) and ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Number of units in King_alliance_in) Greater than 0
              • (Number of units in King_horde_in) Equal to 0
        • Then - Actions
          • Set king_ally_points = (king_ally_points + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Number of units in King_alliance_in) Equal to 0
              • (Number of units in King_horde_in) Greater than 0
        • Then - Actions
          • Set king_horde_points = (king_horde_points + 1)
        • Else - Actions
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
No as that will throw a syntax error and prevent the map from loading.

JASS:
native DestroyGroup takes group whichGroup returns nothing
This is not a valid line of user JASS. The native is already declared in the native script file and it is certainly invalid to declare a native inside a function.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Because that is the deceleration (interface specification) for the native. It is so you know what the function name is and what arguments it takes and returns. Without that you cannot possibly know how to call it (use it). I thought you already knew the basics of JASS (as you are making a WC3 map) so I do apologize if I confused you in any way.
 
Status
Not open for further replies.
Top