• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] periodically creating item

Status
Not open for further replies.
Level 2
Joined
Sep 21, 2007
Messages
17
I need a trigger that creats an item at the position of a unit (not a prebuilt unit, a unit built in-game) every so often.
 
Level 8
Joined
Feb 20, 2007
Messages
338
You might need two triggers.

The first is the set up trigger:

  • Build Item Setup
    • Events
      • Unit - A unit owned by Player 1 (Red) Finishes construction
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Keep
    • Actions
      • Set Keep = (Constructed structure)
I give you both a player event of construction (if you only want this for one or two players) and a generic construction event for all players.

I set the Variable as Keep - It is a unit variable Not an array and has no intial value.

Then you can have your second trigger:

  • Keep Item
    • Events
      • Unit - A unit enters Village <gen>
    • Conditions
    • Actions
      • Item - Create Tome of Experience at (Position of Keep)
I just tossed in an event to trigger the creation of the keep.

If this is a hero unit then you would use Set the Hero when she/he is created or trained:

  • HERO Setup
    • Events
      • Unit - A unit owned by Player 1 (Red) Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Paladin
    • Actions
      • Set HERO = (Trained unit)
  • HERO Item
    • Events
      • Unit - A unit enters Village <gen>
    • Conditions
    • Actions
      • Hero - Create Tome of Experience and give it to HERO
      • Hero - Give (Last created item) to HERO
The Nice thing with setting a variable for units is that if you have many things going on for say the HERO you can just refer to the HERO in other triggers (Or the Keep or whatever)

Of course you need to clean up for leaks: http://www.hiveworkshop.com/forums/showthread.php?t=35124

And perhaps turn off the trigger(s) once they have fired - I do not know how you want to use this exactly, perhaps you need a certain item each time a specific unit is built/trained/created?
 
Level 8
Joined
Feb 20, 2007
Messages
338
Then change "Unit enters village" (based on entering a region/rect)

To a timer:
  • Events
    • Time - Every 30.00 seconds of game time
IF this is based on a single unit type you can use a unit group action:

  • Unit Group - Pick every unit in (Units of type Gold Mine) and do (Actions)
    • Loop - Actions
  • ---> insert create item action here.
Unit group specifications can be set to anything you need, in a specific region, from a specific team... etc.

Of course you most likely do not want your items being created over and over again every 30 seconds without a cleaning up of your map of items.

One way to do that is to set the custom value of items created:

  • Item - Set the custom value of (Last created item) to 30
That would go with a trigger like so:

  • ItemRemove
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Item - Pick every item in (Playable map area) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked item) is owned) Equal to False
              • ((Picked item) is invulnerable) Equal to False
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Picked item)) Less than or equal to 0
                • Then - Actions
                  • Item - Remove (Picked item)
                • Else - Actions
                  • Item - Set the custom value of (Picked item) to ((Custom value of (Picked item)) - 1)
                  • Floating Text - Create floating text that reads (String((Custom value of (Picked item)))) at (Position of (Picked item)) with Z offset 48.00, using font size 10.00, color (0.00%, 100.00%, 0.00%), and 50.00% transparency
                  • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
                  • Floating Text - Change (Last created floating text): Disable permanence
                  • Floating Text - Change the lifespan of (Last created floating text) to 0.50 seconds
            • Else - Actions
What this does is every second of the game it minuses one from the custom value of all items set with a custom value. Floating up and from the item is a number (the custom value) since this is taking place every second this is a countdown from - in this case 30 (as the set value of the items created at the location of in this case gold mines across the map). When countdown reaches zero the item is removed from the game. 30 is equal to 30 seconds.

If you have other items that drop say from creeps you can set their custom value higher say to 120 seconds (2 minutes) or if you want them all to last you make them invulnerable:

Examples:

Invulnerable "boss drops"

  • Boss drops
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Triggering unit)) Equal to Neutral Extra
          • ((Triggering unit) is A Hero) Equal to True
          • (Unit-type of (Triggering unit)) Equal to Pit Lord
    • Actions
      • Item - Make (Last dropped item) Invulnerable
I'm using the team neutral extra - you can specify other teams.
The next OR condition is A Hero - if A Hero loses and item it becomes invulnerable.

The next OR condition is set to specific unit type - in this case if a Pit Lord loses and item it is invulnerable.

If you just want the items to last longer when dropped by certain units/destructibles:

  • Crate Barrel death
    • Events
      • Destructible - Destructible dies [COLOR="Red"](set specific destructible here)[/COLOR]
    • Conditions
    • Actions
      • Item - Create (Random level (Random integer number between 1 and 10) item-type) at (Position of (Dying destructible))
      • Item - Set the custom value of (Last created item) to [COLOR="Red"]120[/COLOR]
      • Wait 0.10 seconds
In this one I used a random level item ranging from all the non-campaign items. Campaign items (like keys) are level 0 and would not be dropped - and any custom items I make I can set at level 11 and have a trigger to drop either random level 11 items or the item specifically.

This time the timer is set to 120 seconds (2 minutes).

Of course none of these have been set to clean up leaks. Go to the Leak Sticky thread and see what I mean about leaks.
 
Status
Not open for further replies.
Top