• 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] Random Unit spawning on death (TFT)

Status
Not open for further replies.
Level 2
Joined
Jun 25, 2009
Messages
20
So, I tried looking for this problem in the forums, and I found this: http://www.hiveworkshop.com/forums/world-editor-help-zone-98/random-unit-spawn-191988/

But it didn't provide much help, probably because I'm a total derp at triggers. I don't know where they were getting the "Set RandomUnit[1] = Footman" action. I tried doing it myself with a hashtable... that didn't work. So, if I could get an "Explain to me like I'm 5" kind of tutorial, it'd be really appreciated. Hell, even just a little bit of help would be awesome.

The premise behind this, if anyone is wondering, is a Soul Eater. He kills a unit, the unit drops one of 3 random souls, each with their own benefit, when he kills the soul (its a unit, mostly because if it was an item, someone else could pick it up) he is instantly given an item, that is consumed on being picked up, and he gets the benefit.
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
RandomUnit is a variable that have to be created in the variable editor (ctrl+B) in the trigger editor.
This variable is also an array it can have many values stored into and each value is referenced by an index, in this case the index is 1.
To get this action use the action set variable.
 
Level 2
Joined
Jun 25, 2009
Messages
20
Random unit is a unit type array variable.

Do Set unitTypeArray[] = footman

To get the random integer do
Create unit unitTypeArray[ random integer from 1 to however many you have] at point.

Ok, so here are the triggers so far. Please feel free to point out any flaws you see:

Unit - Create 1 (Unit-type of (Load 1 of 3 in RandomUnit[1])) for Neutral Passive at (Position of (Triggering unit)) facing Default building facing degrees

Unit - Create 1 (Unit-type of (Load 2 of 3 in RandomUnit[2])) for Neutral Passive at (Position of (Triggering unit)) facing Default building facing degrees

Unit - Create 1 (Unit-type of (Load 3 of 3 in RandomUnit[3])) for Neutral Passive at (Position of (Triggering unit)) facing Default building facing degrees

The Variable is:

RandomUnit - Hashtable Array (3) - Initial Value -None-
 
Level 2
Joined
Jun 25, 2009
Messages
20
  • Randomly Spawning Souls
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Blood Soul
      • (Unit-type of (Triggering unit)) Not equal to Body Soul
      • (Unit-type of (Triggering unit)) Not equal to Mind Soul
    • Actions
      • Unit - Create 1 (Unit-type of (Load 1 of 3 in RandomUnit[1])) for Neutral Passive at (Position of (Triggering unit)) facing Default building facing degrees
Better? Also, I'm only using a hashtable because I don't know how to really do this stuff. As I said before, I'm a derp. There's probably a tutorial or something, and if there is I could really use a link. I don't know about whats efficient, whats not efficient, whats the easiest way to do something, or whats the hardest way to do something.

I take back what I said about pointing out my flaws, I'd also like to make this point: Please just help me rather than criticize me.
 
I am trying to help you but you're not listening to something very simple.
I'm not sure how you understand hashtables and not variables....

Here is how to do this.
  • map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set unitTypeArray[1] = Peasant
      • Set unitTypeArray[2] = Footman
      • Set unitTypeArray[3] = Knight
      • Set unitTypeArray[4] = Rifleman
      • Set unitTypeArray[5] = Mortar Team
      • Set untTypeMaxIndex = 5
  • random unit create
    • Events
    • Conditions
    • Actions
      • Set tempPoint = (Center of (Playable map area))
      • Unit - Create 1 unitTypeArray[(Random integer number between 1 and untTypeMaxIndex)] for Player 1 (Red) at tempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation( udg_tempPoint)
Theres plenty of tutorials.
Look for a tutorial on variables.
Then look at my tutorial in my sig on Things a GUIer should know.
Then look at things that leak tutorial on triggers and scripts page.
 
Level 2
Joined
Jun 25, 2009
Messages
20
I am trying to help you but you're not listening to something very simple.
I'm not sure how you understand hashtables and not variables....

