| 02-19-2006, 10:31 PM | #1 |
How can i have this prevent an item from dropping twice in the same drop? Here is my scripts: JASS://Item Table Functions function RanDistReset takes nothing returns nothing set udg_randDistCount = 0 endfunction function RanDistAddItem takes integer inID, real inChance returns nothing set udg_randDistID[udg_randDistCount] = inID set udg_randDistChance[udg_randDistCount] = inChance set udg_randDistCount = udg_randDistCount + 1 endfunction function RanDistChoose takes nothing returns integer local real sum = 0 local real chance = 0 local integer index local integer foundID = -1 local boolean done // No items? if (udg_randDistCount == 0) then return -1 endif // Find sum of all chances set index = 0 loop set sum = sum + udg_randDistChance[index] set index = index + 1 exitwhen index == udg_randDistCount endloop // Choose random number within the total range set chance = GetRandomReal(0.01, sum) // Find ID which corresponds to this chance set index = 0 set sum = 0 set done = false loop set sum = sum + udg_randDistChance[index] if (chance <= sum) then set foundID = udg_randDistID[index] set done = true endif set index = index + 1 if (index == udg_randDistCount) then set done = true endif exitwhen done == true endloop return foundID endfunction //number of drops Functions function DropDistReset takes nothing returns nothing set udg_dropDistCount = 0 endfunction function DropDistAddItem takes integer inID, real inChance returns nothing set udg_dropDistID[udg_dropDistCount] = inID set udg_dropDistChance[udg_dropDistCount] = inChance set udg_dropDistCount = udg_dropDistCount + 1 endfunction function DropDistChoose takes nothing returns integer local real sum = 0 local real chance = 0 local integer index local integer foundID = -1 local boolean done // No items? if (udg_dropDistCount == 0) then return -1 endif // Find sum of all chances set index = 0 loop set sum = sum + udg_dropDistChance[index] set index = index + 1 exitwhen index == udg_dropDistCount endloop // Choose random number within the total range set chance = GetRandomReal(0.01, sum) // Find ID which corresponds to this chance set index = 0 set sum = 0 set done = false loop set sum = sum + udg_dropDistChance[index] if (chance <= sum) then set foundID = udg_dropDistID[index] set done = true endif set index = index + 1 if (index == udg_dropDistCount) then set done = true endif exitwhen done == true endloop return foundID endfunction //number of items chance table function chance_table takes nothing returns integer local integer ID = 0 call DropDistReset( ) call DropDistAddItem( 0, 0.50 ) call DropDistAddItem( 1, 30.00 ) call DropDistAddItem( 2, 30.00 ) call DropDistAddItem( 3, 25.00 ) call DropDistAddItem( 4, 5.00 ) call DropDistAddItem( 5, 0.50 ) call DropDistAddItem( 6, 0.12 ) set ID = DropDistChoose( ) return ID endfunction //Drop Tables function Drop_Table_0001 takes nothing returns integer local integer itemID = 0 call RanDistReset( ) call RanDistAddItem( 'I000', 0.39 ) call RanDistAddItem( 'I001', 0.03 ) call RanDistAddItem( 'I002', 0.06 ) call RanDistAddItem( 'I003', 0.06 ) call RanDistAddItem( 'I004', 0.06 ) call RanDistAddItem( 'I005', 0.03 ) call RanDistAddItem( 'I006', 0.03 ) call RanDistAddItem( 'I007', 0.03 ) call RanDistAddItem( 'I008', 12.41 ) call RanDistAddItem( 'I009', 2.21 ) call RanDistAddItem( 'I00A', 0.49 ) set itemID = RanDistChoose( ) return itemID endfunction JASS:function Trig_dreadlord_dies_Conditions takes nothing returns boolean if ( not ( GetUnitTypeId(GetDyingUnit()) == 'H000' ) ) then return false endif return true endfunction function Trig_dreadlord_dies_Func005C takes nothing returns boolean if ( not ( udg_random != 0 ) ) then return false endif return true endfunction function Trig_dreadlord_dies_Actions takes nothing returns nothing local integer itemID call CreateNUnitsAtLoc( 1, 'h001', Player(0), GetUnitLoc(GetDyingUnit()), bj_UNIT_FACING ) set udg_tempunit = GetLastCreatedUnit() call UnitApplyTimedLifeBJ( 60, 'BTLF', udg_tempunit ) set udg_random = chance_table() if ( Trig_dreadlord_dies_Func005C() ) then set bj_forLoopAIndex = 1 set bj_forLoopAIndexEnd = udg_random loop exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd set itemID = Drop_Table_0001() call UnitAddItemByIdSwapped(itemID, udg_tempunit ) set bj_forLoopAIndex = bj_forLoopAIndex + 1 endloop else call RemoveUnit( udg_tempunit ) endif endfunction //=========================================================================== function InitTrig_dreadlord_dies takes nothing returns nothing set gg_trg_dreadlord_dies = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_dreadlord_dies, EVENT_PLAYER_UNIT_DEATH ) call TriggerAddCondition( gg_trg_dreadlord_dies, Condition( function Trig_dreadlord_dies_Conditions ) ) call TriggerAddAction( gg_trg_dreadlord_dies, function Trig_dreadlord_dies_Actions ) endfunction |
| 02-19-2006, 10:43 PM | #2 |
That requires some modiffying on the function that sets the table so it doesn't add an already droped item back. |
| 02-19-2006, 11:01 PM | #3 |
I still want an item to be able to drop on future drops but only 1 time on the a single drop For example: a drop drops: item a, item b. item c it will not do something like item a, item a item b So lets say it chooses to drop 5 items i want it so none of those 5 items are the same but it still drops 5 items |
| 02-19-2006, 11:46 PM | #4 |
Then save last returned value in a variable. And when picking the new item loop until the returned item type is different to the value of the variable |
| 02-20-2006, 12:13 AM | #5 |
I'm not too sure how to do that in jass. |
