1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Need to Switch out one unit for another

Discussion in 'Triggers & Scripts' started by fargs, Mar 14, 2007.

  1. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    Ok so what i want to happen is when a unit aquires a item, i want to swithc that unit out and put another in its place (BUT i want the new unit to have all the same items as the guy before...) so yeah.... if anyone can help guide me through it that would be Ggreeeeaatt
     
  2. Xelephant

    Xelephant

    Joined:
    Feb 2, 2005
    Messages:
    215
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Well the event should be

    • Unit - A unit Acquires an item


    After that you should check the item, so it changes only on tha specific item
    • (Item-type of (Item being manipulated)) Equal to MyImbaItem


    And the last point is the replace action (ye the items will be the same)
    • Unit - Replace (Hero manipulating item) with a ImbaHero using The old unit's relative life and mana


    Btw the replaced unit will have an slight higher hp amount than the Unit you replace. So if you want to switch often you need an workarround for that.
     
  3. TheBlackMage

    TheBlackMage

    Joined:
    Jan 14, 2006
    Messages:
    4
    Resources:
    0
    Resources:
    0
    Interesting problem.
    It may be possible to assign each unit with an inventory a unique ID. Then when a unit receives any item, add this item to an array Items[UnitID].

    Once the unit is replaced, use Hero - Add Item for Hero actions for each of the Items in UnitID.

    Alternatively, you could spawn another unit at the same position, order the old unit to give all of the items to the new unit, and then remove the old unit.
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,189
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    You can just create a global item array of size 5 and use the action that fetches the item in slot X to store your items in the array of the time of change over. To fix the issue with over HP, you can use a tome of HP with -HP addition so it removes hp untill the desired ammount.
     
  5. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Yeah, what doc said, create an item-type variable array:

    Loop from 1 to 6
    Set Item[Integer A] = Item-type of (Item in slot (Integer A) for <unit>)
    //replace the unit
    Loop from 1 to 6
    Create a Item[Integer A] for <replacedUnit> in slot (Integer A)

    Or sthg like this.
     
  6. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    But what about the <unit> factor?

    When u say for <unit> that is saying that it will only be applied to the unit you have selected on the trigger, i don';t think this would work in the long run because as soon as u have switched units you would somehow need to redefine the <unit> for the new unit.... something that might help is that each player in the map will only have one character, one unit the whole time, it will just be switched out occatiionally when it aquires the items. so idk if this makes this worthless or i just need to add a line or something but yeah, im not a pro with variables lol but thanks
     
  7. Xelephant

    Xelephant

    Joined:
    Feb 2, 2005
    Messages:
    215
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Btw if you would use that replace trigger the unit will still hold the items, it wont loose it. I did an map where you switch the hero if you quip an weapon, so it works fine. You dont need an item store array. Just one for the percent of life.

    Sad that no one tried it, and just discuss on...
     
  8. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    What do u mean u just need one for Percent life?? and for the idea above on using the tomes, how would u make it stop at a set amount?
     
  9. Xelephant

    Xelephant

    Joined:
    Feb 2, 2005
    Messages:
    215
    Resources:
    1
    Maps:
    1
    Resources:
    1
    well declare exact waht you want to do, and where the limit are set. The Trigger above is just onetime its witches unit x for y. And if y takes it again it will just switch 2 y.

    Well if you use the unit - replace action. The new unit will have slight higher hp for example 650/1000 instead of 500/1000 hp

    Therefore you will need some variable to store the current health of the unit if you switch multiple times in an minute.
     
  10. HappyTauren

    HappyTauren

    Joined:
    Nov 3, 2006
    Messages:
    8,408
    Resources:
    87
    Models:
    61
    Icons:
    23
    Packs:
    1
    Tutorials:
    2
    Resources:
    87
    maybe simply copy unit? copy it into cache , and then restore it?
     
  11. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Set OriginalUnit = <unit you want to replace>
    You store the item-types of OriginalUnit (the way i wrote it down)
    Replace OriginalUnit with a new one
    Set NewUnit = Last Replaced Unit (!!!)
    Add the items to NewUnit

    And by the way, if they are heroes, when they are replaced, their abilities must be learned again.
     
  12. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    But the units are not heros..... so what does that mean, and thanks Paskovich i think that should help alot
     
  13. Xelephant

    Xelephant

    Joined:
    Feb 2, 2005
    Messages:
    215
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Well thats the Original Trigger before i improved it, you can find it here

    http://www.epicwar.com/maps/7715/

    You wont need an array for item transfer as you see, go ahead test it.

    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Unit-type of (Hero manipulating item)) Not equal to Bereta 9000S
      • (Item-type of (Item being manipulated)) Equal to Beretta 9000S
      • (Charges remaining in (Item being manipulated)) Greater than 0
    • Actions
      • Item - Set charges remaining in (Item being manipulated) to ((Charges remaining in (Item being manipulated)) + 1)
      • Sound - Play PickUpItem <gen> at 100.00% volume, attached to (Hero manipulating item)
      • Unit - Replace (Hero manipulating item) with a Bereta 9000S using The old unit's life and mana
      • Special Effect - Create a special effect attached to the weapon of (Last replaced unit) using pistol2.MDX
      • Unit - Change color of (Last replaced unit) to Black
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Last replaced unit)) Equal to Player 1 (Red)
        • Then - Actions
          • Set RedHero = (Last replaced unit)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Last replaced unit)) Equal to Player 2 (Blue)
        • Then - Actions
          • Set BlueHero = (Last replaced unit)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • .....
      • Selection - Add (Last replaced unit) to selection for (Owner of (Last replaced unit))


    Side note its based on use the item in the inventory.

    But you have only to change the event. You will need an trigger for every Unit you want to switch or improve. For example you want to increase an Units Range 3 times. You will need 3 triggers. The Unit may use/acquire the item but it wont be replaced. If you want my whole trigger i ll post it.
     
  14. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Here's a trigger, just to show how it should look like:
    • Events
    • Whatever...
    • Conditions
    • Same...
    • Actions:
    • Set OrigUnit = Triggering Unit (or whatever, depends on the event)
    • For each integer from 1 to 6 do Actions
    • Set Item[Integer A] = Item in slot (Integer A) for OrigUnit
    • ..
    • Unit - Replace OrigUnit with a <newunittype>
    • Set NewUnit = Last Replaced Unit
    • For each integer from 1 to 6 do Actions:
    • Hero - Create a Item[Integer A] for NewUnit at slot (Integer A)
     
  15. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    Paskovich, srry to say but that guide is not very helpful for me, i tryed to get it working for about an hour, but since i am not an expert with triggers, i just couldn't figure it out srry >.< but GOdless yours was good ty
     
  16. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    Ok, so godless i was looking at your trigger more thuroughly and i decided that infact it was not that informative and also not helpful in my situation, all i want to do is when my unit picks up a pistol, have him be replaced by another unit and have his inventory be transfered over....? soo i don['t think i need the play sound stuff? i just need the most simplistic version of this trigger that i could get, mostly because i am not that good at triggers...
     
  17. Xelephant

    Xelephant

    Joined:
    Feb 2, 2005
    Messages:
    215
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Okay here we go ill comment all stuff so you get an idea of the trigger. So here is the very simple version.

    • Change to Bereta 9000S
      • Events
        • Unit - A unit Acquires an item
      • Conditions
        • (Unit-type of (Hero manipulating item)) Not equal to Beretta 9000S
        • (Item-type of (Item being manipulated)) Equal to Beretta 9000S
      • Actions
        • -------- The Condition is checking if the Units is already the Unit it changes to --------
        • Set lifetrans[(Player number of (Owner of (Triggering unit)))] = (Percentage life of (Hero manipulating item))
    • -------- lifetrans is an real array--------
      • Unit - Replace (Hero manipulating item) with a Beretta 9000S using The old unit's relative life and mana
    • -------- Replaces you Unit --------
      • Set Hero[(Player number of (Triggering player))] = (Last replaced unit)
    • -------- Hero is an Unit Array --------
      • Unit - Set life of (Last replaced unit) to lifetrans[(Player number of (Owner of (Triggering unit)))]%
    • -------- This is need to set the hp--------
      • Selection - Select (Last replaced unit) for (Owner of (Last replaced unit))
    • -------- Selects you hero again, when replaced the selection is gone --------

    You can leave out the lifetrans stuff, but there is an bug with the hp ammount which can be abused.

    Feel free to ask me on icq on further details. You wont need to save the items, the new Unit will have the old items. If you have trouble doing it, i ll do an example map for you so you can copy paste the Trigger.
     
    Last edited: Mar 17, 2007
  18. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    I GOT IT WORKING wooo hooo lol, just combined some other hints really early on about getting item invetory arrays and stuff, with Godless's guide and it works fine, replaces it and holds old items w00t ty guys
     
  19. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Ok, but don't doublepost that much!!
     
  20. fargs

    fargs

    Joined:
    Sep 15, 2005
    Messages:
    35
    Resources:
    0
    Resources:
    0
    i was just telling the current problem, i didn't mean it to be a double post or anything