Here is how to do this.
  • map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set unitTypeArray[1] = Peasant
      • Set unitTypeArray[2] = Footman
      • Set unitTypeArray[3] = Knight
      • Set unitTypeArray[4] = Rifleman
      • Set unitTypeArray[5] = Mortar Team
      • Set untTypeMaxIndex = 5
  • random unit create
    • Events
    • Conditions
    • Actions
      • Set tempPoint = (Center of (Playable map area))
      • Unit - Create 1 unitTypeArray[(Random integer number between 1 and untTypeMaxIndex)] for Player 1 (Red) at tempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation( udg_tempPoint)
Theres plenty of tutorials.
Look for a tutorial on variables.
Then look at my tutorial in my sig on Things a GUIer should know.
Then look at things that leak tutorial on triggers and scripts page.

something very simple.

It may be something very simple to you, but its super confusing it me.

After fiddling around for a bit. I believe I may have gotten it working. I can't test it because every time I try to enable the Spawning Trigger, I get these errors:

Line 51: Invalid argument type (rect)

call RemoveLocation( udg_tempPoint)

Line 54: Expected a code statement (rect)

//===========================================================================

I'm not sure what this means, or how to fix it. But I'm guessing you might. So, can you help? Because I'm almost 100% sure I've gotten it working, ya know... aside from this little hiccup.
 
Last edited:
Level 2
Joined
Jun 25, 2009
Messages
20
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Remove creeps and critters from used start locations (for all players)
      • Melee Game - Create starting units (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
      • Melee Game - Enforce victory/defeat conditions (for all players)
      • Set unitTypeArray[1] = MindSoul
      • Set unitTypeArray[2] = BodySoul
      • Set unitTypeArray[3] = BloodSoul
      • Set unitTypeMaxIndex = 3
  • Randomly Spawning Souls
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Blood Soul
      • (Unit-type of (Triggering unit)) Not equal to Body Soul
      • (Unit-type of (Triggering unit)) Not equal to Mind Soul
    • Actions
      • Set tempPoint = (Center of (Playable map area))
      • Unit - Create 1 (Unit-type of unitTypeArray[(Random integer number between 1 and unitTypeMaxIndex)]) for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Custom script: call RemoveLocation( udg_tempPoint)
No more errors, I can get into the game just fine, but this time I kill a unit, and it doesn't spawn the soul. My untrained eyes say everything is the same as your trigger (mine is a bit different but that's just because my spawning trigger has an event and conditions), but what do your trained eyes tell you?
 
