• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Whats wrong?

Status
Not open for further replies.
Level 9
Joined
Jun 20, 2008
Messages
476
  • city
    • Events
      • Time - Every 20.00 seconds of game time
    • Conditions
    • Actions
      • Set Taxincome = Small Town Hall
      • Unit Group - Pick every unit in (Units of type Small Town Hall) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 512.00 of (Position of (Picked unit))) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Triggering unit)) Equal to Farm
                • Then - Actions
                  • Player - Add 1 to (Owner of (Triggering unit)) Current gold
                • Else - Actions
It should pick all units of unit type farm in a 512 range of the unit type small town hall

It doesnt work
 
Level 4
Joined
Jan 9, 2010
Messages
89
I see the problem.

The reason for it not working is that in your if-then-else condition you use unit- type of triggering unit. There is no triggering unit.

I would change the second unit group to units within range matching condition and then use the (unit-type of (matching unit) = Farm) condition.
 
Level 9
Joined
Jun 20, 2008
Messages
476
Negative :( i got this now

  • city
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Small Town Hall) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 512.00 of (Position of (Picked unit)) matching ((Unit-type of (Picked unit)) Equal to Farm)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Farm
                • Then - Actions
                  • Player - Add 1 to (Owner of (Picked unit)) Current gold
                • Else - Actions
 
Level 4
Joined
Jan 9, 2010
Messages
89
Remove the whole if-then-else, including the condition. I think the problem is that you are referring to the unit as "picked unit", since there are two pick unit loops.

Edit: 2 minutes... I guess M0RT is right, you can't put two unit group loops within each other.
 
Level 4
Joined
Jan 9, 2010
Messages
89
Here is a (or rather: three) triggers you can use instead. I haven't tested but they seem right. It should be noted that they leak unit groups.
This initializes the hashtable
  • Untitled Trigger 002
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set hashVar = (Last created hashtable)
This one saves the number of farms within range of all town halls to the hashtable.
  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Town Hall)) and do (Actions)
        • Loop - Actions
          • Hashtable - Save (Number of units in (Units within 512.00 of (Position of (Picked unit)) matching ((Unit-type of (Matching unit)) Equal to Farm))) as 0 of (Key (Picked unit)) in hashVar
This one gives the player gold for every farm.
  • Untitled Trigger 003
    • Events
      • Time - Every 20.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Town Hall)) and do (Actions)
        • Loop - Actions
          • Player - Add (Load 0 of (Key (Picked unit)) from hashVar) to (Owner of (Picked unit)) Current gold
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
Here's the thing in one trigger, and this does not leak and it's MPI.
  • Untitled Trigger 075
    • Events
      • Time - Every 20.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Temp_Group_1 = (Units owned by (Player((Integer A))) of type Town Hall)
          • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
            • Loop - Actions
              • Set Temp_Loc_1 = (Position of (Picked unit))
              • Set Temp_Group_2 = (Units within 512.00 of Temp_Loc_1 matching (((Owner of (Matching unit)) Equal to (Player((Integer A)))) and ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Farm))))
              • Player - Add (Number of units in Temp_Group_2) to (Player((Integer A))) Current gold
              • Custom script: call RemoveLocation(udg_Temp_Loc_1)
              • Custom script: call DestroyGroup(udg_Temp_Group_2)
          • Custom script: call DestroyGroup(udg_Temp_Group_1)
 
Level 2
Joined
Feb 17, 2008
Messages
10
Unit Group - Pick every unit in (Units within 512.00 of (Position of (Picked unit)) matching ((Unit-type of (Picked unit)) Equal to Farm)) and do (Actions)

matching ((Unit-type of (Picked unit)) Equal to Farm)) <---- Change this to

matching ((Unit-type of (MATCHING unit)) Equal to Farm)) and it should work
 
Level 10
Joined
Aug 15, 2008
Messages
720
Now I really don't understand why you guys need whole hashtable system for this, just put first unit group's picked unit in variable and set (triggering unit) to (picked unit), like this.

  • city
  • Events
    • Time - Every 20.00 seconds of game time
  • Conditions
  • Actions
  • Set Taxincome = Small Town Hall
    • Unit Group - Pick every unit in (Units of type Small Town Hall) and do (Actions)
      • Loop - Actions
        • Set TempUnit = (Picked Unit)
    • Unit Group - Pick every unit in (Units within 512.00 of (Position of (TempUnit))) and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Picked Unit)) Equal to Farm
          • Then - Actions
            • Player - Add 1 to (Owner of (Picked Unit)) Current gold
          • Else - Actions
Also put Unit Groups in variables and remove em at the end, else you might experience fps drop or lags later.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,233
Instead of doing unescescary enuming, just enum them once into a group and then for through that whole group all the time.

Basically On unit death you remove the farm from the farm group if the type is farm (of dieing unit). If the type is a town, then you enum all farms in range of it and then check for each one of them if there is a living town in range of them (if not remove them from the farm group).
On unit construction completion, if the type is a farm, you check if it is in range of a town, and if so add it to the farm group. If the type is a town you check all farms in the area are in the farm group, and if not add them to it.
On build start you check if the farm is in range of a town, if not you immediatly abort its construction and give an error message (why on earth should you be able to build usless farms?).

Ontop of the group of farms (used for checking which farms are counted), you have a counter which is the farm number (how many farms are working at any time).
Finally, every X seconds you simply add the farm number worth of gold to the player. Yes really it is that simple after the system above is added.

As you can see, my recommended solution has high processing load only when new buildings are made or destroyed. The only possible time it has a chance of lagging is when a town is destroyed near a lot of farms but this is not likely. However at any time it will be a hell of a lot more efficent than the perodic enum solution you are trying above by incomparable ammounts. My solution should also be highly scaleable unlike yours meaning the load at any time for any opperation of the system remains approximatly constant weather one or hundreds of units are in the system. By a few hundred your system should start to cause visible FPS reduction if not have the chance to crash due to the opt limit.
 
Status
Not open for further replies.
Top