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

drop random item from inventory on death!

Status
Not open for further replies.
Level 6
Joined
Aug 30, 2005
Messages
161
ok i am making a map and i need so when a hero dies it drops a random item from its inventory.

i have the variable with the item types set, there is a total of 12 items that i want the heroes to drop if it carrying one of them.

for example if the hero has the fire card item (#1) and the blizzard card item (#2) i want him to drop one of them at random upon its death.... i have been trying to work on this trigger for 3 days now, i cant seem to make it work can anyone help me?
 
Level 6
Joined
Aug 30, 2005
Messages
161
ok u are not reading i dont want him to drop a random item from its inventory i want him to drop a random item FROM THE LIST from his inventory provided that he has an item from that inventory!!!, not to just drop an item at random i already know hwo to do that but not with the variables i mentioned before
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
I wonder why the hell Blizzard didn't implement conditional loops in GUI. Well, in JASS solution is pretty simple but we can solve it in GUI as well. First of all, you will need a new integer variable, which I will call test in this case. As you know, FORS increment the variable at each repeat until it reaches a certain value. Well, in our case we could keep the for looping until we find the desired item, and if we find it then all we have to do is set the value of the "variable of the loop" (in our case test) greater than the final value of the loop. Ok, enough blabla. Let's see:

For test from 1 to 3 do actions
set random = (Random Integer between 1 and 12)
IF HERO_HAS_ITEM (you need to check if the hero doesn't have the item into one of his slots and if he does you will have to store it => a series of ifs but I am interested in this case in the outern IF) THEN
-> set test = 10
-> Drop Item from (Dying Unit)
ELSE
-> set test = 1

That should do it. Normally it should work.

~Daelin
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
Ok, this code was much more difficult than I expected. You will surely need the map to get things working. But anyway, here is the code. I will explain the variables after.

Code:
Initialize Items
    Events
    Conditions
    Actions
        -------- Just some dummy items. Change them to whatever you want into your map. --------
        Set Var_Items[1] = Shadow Orb +1
        Set Var_Items[2] = Shadow Orb +2
        Set Var_Items[3] = Shadow Orb +3
        Set Var_Items[4] = Shadow Orb +4
        Set Var_Items[5] = Shadow Orb +5
        Set Var_Items[6] = Shadow Orb +6
        Set Var_Items[7] = Shadow Orb +7
        Set Var_Items[8] = Shadow Orb +8
        Set Var_Items[9] = Shadow Orb +9
        Set Var_Items[10] = Shadow Orb +10
        Set Var_Items[11] = Shadow Orb Fragment
        Set Var_Items[12] = Soul

Code:
Item Drop
    Events
        Unit - A unit Dies
    Conditions
    Actions
        -------- Each time an unit dies the Var_Items array is messed up, so we have to rearrange it. --------
        Trigger - Run Initialize Items <gen> (ignoring conditions)
        Set Var_ItemPosition = 0
        Set Var_MaxVal = 12
        For each (Integer Var_Stop) from 1 to 3, do (Actions)
            Loop - Actions
                -------- Let's do the Randomization --------
                Set Var_Randomize = (Random integer number between 1 and Var_MaxVal)
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Var_Randomize Equal to Var_MaxVal
                    Then - Actions
                        Set Var_MaxVal = (Var_MaxVal - 1)
                    Else - Actions
                        -------- Swap --------
                        Set Var_Auxiliary = Var_Items[Var_MaxVal]
                        Set Var_Items[Var_MaxVal] = Var_Items[Var_Randomize]
                        Set Var_Items[Var_Randomize] = Var_Auxiliary
                        Set Var_Randomize = Var_MaxVal
                        Set Var_MaxVal = (Var_MaxVal - 1)
                -------- Check if the item exists on the hero --------
                If ((Item-type of (Item carried by (Dying unit) in slot 1)) Equal to Var_Items[Var_Randomize]) then do (Set Var_ItemPosition = 1) else do (Do nothing)
                If ((Item-type of (Item carried by (Dying unit) in slot 2)) Equal to Var_Items[Var_Randomize]) then do (Set Var_ItemPosition = 2) else do (Do nothing)
                If ((Item-type of (Item carried by (Dying unit) in slot 3)) Equal to Var_Items[Var_Randomize]) then do (Set Var_ItemPosition = 3) else do (Do nothing)
                If ((Item-type of (Item carried by (Dying unit) in slot 4)) Equal to Var_Items[Var_Randomize]) then do (Set Var_ItemPosition = 4) else do (Do nothing)
                If ((Item-type of (Item carried by (Dying unit) in slot 5)) Equal to Var_Items[Var_Randomize]) then do (Set Var_ItemPosition = 5) else do (Do nothing)
                If ((Item-type of (Item carried by (Dying unit) in slot 6)) Equal to Var_Items[Var_Randomize]) then do (Set Var_ItemPosition = 6) else do (Do nothing)
                -------- Try to exit from the loop --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Var_ItemPosition Equal to 0
                    Then - Actions
                        Set Var_Stop = 1
                    Else - Actions
                        Set Var_Stop = 5
                        Hero - Drop (Item carried by (Dying unit) in slot Var_ItemPosition) from (Dying unit)
                 If (Var_MaxVal Equal to 0) then do (Set Var_Stop = 5) else do (Do nothing)

Yes, it's long and it sounds difficult. If you have ever programmed before it will be piece of cake, but if you haven't... Anyway, here are the global variables:

Var_Items (Item_Type Array - size 13) - In this array you will store those items from which you are to choose the random to be dropped from the hero.
Var_Auxiliary (Item Type) - You will need it to make the swap inside the Var_Items array. If you wouldn't have done this, the loop could've been endless, in case in which the dying unit didn't have any of the items desired.
Var_Maxval (Integer) - Well, this is contributing at the trick I mentioned before. If initially you have 12 items in the array, once you check if the hero has an item, we have to eliminate it from the array. Maxval stores the total number of variables left in the array and if it is equal to 0 we get out of the loop.
Var_Randomize (Integer) - It is simply used for the randomization of the item dropped.
Var_Stop (Integer) - The variable about which I told you in my previous post. At that point I called it test.
Var_ItemPosition (Integer) - Once you found the item on the hero, you will need to store its position so that you can remove it from the hero. If the item isn't find, this variable will retain it's value to 0 (which I initialized at the beginning of the trigger).

That's all, so, if you need the map (thing which you will), PM me with your email adress..

~Daelin
 
Level 6
Joined
Aug 30, 2005
Messages
161
thanks!!!, perhaps ill make this i na different map as well and upload it into system i will give you full credit for it, but ill do that when i finish my map IF you havent done it yourself i bet there are people that have been wondering how to do that... and i really dont know why there isnt a looping trigger for this in the editor... once again THANKS!!!!!
 
Status
Not open for further replies.
Top