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

[Trigger] Triggered Pocket Factory


Here is how I made the pocket factory. This is not exactly the same as what you need but it might help to inspire you.

In my project, I am mimicking Warcraft 3 from a different game engine so that editing the abilities will be easy or whatever.. But because of that, this ability code is not directly applicable to Warcraft 3. But you could implement a parallel concept.

Or, if you find it easier, you could make a trigger like:
  • Events
    • Unit - A unit spawns a summoned unit
  • Conditions
    • Comparison - Unit type of (Summoned unit) equal to Pocket Factory
  • Action
    • Unit - Set the max hit points of (Summoned unit) equal to ((Max hit points of (Summoned unit)) + ((Level of (Summoning unit)) * 100))
The trigger solution will be a lot less customizable than the crazy in my video, but it would solve your problem pretty quickly I assume.
 
Level 14
Joined
Jul 19, 2007
Messages
772

Here is how I made the pocket factory. This is not exactly the same as what you need but it might help to inspire you.

In my project, I am mimicking Warcraft 3 from a different game engine so that editing the abilities will be easy or whatever.. But because of that, this ability code is not directly applicable to Warcraft 3. But you could implement a parallel concept.

Or, if you find it easier, you could make a trigger like:
  • Events
    • Unit - A unit spawns a summoned unit
  • Conditions
    • Comparison - Unit type of (Summoned unit) equal to Pocket Factory
  • Action
    • Unit - Set the max hit points of (Summoned unit) equal to ((Max hit points of (Summoned unit)) + ((Level of (Summoning unit)) * 100))
The trigger solution will be a lot less customizable than the crazy in my video, but it would solve your problem pretty quickly I assume.
Well your triggers is only for the factory building but I also want the units summoned by the factory to have hit points based on casting hero's level.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543

I'm sure you can figure out the scaling hit points, there's an Action to set a unit's Max HP and there's an Action to get the level of a unit's ability.
 
Level 14
Joined
Jul 19, 2007
Messages
772

I'm sure you can figure out the scaling hit points, there's an Action to set a unit's Max HP and there's an Action to get the level of a unit's ability.
I know how to do the HP scaling of Hero's level but I tried to test the spellpack you added on the thread you posted but nothing happened, no factory were summoned at all and what does the "Check Goblin's leash range" mean? Does it mean it will kill the summoned units if they are to far from the factory? I don't want it like that btw...
 
Level 14
Joined
Jul 19, 2007
Messages
772

I'm sure you can figure out the scaling hit points, there's an Action to set a unit's Max HP and there's an Action to get the level of a unit's ability.
I still don't get how to do it... Please fix the spellpack you made in that thread because it's not working at all and I also use different spawn units in every level (4 levels).
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
I still don't get how to do it... Please fix the spellpack you made in that thread because it's not working at all and I also use different spawn units in every level (4 levels).
I updated that post, there's a little mistake in the creation action:
  • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
You need to create the factory at PF_Point[0]. Also, that's where you can modify the Factory unit.

To modify the spawned goblins you would change this line:
  • Set VariableSet PF_Goblin[PF_Index] = Clockwerk Goblin
So get the level of the ability being cast and modify those two Actions to use different Unit-Types based on the level.
 
Level 14
Joined
Jul 19, 2007
Messages
772
I updated that post, there's a little mistake in the creation action:
  • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
You need to create the factory at PF_Point[0]. Also, that's where you can modify the Factory unit.

To modify the spawned goblins you would change this line:
  • Set VariableSet PF_Goblin[PF_Index] = Clockwerk Goblin
So get the level of the ability being cast and modify those two Actions to use different Unit-Types based on the level.
Still not working. No factory is created...
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Worked for me, are you sure you're referencing the correct point?

It's a simple fix:
  • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
Set it to PF_Point[0] instead of PF_Point[PF_Index].
 
Level 14
Joined
Jul 19, 2007
Messages
772
Worked for me, are you sure you're referencing the correct point?

