Easier way to do this trigger? (assigning custom values to units in range of unit)

NuQ

Member
Reaction score
8
What i need it to do is to pck every Unit type - flag in the map area, assign it a random custom value, then assign that same custom value to all the units within a certain range. Basiclly a way to associate all the units with a certain "Town." What i have now, works... but sometimes it skips some units and i know it's not because they were out of range. is there an easier way to do this?

What i have so far:
Trigger:
  • Association
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Flag)) and do (Unit - Set the custom value of (Picked unit) to (Integer((Random real number between 100.00 and 9999.00))))
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Not equal to Flag)) and do (Unit - Set the custom value of (Picked unit) to (Custom value of (Random unit from (Units within 1200.00 of (Position of (Picked unit)) matching ((Unit-type of (Matching unit)) Equal to Flag)))))


I'm thinking it might have something to do with the (Random unit from (Units within 1200.00 of (Position of (Picked unit)) part... I figure that if there is only one Flag within 1200 of the unit in question, that will be the one selected by rule of default, right? (i've ensured that there is always a flag within 1200 of a unit that this needs to apply to.)

any ideas?
 

Jonnycakes

New Member
Reaction score
6
This is how I would do it:
Trigger:
  • In Range of Flag
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set TempGroup = (Units of type Flag)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set RandomValue = (Random integer number between 100 and 9999)
          • Unit - Set the custom value of (Picked unit) to RandomValue
          • Set TempPoint = (Position of (Picked unit))
          • Set TempGroup2 = (Units within 1200.00 of TempPoint)
          • Unit Group - Pick every unit in TempGroup2 and do (Unit - Set the custom value of (Picked unit) to RandomValue)
          • Custom script: call RemoveLocation (udg_TempPoint)
          • Custom script: call DestroyGroup (udg_TempGroup2)
      • Custom script: call DestroyGroup (udg_TempGroup)


The snippets of custom script are to remove memory leaks. Whenever you use a group or a location, you should set them to a variable and destroy them with a snippet of custom script to prevent lag later in the game. Check this out.

As to why some units aren't being selected, I have no idea. How are you checking the custom values? That might have something to do with it as well.
 

NuQ

Member
Reaction score
8
That just opened a whole new can of worms. Rep added!

As for the trigger, it originally picked all flags and set them to a custom value, then picked all units within range and set them to the custom value of the flag. however this will be deprecated in light of the code you hve provided. thanks!

Also, noob question... how do you get it to post code like you did?
 

Jonnycakes

New Member
Reaction score
6
In the trigger editor, right click anywhere in your trigger text and select "copy as text". Then in your post, click on the yellow "a" button (WC3 GUI tags-it is just above the text box) and paste inside of them. Glad I could be of some help!
 

NuQ

Member
Reaction score
8
Awesome, thanks.

Seriously, the info you provided was like giving beer and fireworks to a teenager.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top