• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Transfer item to another unit - Trigger

Status
Not open for further replies.
Level 1
Joined
Jan 7, 2022
Messages
3
Hello, i want to make transfer item trigger (miner to craftsman). My method is using different abilities, i made 2 (transfer item 1 and transfer item 2). But when it cast transfer item 1 (slot 1 transfer) it transfer slot 2 too even i made a condition. Same for second ability, instead transfering only item 2, it transfer item from slot 1 too. Any idea to improve my trigger to work propely? One solution of mine is to remain with one ability and transfer items only with slot 1, but i wish to figure out with multiple abilities. That will helps in future i will add more abilities to units.
I want to mention, i've search for similar thread but i did not find anything. I am beginner on WE. Working for 2 weeks :)


tramsferitem.png
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
If you need help with an existing trigger you should post in the Triggers & Scripts forum. I moved the thread for you. World Editor Help Zone is more for getting something started, IE: How would I create a trigger that gives each player 100 gold? It's also for questions about general use of the World Editor, IE: How can I raise the height of a Doodad? The two forums can blend together sometimes so it can be confusing.

Anyway, welcome to Hive :D You should read this: How To Post Your Trigger

Now let's talk about your trigger. So there's some important methods to use in order to make your life a lot easier when creating triggers.
I'm going to assume that there are multiple players in your map that have their own Hero/Miner, seeing as how most maps are designed in a way that the experience is pretty much the same for all non-Computer players. If that's the case, I recommend taking advantage of Variable arrays.

Here's an example of storing the Hero/Miner for Player 1 inside of Unit array variables. You can easily add more Players to this trigger by copying and pasting the Hero/Miner variable and changing the [Index] to the desired player's number. 1 = Red, 2 = Blue, 3 = Teal, etc...
  • Setup Unit Variables
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- The [Index] represents the Player Number, so Hero[1] is Player 1's hero: --------
      • Set Hero[1] = Mountain King 0000 <gen>
      • Set Miner[1] = Peasant 0001 <gen>

Now in the Transfer Items trigger, we can easily make this trigger work for EVERYONE without having to reference a specific player:
  • Transfer Items
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Transfer 1
        • Then - Actions
          • Set TransferPN = (Player number of (Owner of (Triggering unit)))
          • Hero - Give (Item carried by Miner[TransferPN] in slot 1) to Hero[TransferPN]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Ability being cast) Equal to Transfer 2
            • Then - Actions
              • Set TransferPN = (Player number of (Owner of (Triggering unit)))
              • Hero - Give (Item carried by Miner[TransferPN] in slot 2) to Hero[TransferPN]
            • Else - Actions
Note: You can use the Give Item function to easily transfer items. Also, the Do nothing function is unnecessary, you can leave the Else - Actions empty, it's perfectly fine.

So TransferPN is an Integer variable which gets Set to the Player number of whoever cast the ability -> (Owner of Triggering unit).
(Triggering unit) is the same thing as (Casting unit) in this case. So if Player 3 cast the ability then TransferPN will be Set to 3.
Then we attempt to give the item carried by Miner[3] to Hero[3]. These two unit Variables need to be Set in our Setup Unit Variables trigger at the start of the game in order for them to work.

Note: TransferPN isn't actually necessary, it's just a shortcut to make your life easier. It can also be more efficient if you reference it multiple times in your trigger.
This is what the Action would look like without TransferPN, ugly, inefficient, and difficult to setup:
  • Hero - Give (Item carried by Miner[(Player number of (Owner of (Triggering unit)))] in slot 1) to Hero[(Player number of (Owner of (Triggering unit)))]

So with this design method it becomes A LOT easier to make "generic" triggers. From here on out, all of your triggers can reference Hero[] and Miner[] instead of Mountain King 0045 <gen>. This should remove the need to have multiple copies of the same trigger since 1 trigger will work for everyone.

Some other useful things to do:
  • Store all of your Heros/Miners in specific Unit Groups so you can easily access all of them at any time. Look into the Pick Every Unit function.
  • Store All User players, All active User players (players that haven't left the game yet), and Computer players in Player Groups so you can easily reference all of them at any time. Look into the Pick Every Player function.
  • Try to avoid reusing Variables like TransferPN in other triggers, there are certain situations where this may cause a conflict. This is why I named it specific to that trigger.
  • Avoid redundancy whenever possible. MOST of the time you can use Variable arrays / 1-2 Triggers to make something that will work for everyone.
  • Plan ahead before diving into your trigger. Ask yourself, "Can I use any of my existing variables like Hero/Miner or any of my Unit Groups/Player Groups?". A properly designed map will have a lot of the Variables already setup beforehand which should make the triggering process a lot smoother.
 
Last edited:
Status
Not open for further replies.
Top