It's a simple fix:
  • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
Set it to PF_Point[0] instead of PF_Point[PF_Index].
Ok now it's working but I still don't know how to make it spawn different unit-types in each level of the ability.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
I recommend learning how to make and modify basic triggers, this is a very easy one to do yourself. Try to break it down into simple steps:

First you need to figure out the level of the ability being cast. I imagine you may already know how to do this.

I recommend storing this information in an Integer variable so that you can easily reference it throughout the trigger"
  • Set Variable AbilityLevel = (Level of (Ability being cast) for (Triggering unit))
Now since we want to spawn different unit-types based on the Ability Level we need to ask an important question:
What level is the ability?

So how do you ask this question in the trigger? Simple, you use Conditions.

And how do you use Conditions inside of the Actions section of the trigger? Simple, you use an If Then Else action:
  • Events
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
      • Then - Actions
      • Else - Actions
Now the logic is very simple, if the Ability Level is Equal to 1 then we want to spawn Pocket Factory (Level 1):
  • If - Conditions
    • AbilityLevel Equal to 1
  • Then - Actions
    • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
If the Ability Level is Equal to 2 then we want to spawn Pocket Factory (Level 2):
  • If - Conditions
    • AbilityLevel Equal to 2
  • Then - Actions
    • Unit - Create 1 Pocket Factory (Level 2) for (Triggering player) at PF_Point[0] facing Default building facing degrees
This pattern continues for as many Levels as you'd like.

You can use this same logic on the goblin which is spawned using this variable:
  • Set VariableSet PF_Goblin[PF_Index] = Clockwerk Goblin

Another nice method is to setup and use an Array variable with the [index] representing the different levels of the ability:
  • Set Variable GoblinType[1] = Clockwerk Goblin (Level 1)
  • Set Variable GoblinType[2] = Clockwerk Goblin (Level 2)
  • Set Variable GoblinType[3] = Clockwerk Goblin (Level 3)
  • Set Variable PF_Goblin[PF_Index] = GoblinType[AbilityLevel]
 
Level 14
Joined
Jul 19, 2007
Messages
772
I recommend learning how to make and modify basic triggers, this is a very easy one to do yourself. Try to break it down into simple steps:

First you need to figure out the level of the ability being cast. I imagine you may already know how to do this.

I recommend storing this information in an Integer variable so that you can easily reference it throughout the trigger"
  • Set Variable AbilityLevel = (Level of (Ability being cast) for (Triggering unit))
Now since we want to spawn different unit-types based on the Ability Level we need to ask an important question:


So how do you ask this question in the trigger? Simple, you use Conditions.

And how do you use Conditions inside of the Actions section of the trigger? Simple, you use an If Then Else action:
  • Events
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
      • Then - Actions
      • Else - Actions
Now the logic is very simple, if the Ability Level is Equal to 1 then we want to spawn Pocket Factory (Level 1):
  • If - Conditions
    • AbilityLevel Equal to 1
  • Then - Actions
    • Unit - Create 1 Pocket Factory (Level 1) for (Triggering player) at PF_Point[0] facing Default building facing degrees
If the Ability Level is Equal to 2 then we want to spawn Pocket Factory (Level 2):
  • If - Conditions
    • AbilityLevel Equal to 2
  • Then - Actions
    • Unit - Create 1 Pocket Factory (Level 2) for (Triggering player) at PF_Point[0] facing Default building facing degrees
This pattern continues for as many Levels as you'd like.

You can use this same logic on the goblin which is spawned using this variable:
  • Set VariableSet PF_Goblin[PF_Index] = Clockwerk Goblin

Another nice method is to setup and use an Array variable with the [index] representing the different levels of the ability:
  • Set Variable GoblinType[1] = Clockwerk Goblin (Level 1)
  • Set Variable GoblinType[2] = Clockwerk Goblin (Level 2)
  • Set Variable GoblinType[3] = Clockwerk Goblin (Level 3)
  • Set Variable PF_Goblin[PF_Index] = GoblinType[AbilityLevel]
