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