• 🏆 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!

Random hero

Status
Not open for further replies.
Hey everyone, I was working on my orb craft project and I've found that only the first 3 units that enter this region get a hero. WHY!?
[hidden="trigger]
  • HRandom
    • Events
      • Unit - A unit enters HRandom <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Sceleton
    • Actions
      • Unit - Remove (Entering unit) from the game
      • Unit - Create 1 (Unit-type of (Random unit from HRandom)) for (Owner of (Entering unit)) at ((Owner of (Entering unit)) start location) facing (Center of (Playable map area))
      • Camera - Pan camera for (Owner of (Entering unit)) to (Position of (Last created unit)) over 0.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Entering unit) is in AI) Equal to True
        • Then - Actions
          • Unit Group - Remove (Entering unit) from AI
          • Unit Group - Add (Last created unit) to AI
        • Else - Actions
      • Set Hero[(Player number of (Owner of (Entering unit)))] = (Last created unit)
[/hidden]
 
Level 15
Joined
Oct 18, 2008
Messages
1,588
  • at ((Owner of (Entering unit)) start location)
this leaks, always put positions into variables then clean them up. Same for
  • (Position of (Last created unit)
Also, both the entering event and the pool of heroes is HRandom. This means that the unit may be replaced by himself (unless HRandom is both a region and a unit array?).

So try it like this:

  • HRandom
    • Events
      • Unit - A unit enters HRandom <gen>
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Sceleton
    • Actions
      • Set TempLoc = Position of (Triggering unit)
      • Unit - Remove (Triggering unit) from the game
      • Unit - Create 1 (Unit-type of (Random unit from RandomUnitPool)) for (Owner of (Triggering unit)) at (TempLoc) facing (Center of (Playable map area))
      • Camera - Pan camera for (Owner of (Triggering unit)) to (TempLoc) over 0.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in AI) Equal to True
        • Then - Actions
          • Unit Group - Remove (Entering unit) from AI
          • Unit Group - Add (Last created unit) to AI
        • Else - Actions
      • Set Hero[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
      • Custom script: call RemoveLocation( udg_TempLoc )
Also, for this you obviously have to use a trigger to preload the content of RandomUnitPool when the map loads. You should use unit type array for this, but no WE installed, so I can't really create that part, so I just used a unit array. This change may also solve the entire problem, not sure.

EDIT: Entering unit -> Triggering unit
Thanks to deathismyfriend for the heads-up!
 
Last edited:
Thanks guys, I made this trigger berfore I've heard about leaks. Anyways it doesn't slove the problem, there are still only 3 on the battlefield.
  • HRandom
    • Events
      • Unit - A unit enters HRandom <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Sceleton
    • Actions
      • Set Temp_Point = ((Owner of (Triggering unit)) start location)
      • Unit - Remove (Triggering unit) from the game
      • Unit - Create 1 (Unit-type of (Random unit from HRandom)) for (Owner of (Triggering unit)) at Temp_Point facing (Center of (Playable map area))
      • Camera - Pan camera for (Owner of (Entering unit)) to Temp_Point over 0.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Entering unit) is in AI) Equal to True
        • Then - Actions
          • Unit Group - Remove (Entering unit) from AI
          • Unit Group - Add (Last created unit) to AI
        • Else - Actions
      • Set Hero[(Player number of (Owner of (Entering unit)))] = (Last created unit)
      • Custom script: call RemoveLocation(udg_Temp_Point)
I saw in dimf's tutrial how to preload abilities but how do you preload... units??
 
Level 25
Joined
Sep 26, 2009
Messages
2,387
  • at ((Owner of (Entering unit)) start location)
this leaks, always put positions into variables then clean them up.
I don't think that leaks.
As I understand the logic of leaks, a memory leak occurs when you create *something* that takes up a bit of your PC's memory space and you're unable to remove it.

So when I create unit at "position of (Triggering unit)", I basically create a location "position of (Triggering unit)" which takes up my space. If I don't save that location into variable firsthand, I will have no way to call that location later to remove it, hence it will cause a memory leak (i.e. as long as I will continue playing that map, that location will remain in game, taking up space in memory).

However start location is created upon map ini, it is set up by map maker, you can easily call it whenever you need it and when you use it, you don't create new (start) location. That makes me believe it does not leak.

-----------------

I saw in dimf's tutrial how to preload abilities but how do you preload... units??
Kanadaj may have meant either:
a) simply upon map ini create unit and remove it
or
b) make a trigger that fires upon map ini, which saves a list of your HRandom heroes. Something like
  • Event
    • Map Initialization
  • Actions
    • Set RandomHero[1] = Archmage
    • Set RandomHero[2] = Blood Mage
    • etc.
