• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Created units can drop items?

Status
Not open for further replies.
Level 9
Joined
Apr 19, 2011
Messages
447
If I create a unit with a trigger (Unit - Create)...
Is there a way to make that unit drop one or more items when it dies?
If the unit is already in the map, it's easy to do that, but when the unit is created with triggers...
How can I do that?

Regards
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,232
Using simlar but more generic triggers than the ones the preplaced units uses.

The basics.
1. Detect when a valid unit dies (hint, use the unit death event).
2. Calculate the items that should drop (from a table or some data structure).
3. Create one or more items at the position of the dieing unit.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
So you're making an Item Table but based it from the not-pre-defined-unit ?
Well, you can also use this:
  • Add To Unit Group
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • Unit Group - Add (Triggering unit) to UnitGroup[1]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Knight
            • Then - Actions
              • Unit Group - Add (Triggering unit) to UnitGroup[2]
            • Else - Actions
This way, you can make your own "Item Table" by referring to the "Unit Group" using array to define its Item Table Group

Event - A unit enters (Playable map area) = This Event can be related to your "Unit - Create"
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,232
Or he could just bind a item table object to a unit type via hashtables and so from the unit type of the dieing unit get an item table which then gets evaluated to roll some items from.
O(1) efficency and only 2 places where code runs (map initialization and on unit death).

The above poster's idea runs code on map initialization, unit creation and unit death as well as requires code structures with an order of O(n) where n is the number of unit types supported.
 
Level 9
Joined
Apr 19, 2011
Messages
447
Thanks all of you for answering.
@Dr Super Good: I've never used hashtables before... Can you tell me what they are used for? How can I used them?

@defskull: The way that Dr Super Good seems to be easier and more efficient (as it uses less code). Anyway, thanks for your answer.

Regards
 
Level 19
Joined
Apr 10, 2010
Messages
2,789
Try using this:
  • Unit Spawn
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Set TempLoc = (Random point in (Playable map area))
      • Unit - Create 1 Gnoll for Neutral Hostile at TempLoc facing Default building facing degrees
      • Hero - Create Potion of Healing and give it to (Last created unit)
      • Custom script: call RemoveLocation (udg_TempLoc)
Make potion of healing the item you want and gnoll the unit you want. Make sure you add to that unit (gnoll) ability unit inventory (human) or any other unit inventory and delete all the techtree requirements. Also make the item which they carry dropable by making the field dropped when carrier dies to true by checking it.
 

Attachments

  • testmap.w3x
    12.4 KB · Views: 56
Level 33
Joined
Mar 27, 2008
Messages
8,035
@Blindman
It will look weird if you click on the unit and see item(s) on its list, LOL
It's like, pre-determined fate for that unit to drop the item
It's not fun :)
It is better as "chances" such as:

10% chance to drop Item A
5% chance to drop Item B
1% chance to drop Item C

This is more epic
 
