• 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] Need to Switch out one unit for another

Status
Not open for further replies.
Level 3
Joined
Sep 15, 2005
Messages
35
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
 
Level 6
Joined
Feb 2, 2005
Messages
205
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.
 
Level 2
Joined
Jan 14, 2006
Messages
3
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.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
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.
 
Level 11
Joined
Jul 12, 2005
Messages
764
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.
 
Level 3
Joined
Sep 15, 2005
Messages
35
But what about the <unit> factor?

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.

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
 
Level 6
Joined
Feb 2, 2005
Messages
205
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...
 
Level 6
Joined
Feb 2, 2005
Messages
205
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.
 
Level 11
Joined
Jul 12, 2005
Messages
764
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.
 
Level 6
Joined
Feb 2, 2005
Messages
205
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.
 
Level 11
Joined
Jul 12, 2005
Messages
764
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)
 
Level 3
Joined
Sep 15, 2005
Messages
35
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
 
Level 3
Joined
Sep 15, 2005
Messages
35
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...
 
Level 6
Joined
Feb 2, 2005
Messages
205
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:
Level 3
Joined
Sep 15, 2005
Messages
35
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
 
Level 6
Joined
Feb 2, 2005
Messages
205
Well i looked into it too. It works fine when you use altered Heros, it wont work on normal Units with added Inventory. So if you use normal Units with Inv then you have to do the Item Array, if you use altered Heros in the map then you wont need the Array.
 
Level 11
Joined
Jul 12, 2005
Messages
764
Ok, according to Godless, you'll have to use the array-structure, here's the less comlicated one (without loop):
  • Events
  • Whatever...
  • Conditions
  • Same...
  • Actions:
  • Set OrigUnit = Triggering Unit (or whatever, depends on the event)
  • Set Item[1] = Item in slot 1 for OrigUnit
  • Set Item[2] = Item in slot 2 for OrigUnit
  • Set Item[3] = Item in slot 3 for OrigUnit
  • Set Item[4] = Item in slot 4 for OrigUnit
  • Set Item[5] = Item in slot 5 for OrigUnit
  • Set Item[6] = Item in slot 6 for OrigUnit
  • ..
  • Unit - Replace OrigUnit with a <newunittype>
  • Set NewUnit = Last Replaced Unit
  • Hero - Create a Item[1] for NewUnit at slot 1
  • Hero - Create a Item[2] for NewUnit at slot 2
  • Hero - Create a Item[3] for NewUnit at slot 3
  • Hero - Create a Item[4] for NewUnit at slot 4
  • Hero - Create a Item[5] for NewUnit at slot 5
  • Hero - Create a Item[6] for NewUnit at slot 6
'Item' is an item-type variable, big surprise!!
I don't know what is so hard about it...
 
Level 3
Joined
Sep 15, 2005
Messages
35
Rofl, because srry i am just not that experienced with triggers, sorry thats whats so hard about it, and you use descriptions like "whatever" and "or whatever, depends on event"..... Ty lol so now u know whats so hard about it? I'm a noob get it? it needs to be laid out in front of me so i can read it quite plainly.
 
Level 6
Joined
Feb 2, 2005
Messages
205
Well you can add those lines to the trigger i have you. You will have to add like below. I didnt create the hole thingy, but i hope you get the idea.
  • Change from Worker to footy
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Unit-type of (Hero manipulating item)) Not equal to Footy
      • (Item-type of (Item being manipulated)) Equal to Armor
    • Actions
      • Set lifetrans[(Player number of (Owner of (Triggering unit)))] = (Percentage life of (Hero manipulating item))
      • Set Items[1] = (Item-type of (Item carried by (Triggering unit) in slot 1))
  • -------- Save The Item in Slot 1 into the array --------
    • Set Items[2] = (Item-type of (Item carried by (Triggering unit) in slot 2))
  • -------- Save The Item in Slot 2 into the array (guess the rest ;) )--------
    • Unit - Replace (Hero manipulating item) with a Footy using The old unit's relative life and mana
    • Set Hero[(Player number of (Triggering player))] = (Last replaced unit)
    • Hero - Create Items[1] and give it to Hero[(Player number of (Owner of (Triggering unit)))]
  • -------- "loads" the 1st Item and give it to hero --------
    • Hero - Create Items[2] and give it to Hero[(Player number of (Owner of (Triggering unit)))]
  • -------- "loads" the 2nd Item and give it to hero --------
    • Unit - Set life of (Last replaced unit) to lifetrans[(Player number of (Owner of (Triggering unit)))]%
    • Selection - Select (Last replaced unit) for (Owner of (Last replaced unit))
 
Status
Not open for further replies.
Top