You then use the integer function Math - Random Number and create unit-type equal to RandomHero[Random number between 1 and X] where X is the highest Index in the hero list.



Thanks guys, I made this trigger berfore I've heard about leaks. Anyways it doesn't slove the problem, there are still only 3 on the battlefield.
I use this trigger, works fine:
  • Changing units
    • Events
      • Unit - A unit enters Start <gen>
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • Set player = (Owner of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in AI) Equal to True
        • Then - Actions
          • Unit Group - Remove (Triggering unit) from AI
          • Unit - Remove (Triggering unit) from the game
          • Unit - Create 1 (Unit-type of (Random unit from HRandom)) for player at (player start location) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to AI
        • Else - Actions
          • Unit - Remove (Triggering unit) from the game
          • Unit - Create 1 (Unit-type of (Random unit from HRandom)) for player at (player start location) facing Default building facing degrees
      • Set Hero[(Player number of player)] = (Last created unit)
      • Camera - Pan camera for player to (player start location) over 0.00 seconds
Test map attached. Note that in this test map, pan camera action works only for player 1 (you), other players are only units with shared control.
 

Attachments

  • HRandom.w3x
    24.3 KB · Views: 51
Thanks Nichilus, but the same thing happens :/
  • HRandom Copy
    • Events
      • Unit - A unit enters HRandom <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Sceleton
    • Actions
      • Set Temp_Player = (Owner of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in AI) Equal to True
        • Then - Actions
          • Unit Group - Remove (Entering unit) from AI
          • Unit - Remove (Triggering unit) from the game
          • Unit - Create 1 (Unit-type of (Random unit from HRandom)) for Temp_Player at (Temp_Player start location) facing (Center of (Playable map area))
          • Unit Group - Add (Last created unit) to AI
        • Else - Actions
          • Unit - Remove (Triggering unit) from the game
          • Unit - Create 1 (Unit-type of (Random unit from HRandom)) for Temp_Player at (Temp_Player start location) facing (Center of (Playable map area))
      • Set Hero[(Player number of (Owner of (Entering unit)))] = (Last created unit)
I tell you this map hates me!
 
*sigh* mate there may be another problem with your map, you better send it to someone to do a throughout search...

Theres chaos in my triggers. Trust me, no one wants to search it through ;)
Anyways problem solved...
  • HRandom Copy
    • Events
      • Unit - A unit enters HRandom <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Sceleton
    • Actions
      • Set Temp_Player = (Owner of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in AI) Equal to True
        • Then - Actions
          • Unit Group - Remove (Entering unit) from AI
          • Unit - Remove (Triggering unit) from the game
          • Unit - Create 1 HeroType[(Random integer number between 1 and 16)] for Temp_Player at (Temp_Player start location) facing (Center of (Playable map area))
          • Unit Group - Add (Last created unit) to AI
        • Else - Actions
          • Unit - Remove (Triggering unit) from the game
          • Unit - Create 1 HeroType[(Random integer number between 1 and 16)] for Temp_Player at (Temp_Player start location) facing (Center of (Playable map area))
      • Set Hero[(Player number of (Owner of (Entering unit)))] = (Last created unit)
Thanks for the help :)
 
Level 25
Joined
Sep 26, 2009
Messages
2,387
the problem must've been somewhere else then, because in the test map I attached in my previous post it worked fine (looking at the difference between your two triggers, I guess the problem was in the HRandom group itself)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
I don't think that leaks.
As I understand the logic of leaks, a memory leak occurs when you create *something* that takes up a bit of your PC's memory space and you're unable to remove it.

So when I create unit at "position of (Triggering unit)", I basically create a location "position of (Triggering unit)" which takes up my space. If I don't save that location into variable firsthand, I will have no way to call that location later to remove it, hence it will cause a memory leak (i.e. as long as I will continue playing that map, that location will remain in game, taking up space in memory).

However start location is created upon map ini, it is set up by map maker, you can easily call it whenever you need it and when you use it, you don't create new (start) location. That makes me believe it does not leak.

that does leak. it basically creates a new location everytime its called. not sure y blizzard made it like this.

@TO
never use entering unit use triggering unit. also anything u use twice or more store into a variable and use that. it is a huge efficiency boost when u use the variable.

also preloading units just create them then remove them when game is started.
 
that does leak. it basically creates a new location everytime its called. not sure y blizzard made it like this.

@TO
never use entering unit use triggering unit. also anything u use twice or more store into a variable and use that. it is a huge efficiency boost when u use the variable.

also preloading units just create them then remove them when game is started.

Ok thanks guys ^^
 
Status
Not open for further replies.
Top