there was a guide there to use it without vJASS/jass knowledge (and there's an example that could be copy-pasted then just edited)... you would just need to follow the instructions [the ability to follow instructions is actually the only requirement]...

or I could also give you a GUI example on how to use it (though it would be using the Custom scripts action, so its actually better to just use the normal jass...)

@Blindman - that really isn't a good example as the unit should always have an inventory if he uses that... its still better to use DSGs idea, which is basically how you do an Item Drop system...

anyway, I've also outlined the basic idea on a previous post, if you ever want to do it urself (though you would need hashtable knowlegde for that unless you want to create 1 trigger per unit rawcode, which is inefficient)... ^_^
 
Level 9
Joined
Apr 19, 2011
Messages
447
Using simlar but more generic triggers than the ones the preplaced units uses.

The basics.
1. Detect when a valid unit dies (hint, use the unit death event).
2. Calculate the items that should drop (from a table or some data structure).
3. Create one or more items at the position of the dieing unit.

After reading all of your posts, I used this basics to create the drop system without hashtables and without Jass.
It's a bit inefficient, but it makes what I want. I made one trigger for each type of monster (afortunatelly, they are only 5). Then I made the system using a random variable to create the probability of dropping each item. As I said, it's inefficient, but it's easy to do once you know how to do it.

Thanks for your advise.

Regards
 
Add the unit created to a unit group.
On the event a unit in that unit group dies
Randomize a variable between (example) 1 and 3

If 1 - drop A
If 2 - drop B
If 3 - drop C

Just created a point at the location of the dead unit, then drop the item there.
*Sigh* and because it's warcraft 3 don't forget to delete the point afterwards :S
If you use that, it'll be a 33.333~% chance for each item to drop.
 
You guys overcomplicate the simplest things. I mean seriously, Ive seen triggers here that are very complicated and don't really make any sense. This trigger is simple and always works. ALWAYS.
EVENT:
Generic Unit Event: Unit Dies
Action:
Make Hero Drop Item: Drop Item Carried By Triggering Unit in Slot 1 of Dying Unit.
Make Hero Drop Item: Drop Item Carried By Triggering Unit in Slot 2 of Dying Unit.
Make Hero Drop Item: Drop Item Carried By Triggering Unit in Slot 3 of Dying Unit.
Make Hero Drop Item: Drop Item Carried By Triggering Unit in Slot 4 of Dying Unit.
Make Hero Drop Item: Drop Item Carried By Triggering Unit in Slot 5 of Dying Unit.
Make Hero Drop Item: Drop Item Carried By Triggering Unit in Slot 6 of Dying Unit.

And yes the hero actions do work on units as long as its something like inventory. Of course the stat changes don't work on units. Also keep in mind that if you want it for a specific unit type, just add a condition that says unit type of dying unit= type of unit you want.

Using simlar but more generic triggers than the ones the preplaced units uses.

The basics.
1. Detect when a valid unit dies (hint, use the unit death event).
2. Calculate the items that should drop (from a table or some data structure).
3. Create one or more items at the position of the dieing unit.

And seriously: What is the point of those steps? Creating the triggers for those would cause lag.

If you aren't convinced, DL my test map just to prove it.
 

Attachments

  • Test001.w3x
    23.6 KB · Views: 51
Because your method will only work if the unit has an inventory (or requires the creator to add the inventory ability to the unit), and it also means that you can only have up to 6 item drops from a unit...

Also, what if the unit can drop an item which gives bonuses (like attack damage bonus etc), but the unit itself shouldn't be affected? Since the item should be in the inventory of that unit, the item will give its bonuses to that unit, ALWAYS... and that is a VERY BAD idea...

while our methods enable you to add a huge amount of item to the drop pool, and its a lot more flexible than yours... and creating them hardly causes any lags (if they cause lag on yours, then its probably due to inefficient coding or lots of leaks)... check my IDS for example...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,232
And seriously: What is the point of those steps? Creating the triggers for those would cause lag.

How so? It would have a miss complexity of O(1). For units that should drop items, it simply recalls the item table, rolls some drops from it (these are all natives) and then just create the item at the dieing position. The code adds virtually no complexity to the map outside of a unit dieing. Further more, there is no net traffic so lag should be impossible even if it drops the frame rate (which is also impossible due to the efficiency).
 
Because your method will only work if the unit has an inventory (or requires the creator to add the inventory ability to the unit), and it also means that you can only have up to 6 item drops from a unit...

Also, what if the unit can drop an item which gives bonuses (like attack damage bonus etc), but the unit itself shouldn't be affected? Since the item should be in the inventory of that unit, the item will give its bonuses to that unit, ALWAYS... and that is a VERY BAD idea...

while our methods enable you to add a huge amount of item to the drop pool, and its a lot more flexible than yours... and creating them hardly causes any lags (if they cause lag on yours, then its probably due to inefficient coding or lots of leaks)... check my IDS for example...

Well if you don't care if the units get bonuses then it doesnt matter.

Plus if this guy means drop a random item, theres a very easy trigger for that to that doesnt require 90 triggers.

Also I guess whether you use my method or all these other methods truely depends on the map. There are maps where you want the units to get the bonuses. So really it all depends.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,232
Plus if this guy means drop a random item, theres a very easy trigger for that to that doesnt require 90 triggers.

Yes which is what we described. You use 1 trigger object bound to the generic death event which then check if the unit type has a hashtable entry (in a map of types to item tables). If not, fail. If it does then recall the item table object and then proceeded to roll items. You could also map an integer for the number of item rolls or use some other way to vary them (like depending on the killer's stats).

You can also provide bonuses to normal units by adding a serioies of +health, +damage and +armor abilities.
 
Yes which is what we described. You use 1 trigger object bound to the generic death event which then check if the unit type has a hashtable entry (in a map of types to item tables). If not, fail. If it does then recall the item table object and then proceeded to roll items. You could also map an integer for the number of item rolls or use some other way to vary them (like depending on the killer's stats).

You can also provide bonuses to normal units by adding a serioies of +health, +damage and +armor abilities.

Yeah I guess both systems are good. Just depends what type of map your making. Sorry I just thought the other ones were complex but further explanation has helped me realize that they aren't.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Some time has passed since the last post, but i've wanted to share what I think would work. There's a wide more "noobish" way to do it fully in GUI...

  • Creep Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in (Units owned by Neutral Hostile)) Equal to True <- This isn't really necessary.
    • Actions
      • Set Point2 = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Rabbit (Black Spider)
          • (Random integer number between 1 and 100) Equal to 12 <- This means 12% Chance to drop.
        • Then - Actions
          • Item - Create Health potion at (Point2)
        • Else - Actions
          • Another If/Then/Else with chance to drop another item... etc.
      • Custom script: call RemoveLocation (udg_Point2)
 
Status
Not open for further replies.
Top