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

assigning item drop set to units that do not exist yet

Status
Not open for further replies.
Level 4
Joined
Apr 29, 2020
Messages
59
I am working on a mini game where every time you kill an enemy, several more spawn nearby. I cant seem to be able to figure out how to assign an item drop set to a unit upon unit creation. I can only figure out how to give them an item to drop 100% of the time (unit dies,_, create item at location of dying unit). Even if i could find a way to make my own artificial drop sets and say something like "when unit dies, provided unit is of certain type, drop an item 50% of the time at location of dying unit" that would be great, but i cannot find a percentage function like this. Best case scenario is being able to assign a drop set that i have already created to the new unit upon unit creation. anyone know how to achieve this?
 
Level 24
Joined
Feb 9, 2009
Messages
1,787
In the conditions, look for either real or integer and then search math for random number, set it to 1 - 100 and make it less than or equal to X, X being the rate of success.

If you look at my most recent spell Ice strike, you can view a trigger on its spell page.
 
Level 4
Joined
Apr 29, 2020
Messages
59
In the conditions, look for either real or integer and then search math for random number, set it to 1 - 100 and make it less than or equal to X, X being the rate of success.

If you look at my most recent spell Ice strike, you can view a trigger on its spell page.

Ah the function is under conditions, not actions. Thank you :) ... so this will def work for me, however, is there any way to assign an already created Item Drop Set? That would be much more user friendly for me
 
Level 18
Joined
Jan 1, 2018
Messages
728
Ah the function is under conditions, not actions. Thank you :) ... so this will def work for me, however, is there any way to assign an already created Item Drop Set? That would be much more user friendly for me
When you create an item table, it auto-generates a function to handle dropping the item(s), so you could call this function in your unit dies trigger using custom script: call ItemTable000005_DropItems().
Of course, using this approach you need to know the index of your item table. In the example it's 5.
 
Level 4
Joined
Apr 29, 2020
Messages
59
When you create an item table, it auto-generates a function to handle dropping the item(s), so you could call this function in your unit dies trigger using custom script: call ItemTable000005_DropItems().
Of course, using this approach you need to know the index of your item table. In the example it's 5.
ok, thank you. this is what im looking for, although i dont really know what im doing. ima look into this and see if i can get it to work :) thx
 
Level 4
Joined
Apr 29, 2020
Messages
59
When you create an item table, it auto-generates a function to handle dropping the item(s), so you could call this function in your unit dies trigger using custom script: call ItemTable000005_DropItems().
Of course, using this approach you need to know the index of your item table. In the example it's 5.
oh man, i really have no idea how to get to where you got for using an item table in a script. could you walk me through it a little more in depth? sry, im a total newb
 
Level 18
Joined
Jan 1, 2018
Messages
728
oh man, i really have no idea how to get to where you got for using an item table in a script. could you walk me through it a little more in depth? sry, im a total newb
In the top menu: Advanced > Item Tables, create your tables (I never used this but it seems user friendly enough so you'll figure it out).
I don't think you can see anywhere in the menu what index a table has, so you have to keep track of that manually (by putting it in the name of the table). It starts at 0 and goes up one every time you create a table. The index of a deleted table does not seem to get recycled (in my test I created three tables (indices 0, 1, 2), deleted the second one (index 1), and created another one, which had index 3).
If you're not sure about the index your table has, you can go to File > Export Script to see which tables exist (though it doesn't show the name you give it, so it may be hard to know what function corresponds to what table). I know it doesn't sound very user-friendly so far but I guess we're kinda abusing the system with this approach.

Anyways, when you have your item tables set up, all you have to do is call it in your trigger, for example something like this:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: set bj_lastDyingWidget = null
      • 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
          • Custom script: call ItemTable000000_DropItems()
        • Else - Actions
          • Custom script: call ItemTable000003_DropItems()
 
Last edited:
Level 4
Joined
Apr 29, 2020
Messages
59
In the top menu: Advanced > Item Tables, create your tables (I never used this but it seems user friendly enough so you'll figure it out).
I don't think you can see anywhere in the menu what index a table has, so you have to keep track of that manually (by putting it in the name of the table). It starts at 0 and goes up one every time you create a table. The index of a deleted table does not seem to get recycled (in my test I created three tables (indices 0, 1, 2), deleted the second one (index 1), and created another one, which had index 3).
If you're not sure about the index your table has, you can go to File > Export Script to see which tables exist (though it doesn't show the name you give it, so it may be hard to know what function corresponds to what table). I know it doesn't sound very user-friendly so far but I guess we're kinda abusing the system with this approach.

