item drop % / storage array

PhoenixICE

New Member
Reaction score
0
i've looked through the forums and couldn't find an trigger that i needed (got up to like page 7) this is what i'm trying to do:

Setup an array then using random function pick an item from the array, but each item has a different ratio % of dropping and each creep has a different chance of dropped an item or not dropping one, so in short multiple items and multiple types of creeps, i need a efficent trigger in storing about 30-100 items and then a trigger to drop the items depending on its drop ratio.

i had this -

Code:
function Trig_item_store_lvl_1_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 99
    set bj_forLoopAIndexEnd = 100
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I001'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 96
    set bj_forLoopAIndexEnd = 98
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I009'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 90
    set bj_forLoopAIndexEnd = 95
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I007'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 83
    set bj_forLoopAIndexEnd = 89
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I005'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 76
    set bj_forLoopAIndexEnd = 82
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I004'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 71
    set bj_forLoopAIndexEnd = 75
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I003'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 61
    set bj_forLoopAIndexEnd = 70
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I002'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 41
    set bj_forLoopAIndexEnd = 60
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I008'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 40
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Item_list_Town_1[GetForLoopIndexA()] = 'I006'
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_item_store_lvl_1 takes nothing returns nothing
    set gg_trg_item_store_lvl_1 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_item_store_lvl_1, 5.00 )
    call TriggerAddAction( gg_trg_item_store_lvl_1, function Trig_item_store_lvl_1_Actions )
endfunction

then i used a drop function

Code:
function Trig_Death_of_noraml_unit_lvl_6_and_below_Conditions takes nothing returns boolean
    if ( not ( GetUnitLevel(GetDyingUnit()) <= 6 ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == false ) ) then
        return false
    endif
    return true
endfunction

function Trig_Death_of_noraml_unit_lvl_6_and_below_Func004C takes nothing returns boolean
    if ( not ( udg_Random_Percentage <= udg_Item_Drop_Ratio ) ) then
        return false
    endif
    return true
endfunction

function Trig_Death_of_noraml_unit_lvl_6_and_below_Actions takes nothing returns nothing
    set udg_Item_Drop_Ratio = ( GetRandomReal(0, 30.00) / I2R(GetUnitLevel(GetDyingUnit())) )
    set udg_Random_Percentage = GetRandomReal(0, 100.00)
    if ( Trig_Death_of_noraml_unit_lvl_6_and_below_Func004C() ) then
        call CreateItemLoc( udg_Item_list_Town_1[GetRandomInt(1, 100)], GetUnitLoc(GetDyingUnit()) )
    else
        call DoNothing(  )
    endif
endfunction

//===========================================================================
function InitTrig_Death_of_noraml_unit_lvl_6_and_below takes nothing returns nothing
    set gg_trg_Death_of_noraml_unit_lvl_6_and_below = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Death_of_noraml_unit_lvl_6_and_below, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Death_of_noraml_unit_lvl_6_and_below, Condition( function Trig_Death_of_noraml_unit_lvl_6_and_below_Conditions ) )
    call TriggerAddAction( gg_trg_Death_of_noraml_unit_lvl_6_and_below, function Trig_Death_of_noraml_unit_lvl_6_and_below_Actions )
endfunction

but that gonna be crazy storing 1 item 20 times in one array isn't the best way of doing this so does anyone have a good system?
 
hmm

Any reason this is in jass?

you do know you can right click the name above "Events" in the actual trigger, and copy as text...

then paste into here?.

Btw

this should work
([E] [C] [A] [V] represent, Events, Conditions, Actions, Variables, just so you can see clearly which is which)
Make a [V] variable called P_Integer, type integer, (Array 1)
Make a [V] variable called Items type item, (Array 1)
Make a [V] variable called Player_Number type integer (No array)
Make a [V] variable called Integer_P_Max, type integer, (Array 1)
Code:
Event - [E] A unit dies
Conditions - 
Actions - set Player_Number = player number of owner of dying unit
For each Integer A from 1 to 6
   loop
     - if (all conditions are true) then (do then actions) else do (else actions)
        - [C] item in slot integer a not equal to <items not to be saved>
          - [A] set Items[P_Integer[Player_Number]] = Item in slot Integer A
          - [A] remove item in slot Integer A from dying unit
          - set P_Integer[Player_Number] = P_Integer[Player_Number] + 1
           - if (all conditions are true) then (do then actions) else do (else actions)
            - if [C] P_Integer[Player_Number] >= P_Integer_Max-1
            - [A] set P_Integer[Player_Number] = P_Integer_Max-10

Code:
Event - [E] Map initilization
Conditions
Actions - For each Integer A from 1 to 12
   loop
     - set P_Integer_Max[Integer A] = Integer A * 100
set P_Integer[1] = 0
set P_Integer[2] = 100
set P_Integer[3] = 200
set P_Integer[4] = 300
set P_Integer[5] = 400
set P_Integer[6] = 500
set P_Integer[7] = 600
set P_Integer[8] = 700
set P_Integer[9] = 800
set P_Integer[10] = 900
set P_Integer[11] = 1000
set P_Integer[12] = 1100

P_Integer_Max is how many items can be stored (NOT TO BIG or PROBLEMS OCCUR)
So, basically, it loops through the inventory, add ANY item you want to be saved to <items not to be saved>
just copy paste the condition and change it each time (If you dont want that, just delete the condition, or right click and disable it)

it sets Items[] = the item
P_Integer is so it doesn't overlap on the item, and Player_Number is so, that player 1, 2, 3, and so on, all have they're own integers, so it doesn't conflict...

now, so
For each item player 1 has,
when he dies
It will be stored in the array from 0 - 99

Player 2, it will be 100 - 199
Player 3, it will be 200 - 299
You should see the pattern

NOTE if this overlaps, it sets P_Integer = P_Integer_Max - 10

(So the last 10 items will be erased if he dies with new items)


----
I realized, I didnt read it properly, and began to write a new one, for that, but TH went down
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top