1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Random Unit spawning on death (TFT)

Discussion in 'Triggers & Scripts' started by thetracker3, Aug 29, 2013.

  1. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    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.
     
  2. Malhorne

    Malhorne

    Joined:
    Sep 14, 2012
    Messages:
    2,330
    Resources:
    6
    Spells:
    4
    Tutorials:
    1
    JASS:
    1
    Resources:
    6
    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.
     
  3. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    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.
     
  4. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    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-
     
  5. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    Please use trigger tags and post the whole trigger. Look at the tutorial how to easily post triggers.
    Also it seems like you are using a Hashtable which is pointless and very inefficient for this.
    You also leak locations. Look at the tutorial things that leak.
     
  6. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    The Trigger
    • 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.
     
  7. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    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.
    Here is the setup trigger
    • 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

    Here is the spawn random unit trigger
    • 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.
     
  8. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    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: Aug 30, 2013
  9. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    tempPoint is a point variable not a region variable.
    You must have it wrong in the variable editor
     
  10. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    Map Initialization
    • 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


    The Spawning Trigger
    • 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?
     
  11. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    in your create unit thing use the tempPoint variable as the location.

    is this a unit type array variable in the variable editor ? unitTypeArray[1]

    Also put a game message in the respawn trigger to see if it is running. If it isn't then remove the conditions and see if it fires.
     
  12. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    Map Initialization
    • 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


    The Spawning Trigger
    • 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.
     
  13. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    7,823
    Resources:
    28
    Packs:
    1
    Maps:
    8
    Spells:
    17
    Tutorials:
    2
    Resources:
    28
    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)
    )
     
  14. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    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.
     
  15. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    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
     
  16. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    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.
     
  17. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    Remove the conditions in the spawn trigger.
    If it spawns units then it works fine.

    It is then the conditions that is the problem.
    Post the trigger where you set the variables that are in the conditions.
     
  18. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    I already removed the conditions, still doesn't spawn anything. The trigger where I had the conditions before was the Spawning Trigger.

    The Conditionless 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...

    The Old Conditions, that are no longer applied to any valid trigger
    • 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?
     
  19. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,528
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    ok then where is the setup trigger ?
     
  20. thetracker3

    thetracker3

    Joined:
    Jun 25, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    The "Setup" Trigger
    • 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?