• 🏆 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!

Possibility to assign Dropped item on death + Name of transmitting unit

Status
Not open for further replies.
Level 5
Joined
May 26, 2012
Messages
76
Hello!
I have a couple of quesitons regarding triggers:

1)Is it possible to assign an item which will be dropped on death to a particular unit reference via script?
If not, what is the most efficient way to do it? I would like to avoid creating it's own trigger for each unit(all of them are dynamically created)
It's located here in editor:
upload_2020-5-23_8-4-21.png

2) In Transmission from unit is it possible to display return unit name without creating additional string variable, storing the name and then using it in the transmission function? I can't find anything that looks like a "transmitting unit."
upload_2020-5-23_8-6-2.png

3) Also - it is possible to return an array index for particular reference without using Jass?
What I want to do:
Array is
0::UnitReference
I know UnitReference and I want to return "0" as integer.
 

Attachments

  • upload_2020-5-23_8-3-20.png
    upload_2020-5-23_8-3-20.png
    12.8 KB · Views: 15

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
With a Unit Indexer you can save an Item-To-Be-Dropped and Item Recipient to any of your units. When that unit dies you can create it's saved Item and attempt to give it to the Item Recipient.
  • IDrop Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Unit - Create 1 Paladin for Player 1 (Red) at (Center of 1 <gen>) facing Default building facing degrees
      • Set VariableSet Paladin = (Last created unit)
      • Unit - Create 1 Archmage for Player 1 (Red) at (Center of 2 <gen>) facing Default building facing degrees
      • Set VariableSet Archmage = (Last created unit)
      • -------- --------
      • -------- Make the Paladin drop an Item for the Archmage --------
      • Set VariableSet CV = (Custom value of Paladin)
      • Set VariableSet IDrop_ItemType[CV] = Claws of Attack +15
      • Set VariableSet IDrop_Recipient[CV] = Archmage
  • IDrop Unit Dies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set VariableSet CV = (Custom value of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • IDrop_Recipient[CV] Not equal to No unit
        • Then - Actions
          • Hero - Create IDrop_ItemType[CV] and give it to IDrop_Recipient[CV]
          • Game - Display to (All players) for 15.00 seconds the text: ((Name of (Triggering unit)) + ( has been slain. It's loot goes to: + (Name of IDrop_Recipient[CV])))
        • Else - Actions
      • -------- Do this last, resetting the IDrop_Recipient for this custom value --------
      • Set VariableSet IDrop_Recipient[CV] = No unit
The only catch with the Unit Indexer is that your units need to be created AFTER Map Initialization in order to have their Custom Values adjusted by the system.

The Unit Indexer provides an Event for this. This Event runs right after Map Initialization:
  • Game - UnitIndexEvent becomes Equal to 3.00
But you could also use something like this which is what I did in my example map:
  • Time - Elapsed game time is 0.00 seconds
Test Map:
Type "paladin" to kill the Paladin, rewarding the Archmage with an Item. Type "archmage" to kill the Archmage, rewarding no loot because it hasn't been assigned an IDrop_Recipient.
 

Attachments

  • Item Drop Example 1.w3m
    22.2 KB · Views: 18
Last edited:
Level 5
Joined
May 26, 2012
Messages
76
My map doesn't have pre-placed units(they are all removed(stored in arrays on Map initialization) and then replaced by dynamic references because I need to reset the whole map a couple of times). So I don't see the point in incorporating unit indexer (yet).
So I guess I can use custom value for this anyway - I can set Custom value 1 for "Health potion", 2 for "Mana potion", 3 for "Quest item 1" etcs. and then use "OnDeath" trigger. as you advised, check for that value and give the appropriate item.
You're being really helpful.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Is the Item that's dropped always given to the Killing unit? Because I was under the impression that you wanted it to be given to some other unit that you didn't have a reference to in the Death trigger.

If that's the case then the triggers can be simplified to this:

When creating a unit, set it's Item Drop.
  • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
    • Set VariableSet IDrop_ItemType[(Custom value of (Last created unit))] = Claws of Attack +15
Since the Killing unit gets the Item, there's no need for the Item_Recipient variable.
  • Unit Dies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Hero - Create IDrop_ItemType[(Custom value of (Triggering unit))] and give it to (Killing unit)
Anyway, I guess you don't need the Unit Indexer if you only wish to save this single value to a unit, but in my opinion it's great to have. It essentially allows you to have more than one Custom Value on a unit, instead of being limited to only one.

You could also setup Random drops like this:
  • Setup Droppable Items
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Droppable_Items[1] = Potion of Greater Healing
      • Set VariableSet Droppable_Items[2] = Circlet of Nobility
      • Set VariableSet Droppable_Items[3] = Claws of Attack +6
  • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
    • Set VariableSet RandomRoll = (Random integer number between 1 and 3)
    • Set VariableSet IDrop_ItemType[(Custom value of (Last created unit))] = Droppable_Items[RandomRoll]
 
Last edited:
Level 5
Joined
May 26, 2012
Messages
76
I wanted to add items to some units(for instance, here I created 3 units and gave one of them a healing rune on death)
I ended up using this:


upload_2020-5-23_10-32-30.png


upload_2020-5-23_10-30-22.png


upload_2020-5-23_10-29-18.png


I agree that Unit indexer is a great system. For now I don't need it but I'll keep it in mind.
 

Attachments

  • upload_2020-5-23_10-31-58.png
    upload_2020-5-23_10-31-58.png
    16 KB · Views: 12
Status
Not open for further replies.
Top