Ok I think I got it working now. I made it like this.
  • Cast Pocket Factory
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Spider Eggs
    • Actions
      • -------- Initialize --------
      • Set VariableSet PF_Index = (PF_Index + 1)
      • Set VariableSet PF_Owner[PF_Index] = (Triggering player)
      • Set VariableSet PF_Level[PF_Index] = (Level of (Ability being cast) for (Triggering unit))
      • Set VariableSet PF_Factory_Duration_Loop[PF_Index] = 0.00
      • Set VariableSet PF_Goblin_Interval_Loop[PF_Index] = 0.00
      • Custom script: set udg_PF_Goblin_Group[udg_PF_Index] = CreateGroup()
      • -------- --------
      • -------- //////////////////// --------
      • -------- CONFIGURE: --------
      • Set VariableSet PF_Factory_Duration[PF_Index] = 25.00
      • Set VariableSet PF_Goblin[PF_Index] = Baby Spider (lvl1)
      • Set VariableSet PF_Goblin_Interval[PF_Index] = 4.00
      • Set VariableSet PF_Goblin_Duration[PF_Index] = 16.00
      • Set VariableSet PF_Goblin_Leash[PF_Index] = 1100.00
      • Set VariableSet GoblinType[1] = Baby Spider (lvl1)
      • Set VariableSet GoblinType[2] = Baby Spider (lvl2)
      • Set VariableSet GoblinType[3] = Baby Spider (lvl3)
      • Set VariableSet GoblinType[4] = Baby Spider (lvl4)
      • -------- //////////////////// --------
      • -------- --------
      • -------- Create Factory --------
      • Set VariableSet PF_Point[0] = (Target point of ability being cast)
      • Unit - Create 1 Spider Eggs for (Triggering player) at PF_Point[0] facing Default building facing degrees
      • Unit - Set Max HP of (Last created unit) to (300 + (25 x (Hero level of Child of the Ungoliant 0149 <gen>)))
      • Unit - Set life of (Last created unit) to 100.00%
      • Custom script: call RemoveLocation (udg_PF_Point[0])
      • Unit - Add a PF_Factory_Duration[PF_Index] second Generic expiration timer to (Last created unit)
      • Set VariableSet PF_Factory[PF_Index] = (Last created unit)
      • Set VariableSet PF_Point[PF_Index] = (Position of (Last created unit))
      • -------- --------
      • -------- Turn On Factory Loop --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (PF Factory Loop <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on PF Factory Loop <gen>
        • Else - Actions
  • PF Factory Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer PF_Loop) from 1 to PF_Index, do (Actions)
        • Loop - Actions
          • Set VariableSet PF_Goblin_Interval_Loop[PF_Loop] = (PF_Goblin_Interval_Loop[PF_Loop] + 0.05)
          • -------- --------
          • -------- If the Interval has been reached then try to create a Goblin (also checks to see if the factory has expired) --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • PF_Goblin_Interval_Loop[PF_Loop] Greater than or equal to PF_Goblin_Interval[PF_Loop]
            • Then - Actions
              • -------- Reset the Interval but increase the Factory's Duration (time elapsed so far) --------
              • Set VariableSet PF_Goblin_Interval_Loop[PF_Loop] = 0.00
              • Set VariableSet PF_Factory_Duration_Loop[PF_Loop] = (PF_Factory_Duration_Loop[PF_Loop] + PF_Goblin_Interval[PF_Loop])
              • -------- --------
              • -------- Try to create a Goblin --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PF_Factory[PF_Loop] is alive) Equal to True
                  • (Level of Spider Eggs for Child of the Ungoliant 0149 <gen>) Equal to 1
                • Then - Actions
                  • Unit - Create 1 GoblinType[1] for PF_Owner[PF_Loop] at PF_Point[PF_Loop] facing Default building facing degrees
                  • Unit - Set Max HP of (Last created unit) to (250 + (30 x (Hero level of Child of the Ungoliant 0149 <gen>)))
                  • Unit - Set life of (Last created unit) to 100.00%
                  • Unit - Add a PF_Goblin_Duration[PF_Loop] second Generic expiration timer to (Last created unit)
                  • Unit Group - Add (Last created unit) to PF_Goblin_Group[PF_Loop]
                  • -------- --------
                  • -------- Rally Point --------
                  • Set VariableSet PF_Point[0] = (Rally-Point of PF_Factory[PF_Loop] as a point)
                  • Unit - Order (Last created unit) to Attack-Move To PF_Point[0]
                  • Custom script: call RemoveLocation (udg_PF_Point[0])
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (PF_Factory[PF_Loop] is alive) Equal to True
                      • (Level of Spider Eggs for Child of the Ungoliant 0149 <gen>) Equal to 2
                    • Then - Actions
                      • Unit - Create 1 GoblinType[2] for PF_Owner[PF_Loop] at PF_Point[PF_Loop] facing Default building facing degrees
                      • Unit - Set Max HP of (Last created unit) to (250 + (30 x (Hero level of Child of the Ungoliant 0149 <gen>)))
                      • Unit - Set life of (Last created unit) to 100.00%
                      • Unit - Add a PF_Goblin_Duration[PF_Loop] second Generic expiration timer to (Last created unit)
                      • Unit Group - Add (Last created unit) to PF_Goblin_Group[PF_Loop]
                      • -------- --------
                      • -------- Rally Point --------
                      • Set VariableSet PF_Point[0] = (Rally-Point of PF_Factory[PF_Loop] as a point)
                      • Unit - Order (Last created unit) to Attack-Move To PF_Point[0]
                      • Custom script: call RemoveLocation (udg_PF_Point[0])
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (PF_Factory[PF_Loop] is alive) Equal to True
                          • (Level of Spider Eggs for Child of the Ungoliant 0149 <gen>) Equal to 3
                        • Then - Actions
                          • Unit - Create 1 GoblinType[3] for PF_Owner[PF_Loop] at PF_Point[PF_Loop] facing Default building facing degrees
                          • Unit - Set Max HP of (Last created unit) to (250 + (30 x (Hero level of Child of the Ungoliant 0149 <gen>)))
                          • Unit - Set life of (Last created unit) to 100.00%
                          • Unit - Add a PF_Goblin_Duration[PF_Loop] second Generic expiration timer to (Last created unit)
                          • Unit Group - Add (Last created unit) to PF_Goblin_Group[PF_Loop]
                          • -------- --------
                          • -------- Rally Point --------
                          • Set VariableSet PF_Point[0] = (Rally-Point of PF_Factory[PF_Loop] as a point)
                          • Unit - Order (Last created unit) to Attack-Move To PF_Point[0]
                          • Custom script: call RemoveLocation (udg_PF_Point[0])
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (PF_Factory[PF_Loop] is alive) Equal to True
                              • (Level of Spider Eggs for Child of the Ungoliant 0149 <gen>) Equal to 4
                            • Then - Actions
                              • Unit - Create 1 GoblinType[4] for PF_Owner[PF_Loop] at PF_Point[PF_Loop] facing Default building facing degrees
                              • Unit - Set Max HP of (Last created unit) to (250 + (30 x (Hero level of Child of the Ungoliant 0149 <gen>)))
                              • Unit - Set life of (Last created unit) to 100.00%
                              • Unit - Add a PF_Goblin_Duration[PF_Loop] second Generic expiration timer to (Last created unit)
                              • Unit Group - Add (Last created unit) to PF_Goblin_Group[PF_Loop]
                              • -------- --------
                              • -------- Rally Point --------
                              • Set VariableSet PF_Point[0] = (Rally-Point of PF_Factory[PF_Loop] as a point)
                              • Unit - Order (Last created unit) to Attack-Move To PF_Point[0]
                              • Custom script: call RemoveLocation (udg_PF_Point[0])
                            • Else - Actions
              • -------- --------
              • -------- Check Goblin's leash range --------
              • Set VariableSet PF_End[PF_Loop] = False
              • Unit Group - Pick every unit in PF_Goblin_Group[PF_Loop] and do (Actions)
                • Loop - Actions
                  • Set VariableSet PF_End[PF_Loop] = True
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is alive) Equal to True
                    • Then - Actions
                      • Set VariableSet PF_Point[0] = (Position of (Picked unit))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Distance between PF_Point[0] and PF_Point[PF_Loop]) Greater than or equal to PF_Goblin_Leash[PF_Loop]
                        • Then - Actions
                          • Unit - Kill (Picked unit)
                          • Unit Group - Remove (Picked unit) from PF_Goblin_Group[PF_Loop].
                        • Else - Actions
                          • Set VariableSet PF_Goblin_Interval_Loop[PF_Loop] = 0.00
                          • Set VariableSet PF_End[PF_Loop] = False
                      • Custom script: call RemoveLocation (udg_PF_Point[0])
                    • Else - Actions
                      • Unit Group - Remove (Picked unit) from PF_Goblin_Group[PF_Loop].
              • -------- --------
              • -------- End if the Goblins are dead and the Factory has expired --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • PF_End[PF_Loop] Equal to True
                  • PF_Factory_Duration_Loop[PF_Loop] Greater than or equal to PF_Factory_Duration[PF_Loop]
                • Then - Actions
                  • Custom script: call DestroyGroup (udg_PF_Goblin_Group[udg_PF_Loop])
                  • Custom script: call RemoveLocation (udg_PF_Point[udg_PF_Loop])
                  • -------- --------
                  • -------- Set the current loop variables to be equal to the last loop variables --------
                  • Set VariableSet PF_Point[PF_Loop] = PF_Point[PF_Index]
                  • Set VariableSet PF_Factory[PF_Loop] = PF_Factory[PF_Index]
                  • Set VariableSet PF_Owner[PF_Loop] = PF_Owner[PF_Index]
                  • Set VariableSet PF_Factory_Duration[PF_Loop] = PF_Factory_Duration[PF_Index]
                  • Set VariableSet PF_Goblin_Interval_Loop[PF_Loop] = PF_Goblin_Interval_Loop[PF_Index]
                  • Set VariableSet PF_Goblin_Group[PF_Loop] = PF_Goblin_Group[PF_Index]
                  • Set VariableSet PF_End[PF_Loop] = PF_End[PF_Index]
                  • -------- --------
                  • -------- Reduce size of the loop --------
                  • Set VariableSet PF_Index = (PF_Index - 1)
                  • Set VariableSet PF_Loop = (PF_Loop - 1)
                  • -------- --------
                  • -------- Check if ALL factories are dead --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • PF_Index Equal to 0
                    • Then - Actions
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
                • Else - Actions
            • Else - Actions
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
You have the right idea for the most part.

But this is the variable that defines which unit is spawned:
  • Set VariableSet PF_Goblin[PF_Index] = Baby Spider (lvl1)
You just need to change that value to equal what you want:
  • Set VariableSet GoblinType[1] = Baby Spider (lvl1)
  • Set VariableSet GoblinType[2] = Baby Spider (lvl2)
  • Set VariableSet GoblinType[3] = Baby Spider (lvl3)
  • Set VariableSet GoblinType[4] = Baby Spider (lvl4)
  • Set VariableSet PF_Goblin[PF_Index] = GoblinType[PF_Level[PF_Index]]
PF_Level[PF_Index] has been set to the Ability Level at the start of the Actions, so you can reference that.

Remember to order the Actions properly so you don't reference a variable that hasn't been set yet.
 
Top