Anyways, when you have your item tables set up, all you have to do is call it in your trigger, for example something like this:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • 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
          • Custom script: call ItemTable000000_DropItems()
        • Else - Actions
          • Custom script: call ItemTable000003_DropItems()
Holy crap. Thank you so much :) i didnt even know i could extract the script. I have been able to find everything you showed me and i think i can take it from here. Are there any bugs or anything weird i need to be aware of?
 
Level 4
Joined
Apr 29, 2020
Messages
59
Holy crap. Thank you so much :) i didnt even know i could extract the script. I have been able to find everything you showed me and i think i can take it from here. Are there any bugs or anything weird i need to be aware of?
So i have been able to get it to work, but there's a catch: It only works for one instance and then it seems to turn itself off. I tried using Triggers>run trigger, but i dont think thats going to work. do you have any suggestions on how to make this a reoccurring trigger?
 
Level 18
Joined
Jan 1, 2018
Messages
728
Holy crap. Thank you so much :) i didnt even know i could extract the script. I have been able to find everything you showed me and i think i can take it from here. Are there any bugs or anything weird i need to be aware of?
I never tried this approach myself, since I never use item tables, so I'm not aware of any potential bugs/issues this may have.

So i have been able to get it to work, but there's a catch: It only works for one instance and then it seems to turn itself off. I tried using Triggers>run trigger, but i dont think thats going to work. do you have any suggestions on how to make this a reoccurring trigger?
Don't know what could be going wrong without more information. Can you post your trigger?

EDIT: I think I know what may be the issue, I have added a custom script to the example trigger in my previous post: set bj_lastDyingWidget = null.
EDIT2: Ignore the above, I just realized the cause is actually at the bottom of the ItemTable function: call DestroyTrigger(GetTriggeringTrigger()). This is done because normally you apply item drop tables for pre-placed units, and it will create one trigger per unit. That's why it only works once.
I (again) have not tested it, but if you change it to this, it should work:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: local trigger t = CreateTrigger()
      • 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
          • Custom script: call TriggerAddAction(t, function ItemTable000000_DropItems)
        • Else - Actions
          • Custom script: call TriggerAddAction(t, function ItemTable000003_DropItems)
      • Custom script: call TriggerExecute(t)
      • Custom script: set t = null
 
Last edited:
Level 4
Joined
Apr 29, 2020
Messages
59
I never tried this approach myself, since I never use item tables, so I'm not aware of any potential bugs/issues this may have.


Don't know what could be going wrong without more information. Can you post your trigger?

EDIT: I think I know what may be the issue, I have added a custom script to the example trigger in my previous post: set bj_lastDyingWidget = null.
EDIT2: Ignore the above, I just realized the cause is actually at the bottom of the ItemTable function: call DestroyTrigger(GetTriggeringTrigger()). This is done because normally you apply item drop tables for pre-placed units, and it will create one trigger per unit. That's why it only works once.
I (again) have not tested it, but if you change it to this, it should work:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: local trigger t = CreateTrigger()
      • 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
          • Custom script: call TriggerAddAction(t, function ItemTable000000_DropItems)
        • Else - Actions
          • Custom script: call TriggerAddAction(t, function ItemTable000003_DropItems)
      • Custom script: call TriggerExecute(t)
      • Custom script: set t = null
excellent! thank you! ... so after doing a bunch of digging last night i discovered the reason to be exactly what you found. I couldnt figure out how to fix it though so i went and learned how to make my own custom drop sets in triggers. it's a little more work than what i wanted but all in all it wasnt so bad to just use the custom method. what you have presented does make sense but im worried that its a hard code thing in JASS that i would need to manipulate in another way (just a guess, i really dont understand too much about how all of this works only that every time i run into a hard coded issue i tend to lose :D ... but thank you for checking this out for me) again, thank you for all your help you really did get me going in the right direction and now im cooking with gas on my project and things are coming together smoothly. thanks much :)
 
Status
Not open for further replies.
Top