Level 2
Joined
Jun 25, 2009
Messages
20
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Remove creeps and critters from used start locations (for all players)
      • Melee Game - Create starting units (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
      • Melee Game - Enforce victory/defeat conditions (for all players)
      • Set unitTypeArray[1] = MindSoul
      • Set unitTypeArray[2] = BodySoul
      • Set unitTypeArray[3] = BloodSoul
      • Set unitTypeMaxIndex1 = 3
  • Randomly Spawning Souls
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set tempPoint = (Center of (Playable map area))
      • Unit - Create 1 (Unit-type of unitTypeArray[(Random integer number between 1 and unitTypeMaxIndex1)]) for Player 1 (Red) at tempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation( udg_tempPoint)
      • Game - Display to (All players) the text: Test to see if this Trigger is working.
Variables:
BloodSoul -- Type: Unit -- Initial Value: None
BodySoul -- Type: Unit -- Initial Value: None
MindSoul -- Type: Unit -- Initial Value: None
tempPoint -- Type: Point -- Initial Value: None
unitTypeArray -- Type: Unit Array (3) -- Initial Value: None
unitTypeMaxIndex1 -- Type: Integer -- Initial Value: 0 (Default)

It displays the message, but it doesn't add the unit. I just know its going to be some small detail that ruins the whole trigger.
 
Level 2
Joined
Jun 25, 2009
Messages
20
Replace the Set Temp_Point = Center of (Playable Map Area) with the actual position where the unit should be created (I think yours is Position of (Triggering Unit))

Nope, still didn't work. I figured it wouldn't, why would changing from one valid location to another valid location change whether or not it works? Thanks for trying though, I'm pretty sure its some tiny detail I'm not seeing.
 
These are wrong.

BloodSoul -- Type: Unit -- Initial Value: None
BodySoul -- Type: Unit -- Initial Value: None
MindSoul -- Type: Unit -- Initial Value: None
unitTypeArray -- Type: Unit Array (3) -- Initial Value: None

They should be like this.

BloodSoul -- Type: Unit Type -- Initial Value: None
BodySoul -- Type: Unit Type -- Initial Value: None
MindSoul -- Type: Unit Type -- Initial Value: None
unitTypeArray -- Type: Unit Type Array (1) -- Initial Value: None
 
Level 2
Joined
Jun 25, 2009
Messages
20
So, I fixed what you said deathismyfriend... Still didn't work. I think its something wrong with the actual creation of the unit, or maybe its with the body/blood/mind soul being set to their respective variables. This is so much more work than necessary.
 
Level 2
Joined
Jun 25, 2009
Messages
20
I already removed the conditions, still doesn't spawn anything. The trigger where I had the conditions before was the Spawning Trigger.

  • Randomly Spawning Souls
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set tempPoint = (Position of (Triggering unit))
      • Unit - Create 1 unitTypeArray[(Random integer number between 1 and unitTypeMaxIndex1)] for Player 1 (Red) at tempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation( udg_tempPoint)
      • Game - Display to (All players) the text: Test to see if this...
  • TRIGGER TESTING
    • Events
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Blood Soul
      • (Unit-type of (Triggering unit)) Not equal to Body Soul
      • (Unit-type of (Triggering unit)) Not equal to Mind Soul
    • Actions
Post the trigger where you set the variables that are in the conditions.

I don't exactly know what you mean by this. I didn't set any variables in any conditions. (unit-type of (Triggering Unit)) not equal to Blood Soul. Blood Soul refers to an actual unit in my game, it isn't a variable. Is THAT the problem?
 
Level 2
Joined
Jun 25, 2009
Messages
20
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Remove creeps and critters from used start locations (for all players)
      • Melee Game - Create starting units (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
      • Melee Game - Enforce victory/defeat conditions (for all players)
      • Set BloodSoul = Blood Soul
      • Set BodySoul = Body Soul
      • Set MindSoul = Mind Soul
      • Set unitTypeMaxIndex1 = 3
Wait... Could it be that these commands don't work on Map Initialization? Should I move them to their own trigger that starts them at like 1 second of game time?
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
It works fine on Map Init you just made a small error, it should be.

  • Actions
    • Set unitTypesMaxIndex[1] = Blood soul
    • Set unitTypesMaxIndex[2] = Mind soul
    • Set unitTypesMaxIndex[3] = Body soul
    • Set unitTypeMaxIndex = 3
 
Level 2
Joined
Jun 25, 2009
Messages
20
It works fine on Map Init you just made a small error, it should be.

  • Actions
    • Set unitTypesMaxIndex[1] = Blood soul
    • Set unitTypesMaxIndex[2] = Mind soul
    • Set unitTypesMaxIndex[3] = Body soul
    • Set unitTypeMaxIndex = 3

Well, if I set unitTypeMaxIndex to a Unit-Type variable I can't have "set unitTypeMaxIndex = 3" as a valid trigger. 3 has to be a unit, and I have to have an index number after unitTypeMaxIndex.

But if I set it to an integer variable, I can have "Set unitTypeMaxIndex = 3" but then I can't have "set unitTypeMaxIndex[1] = Blood Soul".

So the problem remains, what type of variable do I have it set to, and how to I get it to do the rest of the stuff?
 
Level 2
Joined
Jun 25, 2009
Messages
20
poke made a simple mistake it should be this.

i posted this above. please read.

  • map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set unitTypeArray[1] = Peasant
      • Set unitTypeArray[2] = Footman
      • Set unitTypeArray[3] = Knight
      • Set unitTypeArray[4] = Rifleman
      • Set unitTypeArray[5] = Mortar Team
      • Set untTypeMaxIndex = 5

Holy cow that was difficult. Its working now. How in Illidan's name was that so hard? Seriously... Was it just our clashing thoughts that caused us to get so confused?
 
Status
Not open for further replies.
Top