• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] How do you detect a Pocket Factory summon?

Status
Not open for further replies.
Level 4
Joined
Nov 20, 2006
Messages
71
upload_2021-1-17_21-48-15.png


  • Detect Summoned Unit
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (Name of (Summoned unit))

You can see here that it properly detects the water elemental. However, the pocket factory is not detected when it is summoned, neither are any of the Clockwork goblins that come from the factory. Does anyone know how to detect either of these things? How would I find the summoner and the summoned unit?
 
Level 4
Joined
Jun 6, 2015
Messages
77
Could you do this instead?

For the summoned unit:
  • Events
    • Unit - A unit enters (Playable map area)
  • Conditions
    • ((Triggering unit) is Summoned) Equal to True
    • (Unit-type of (Triggering unit)) Equal to Pocket Factory (Level 1)
  • Actions
    • Game - Display to (All players) the text: (Name of (Triggering unit))
For the summoner:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Pocket Factory
  • Actions
    • Game - Display to (All players) the text: (Name of (Triggering unit))
Edit: Maybe the condition ((Triggering unit) is summoned) don't work I havent tested, but in that case remove it. Assuming there is no other way a Pocket factory may enter the map other than being spawned by this particular spell, I don't see a problem in doing this.
 
Last edited:
Level 12
Joined
Feb 5, 2018
Messages
521
You can just use a unit enters playable map area as long as you don't over use it.

It has advantages and disadvantages.
 
Level 4
Joined
Nov 20, 2006
Messages
71
There might be a better/different way, but you could always make an identical custom unit, and make the pocket factory the only source of that new custom unit. Then you just make a simple condition check to check the unit type of the summoned unit.


This works but then you have a lot of delay. You have to wait until the factory spawns, then for it to spawn a unit, and of course it can't spawn something like Clockwork Goblins at the same time.


Could you do this instead?

For the summoned unit:
  • Events
    • Unit - A unit enters (Playable map area)
  • Conditions
    • ((Triggering unit) is Summoned) Equal to True
    • (Unit-type of (Triggering unit)) Equal to Pocket Factory (Level 1)
  • Actions
    • Game - Display to (All players) the text: (Name of (Triggering unit))
For the summoner:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Pocket Factory
  • Actions
    • Game - Display to (All players) the text: (Name of (Triggering unit))
Edit: Maybe the condition ((Triggering unit) is summoned) don't work I havent tested, but in that case remove it. Assuming there is no other way a Pocket factory may enter the map other than being spawned by this particular spell, I don't see a problem in doing this.


A pocket factory enters the map, but who summoned it?

Yes you can use "unit stars effect of ability" but lets say two abilities from the same player are cast at different ranges. Then, the missiles will land at different times so the order of "starting effect of ability" won't be reliable.
 
Level 4
Joined
Nov 20, 2006
Messages
71
That's a good point, and maybe the closest we can get to detecting it.

But does the missile start during "effect of an ability" or after a cast animation? Complicated but still may be the only way.
 
Level 9
Joined
Mar 26, 2017
Messages
376
Its 'effect of ability'.

Usually whenever the unit is issues a spell order he 'starts casting'. Then there is the cast animation (~.5 sec), and then 'starts ability'.

I think there may be a guide on Hive that explains this in detail.
 
Level 12
Joined
Feb 5, 2018
Messages
521
For the latter, you can add a delay that is based on the distance of the spell cast, divided by the missile speed.

What? Why would you do anything this complicated on a simple thing like this?

Save the caster into a hashtable and load the UnitHandle when the pocket factory enters map area.

  • Pocket Factory
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Pocket Factory
    • Actions
      • Set VariableSet PF_Caster = (Triggering unit)
      • Hashtable - Save Handle OfPF_Caster as 0 of 1 in PF_Hash.
      • Unit Group - Add PF_Caster to PF_Group
      • Game - Display to (All players) the text: Pocket Factory Cast
  • Pocket Factory Check
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Pocket Factory (Level 1)
    • Actions
      • Unit Group - Pick every unit in PF_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet PF_Caster = (Load 0 of 1 in PF_Hash.)
      • Game - Display to (All players) the text: (Name of PF_Caster)
 

Attachments

  • WC3ScrnShot_011821_211725_001.png
    WC3ScrnShot_011821_211725_001.png
    3.2 MB · Views: 19

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,496
I threw together a custom triggered Pocket Factory. It's missing the missile component of the spell but it should have everything else.

The missile stuff could be easily added to it, maybe I'll do it later.

Anyway, with this you can get access to the creator of the Pocket Factory and the creator of the Goblins. You could also do more fun stuff like spawn multiple goblins at a time (after a small adjustment).

Edit: There's a mistake in the Cast trigger, make sure the Pocket Factory is created at PF_Point[0]:
  • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
 

Attachments

  • Pocket Factory 1.w3m
    20.7 KB · Views: 21
Last edited:
Level 9
Joined
Mar 26, 2017
Messages
376
What? Why would you do anything this complicated on a simple thing like this?

It is not very simple? You take the distance and divide it by missile speed.

Personally, I would never want a 'unit enters' trigger in my map for performance reasons.

Also I'm not sure if there can be multiple pocket factory casters for one player in his map, in which case there may be collision using your proposed solution.
>> nvm misread and though you saved on a player basis. Still I wouldn't use 2 triggers for this.
 
Last edited:
Level 12
Joined
Feb 5, 2018
Messages
521
Also I'm not sure if there can be multiple pocket factory casters for one player in his map, in which case there may be collision using your proposed solution.

And why is that? The unithandle is saved on a hashtable for each casting unit. Please enlighten me :)
 
Level 4
Joined
Jun 6, 2015
Messages
77
What? Why would you do anything this complicated on a simple thing like this?

Save the caster into a hashtable and load the UnitHandle when the pocket factory enters map area.

  • Pocket Factory
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Pocket Factory
    • Actions
      • Set VariableSet PF_Caster = (Triggering unit)
      • Hashtable - Save Handle OfPF_Caster as 0 of 1 in PF_Hash.
      • Unit Group - Add PF_Caster to PF_Group
      • Game - Display to (All players) the text: Pocket Factory Cast
  • Pocket Factory Check
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Pocket Factory (Level 1)
    • Actions
      • Unit Group - Pick every unit in PF_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet PF_Caster = (Load 0 of 1 in PF_Hash.)
      • Game - Display to (All players) the text: (Name of PF_Caster)

Cool, I must definitely learn to use hashtables soon!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,496
@DoomBlade
@verstefyren
The issue still stands even with Hashtables. If two units cast Pocket Factory at the same time, both will be added to PF_Group. When the first Pocket Factory enters the map, the Pick Every Unit function will set PF_Caster = BOTH picked units, which results in the very last Picked unit becoming PF_Caster. This last unit may or may not be the actual owner of the Entering unit, it's whichever one the game decides is picked last (I believe the most recent unit added to the Unit Group is always picked last).

You can check the owner of the entering unit and compare it with the owner of the picked unit, but then you're stuck with the limitation of only being allowed 1 of these abilities per Player. Plus, at that point it'd be easier to just use the player number in a unit-array, like PF_Caster[player number of triggering player] = Casting unit, rather than bothering with Hashtables and Unit Groups.

Edit: My mistake, the PF_Caster will always be the most recent unit regardless, and the Unit Group serves no purpose.
 
Last edited:
Level 12
Joined
Feb 5, 2018
Messages
521
The issue still stands even with Hashtables. If two units cast Pocket Factory at the same time, both will be added to PF_Group. When the first Pocket Factory enters the map, the Pick Every Unit function will set PF_Caster = BOTH picked units, which results in the very last Picked unit becoming PF_Caster. This last unit may or may not be the actual owner of the Entering unit, it's whichever one the game decides is picked last (I believe the most recent unit added to the Unit Group is always picked last).

Well, you are propaly right, but I just tried with 6 units owned by one player to cast the skill at the exact same time and it did not lose the unithandle.

Ofcourse this requires some tweaking and memory clean for the hashtables and units removed from the group and so on.

Still very interesting thought. :)

Also got another idea, sphere effect launches when the projectile reaches it's point right? You could add a dummy unit in your system with sphere, using the pocket factory missile projectile.

I just remembered I used that alot for effect delays and missile type spells.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,496
So the Unit Group in your example isn't actually serving any purpose. 0 of 1 in PF_Hash is always going to be the most recent Tinker to cast Pocket Factory. This gets replaced each time.

What OP wants to find is the Tinker that created the Pocket Factory. You are getting the most recent Tinker that has casted Pocket Factory. Even after fixing up leaks and removing units from the unit group the problem still exists.

If Pocket Factories always took the same amount of time to spawn then this problem could be resolved using an Array. First unit to cast Pocket Factory is stored at Index 1, second unit at Index 2, and then we just match these indexes when our first Factory enters the map, then our second, etc... But that's not the case, Pocket Factories time until entering the map will vary depending on where you cast the ability. Shorter the cast range, the quicker the Factory will spawn. Because of this variance you leave yourself open to potential mix ups (associating the wrong Summoning and Summoned units).

The only good solution that comes to mind is to trigger the spell yourself since you'll be in full control of everything. Everything else seems to have potential for mistakes.
 
Last edited:
Status
Not open for further replies.
Top