• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Simple Item Drop via Trigger ?

Status
Not open for further replies.

Ardenian

A

Ardenian

  • loot forest common
    • Ereignisse
      • Einheit - A unit Stirbt
    • Bedingungen
      • And - All (Conditions) are true
        • Bedingungen
          • ((Triggering unit) is Ein Held) Gleich False
          • (Owner of (Triggering unit)) Gleich Spieler 12 (Braun)
          • Or - Any (Conditions) are true
            • Bedingungen
              • (Unit-type of (Triggering unit)) Gleich Wolf
              • (Unit-type of (Triggering unit)) Gleich Big Wolf
              • (Unit-type of (Triggering unit)) Gleich Little Ent
    • Aktionen
      • If ((Random integer number between 1 and 100) Gleich 1) then do (Gegenstand - Create Lesser Nature Shard at (Position of (Triggering unit))) else do (Do nothing)
      • If ((Random integer number between 1 and 500) Gleich 1) then do (Gegenstand - Create Greater Nature Shard at (Position of (Triggering unit))) else do (Do nothing)
      • If ((Random integer number between 1 and 120) Gleich 1) then do (Gegenstand - Create Corrupted Fragment at (Position of (Triggering unit))) else do (Do nothing)
Does this trigger example works ? I searched for Item Drop Systems but decided to use this way, but it seems to be strange, dropping items with 1% dropchance at around 5 kills. Just fortuity ?

Why NOT use item drop via this kind of Trigger ?
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
It works. A unit can drop three items when it dies, is that what you want? Or if a unit dies, it can only drop one item?

You can remove the And - All (Conditions) are true. Place the conditions directly under the main "Bedingungen".

I would use a hastable for an item drop system.

Event
- Unit dies
Condition
- Data is stored for the unit type in drop hashtable
Actions
- Load drop chances and item types to create

You would only possibly need one trigger to handle all unit types. You would only need one condition, instead of many.
 

Ardenian

A

Ardenian

It works. A unit can drop three items when it dies, is that what you want? Or if a unit dies, it can only drop one item?

You can remove the And - All (Conditions) are true. Place the conditions directly under the main "Bedingungen".

I would use a hastable for an item drop system.

Event
- Unit dies
Condition
- Data is stored for the unit type in drop hashtable
Actions
- Load drop chances and item types to create

You would only possibly need one trigger to handle all unit types. You would only need one condition, instead of many.

I want that there´s a Chance that 0-3 items can drop each time this Kind of creep is dying.

Oh you can create it via hashtable ? Guess there´s sth new to learn now...

Thank you!
 

Ardenian

A

Ardenian

I have a drop system in my sig that will do exactly what you want.

JASS:
STEP 1: Install JNGP first if you dont have JNGP.

I am sorry, I don´t use JNGP atm :(
But Thank You for your effort :)

EDIT: I don´t get it, you say its
This system is GUI friendly
in your description but you have to install JNGP ? Thought GUI means that you have a Trigger that can work several times at the same time, in difference to MUI which allows only one use at the time...

So this means I could add your System although I have no JNGP, because it´s GUI-friendly ?

Maker said:
I would use a hastable for an item drop system.

Well, I looked it up and I understand whats a hashtable, but I don´t get it how to use it the right way. In case I am right, you have to create variables for each table place, seems more difficult to me.

I would really appreciate if you could post an item drop example with hashtable here, I didn´t find one myself...
 
Last edited by a moderator:
Level 24
Joined
Aug 1, 2013
Messages
4,658
I have a drop system that works smooth but you have to register all drops for all unit types.
You have a drop table that is just a hashtable with each row a different drop set.
Ex. row 0: ring of protection, 100 per mille, orb of venom, 5 per mille.
row 1: gold coins, 1000 per mille
etc etc etc

you can assign a drop set to every unit type (or specific unit) and then it loops through all possibilites and drops stuff if you are lucky
(i use per mille because it is just more fun and modifyable, you can use per cent ofcourse)

the bad thing is that you have to register all data... nothing more than simply adding a row in the object editor.

This trigger gives the unit types their own drop row:
JASS:
function RegisterUnitItemDropSet takes integer id, integer dropTableRowId returns nothing
    call SaveInteger(udg_Hashtable_UnitType, id, 0, dropTableRowId)
endfunction

//===========================================================================
function InitTrig_Units takes nothing returns nothing
    call RegisterUnitItemDropSet('hfoo', 0)//Footman
    call RegisterUnitItemDropSet('hkni', 0)//Knight
    call RegisterUnitItemDropSet('hrif', 0)//Rifleman
    call RegisterUnitItemDropSet('hgry', 1)//Gryphon Rider
endfunction

This trigger registers the drop tables:
In this trigger you have to add all item types and their chance to the hashtable.
JASS:
function RegisterNewItemForTable takes integer row, integer itemId, integer chance returns nothing
    local integer i = 0
    local integer itemType = 0
    
    loop
        set itemType = LoadInteger(udg_Hashtable_ItemDrop, row, i)
        exitwhen itemType == 0
        set i = i + 2
    endloop
    call SaveInteger(udg_Hashtable_ItemDrop, row, i, itemId)
    call SaveInteger(udg_Hashtable_ItemDrop, row, i+1, chance)
endfunction

//===========================================================================
function InitTrig_Items takes nothing returns nothing
    call RegisterNewItemForTable(0, 'rde2', 100)//Ring of Protection +3
    call RegisterNewItemForTable(0, 'oven', 5)//Orb of Venom
    call RegisterNewItemForTable(1, 'gold', 1000)//Gold Coins
endfunction

This is the drop item(s) trigger: (Could be done in GUI easily but does not need any modification.
JASS:
function Trig_Item_Drop_Create_Item takes integer itemId, integer chance, location l returns nothing
    local integer random = GetRandomInt(0, 999)
    if (random < chance) then
        call CreateItem(itemId, GetLocationX(l), GetLocationY(l))
    endif
endfunction

function Trig_Item_Drop_Actions takes nothing returns nothing
    local unit u = GetDyingUnit()
    local integer row = LoadInteger(udg_Hashtable_UnitType, GetUnitTypeId(u), 6)
    local integer i = 0
    local integer id
    local integer chance
    local location l
    
    loop
        set id = LoadInteger(udg_Hashtable_ItemDrop, row, i)
        exitwhen (id == 0)
        set chance = LoadInteger(udg_Hashtable_ItemDrop, row, i+1)
        set l = GetUnitLoc(u)
        call Trig_Item_Drop_Create_Item(id, chance, l)
        call RemoveLocation(l)
        set i = i + 2
    endloop
endfunction

//===========================================================================
function InitTrig_Item_Drop takes nothing returns nothing
    set gg_trg_Item_Drop = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Item_Drop, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction(gg_trg_Item_Drop, function Trig_Item_Drop_Actions)
endfunction

If you copied everything right, every footman, knight and rifleman now has a chance of 100 out of 1000 (10%) to drop a Ring of Protection and 5 out of 1000 (0,5%) to drop an Orb of Venom.
Every Gryphon Rider has a 1000 out of 1000 chance (100%) that it will drop Gold Coins on death.

You can create a different drop set for every single unit but with this you can assign item sets to multiple units.
In my map I also have my own system that a unit can drop variable gold amounts and because of that, the original triggers are a bit different.
You can blend the item and unit registration with the one you already have (if you have any)
 
Last edited:

Ardenian

A

Ardenian

@Wietlol

Thanks for your effort and I really would like to say that I understand these scripts because I understand what they do, but I have no clue...

As you said in another thread to me, I am not able to customize those scripts, therefore, in case I will 'finish' Beta of my ORPG, I will recruite a coder who's able to write and understand these scripts
 
Why would you want it in a condition instead of an action?

Look at my tutorial Converting GUI to efficient jass.

Hashtables are easy to start with, but once you get the hang of it you should switch to arrays... but even with hashtables i cannot see any latency so far

Hashtables are about 8 times slower than an array lookup to start. The more information managed by a hashtable the slower it gets.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Try this system, yes it is GUI.
http://www.hiveworkshop.com/forums/...?prev=status=a&search=item%20drop&d=list&r=20

If you have troubles of using it, insist on PM me, I'll try to handle your questions about the system.

It still has few considerations for a fixing, but it does not affect the usability of the system in terms of its features and mechanics, those fix are just minor.

I'll try to adapt the system's features if you want a minor adjustments for it, I'll try to consider it, such as dropping more than 1 loot per enemy, etc.
 

Ardenian

A

Ardenian

Try this system, yes it is GUI.
http://www.hiveworkshop.com/forums/...?prev=status=a&search=item%20drop&d=list&r=20

If you have troubles of using it, insist on PM me, I'll try to handle your questions about the system.

It still has few considerations for a fixing, but it does not affect the usability of the system in terms of its features and mechanics, those fix are just minor.

I'll try to adapt the system's features if you want a minor adjustments for it, I'll try to consider it, such as dropping more than 1 loot per enemy, etc.

Seems exactly what I need, but
Maker said:
Add drop chance
and there are a few other critics on this system. Just wondering why don't you add content/rework it after feedback ?

Would need atleast drop chances and amount ( + multiple amount of one item) to add your system into my map.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
It is a GUI version of mine XD
Except that you do not support drop chance and your units choose one out of their drop list... I also save less data because I use item drop lists and assign those to units instead of assigning items directly to them.

In any case I will create a GUI item drop system with arrays instead of a hashtable just to give some better stuff too... not to tease you, but... yea to tease you :p

EDIT: amounts are nice too... never actually had any need for it but will do it
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Ardenian can you specify what you want in that system?
Like a unit may only drop 1 item from its item table. or A unit can drop all items from its table (if lucky as hell)
and stuff like a minimum and maximum amount of items
etc etc etc

Also one question... do you know how to define an item-type or unit-type in an integer?
Do you know what 'A000', 'A001', 'h000' and 'h001' means and how you can get those values?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Also one question... do you know how to define an item-type or unit-type in an integer?
Do you know what 'A000', 'A001', 'h000' and 'h001' means and how you can get those values?
Why not let him just input/configure the Item-type and you yourself (System Maker) provide the conversion from Item Type to its ID?

You can't expect System User to know these stuffs, you should keep it simple to them, and hard work for you.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
I really try to keep everything as simple as possible but I searched the web and I cannot find any conversion from item-type/unit-type to integer nor can I see the function for adding a item-type/unit-type value in a hashtable

Arrays in my concept are kinda impossible because I need dynamic arrays... I somehow like difficult things.
If I had everything in arrays then I could have item-type/unit-type as a value but that is not happening until I can see a different way to break JASS code.
 
I really try to keep everything as simple as possible but I searched the web and I cannot find any conversion from item-type/unit-type to integer nor can I see the function for adding a item-type/unit-type value in a hashtable
ItemTypes and UnitTypes already are integers. But the GUI doesn't show it as one. Instead it makes the user think it's a new variable type, so you are not allowed to use it as an integer in GUI.

No problem with it in JASS/custom script. You simply can store a Unit/Item- type variable as an integer into hashtable.
 

Ardenian

A

Ardenian

Ardenian can you specify what you want in that system?
Like a unit may only drop 1 item from its item table. or A unit can drop all items from its table (if lucky as hell)
and stuff like a minimum and maximum amount of items
etc etc etc

Well, I would like that, if a unit dies, there is a chance to drop different item-types. So there may drop, for example, 3 different item-types if you kill a wolf.

But, additionally, there should be the possibility that one item-type can drop e.g. 3 times with one kill. So if you kill a unit, it can drop 0-3 items, and e.g. Item-type 1 can drop up to 3 times.

Item-drop should be unit-specific, so each unit-type drops other/same/more items like another.

A unit-type may drop all of it's item table, but there will be little chance for each item drop.

Think no maximum or minimum for number of dropped items.

Would be really glad if you can create such a system.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
I knew that they were some kind of integers but the editor sais that the only conversion that is automatically made is Real -> Integer and vice versa.
Good to know that I can still use everything properly.

Anyway here is the map.
One thing that I don't like is that the random stuff is pretty odd... The footmen have a 40% drop chance to drop 2 to 9 gold coins (separate items) but it is like the first 5 dont drop it and then the next 4 does and then the next 6 dont etc etc etc... after killing 63, they had an average of 41,2698% so I guess it doesnt matter that much.

But here is the map.
You can find your way.

You can give every unit-type a set of items that they drop.
You can give more items to a unit-type.
You can set the drop rate/chance in percentage as a real.
You can set the minimum and maximum of how much items will be dropped if any were dropped in the first place.

(Sorry if you dont like the odd variable names... I can either make almost all of them temp variables (can be used in other triggers as well) or name them properly (easier to read, but you will have a lot of variables if you do that with everything))

For those who are lazy... or whatever reason you have. Here are the triggers:
  • IDS Register
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set IDS_Hashtable = (Last created hashtable)
      • Set TempUnitType = Footman
      • -------- New unit --------
      • Set TempItemType = Gold Coins
      • Set IDS_Chance = 40.00
      • -------- 40.00% chance --------
      • Set IDS_Amount_Min = 2
      • -------- minimum 2 --------
      • Set IDS_Amount_Max = 9
      • -------- maximum 9 --------
      • Trigger - Run IDS Save <gen> (ignoring conditions)
      • -------- Same unit --------
      • Set TempItemType = Crown of Kings +5
      • Set IDS_Chance = 5.00
      • -------- 5.00% chance --------
      • Set IDS_Amount_Min = 1
      • -------- minimum 1 --------
      • Set IDS_Amount_Max = 1
      • -------- maximum 1 --------
      • Trigger - Run IDS Save <gen> (ignoring conditions)
      • Set TempUnitType = Rifleman
      • -------- New unit --------
      • Set TempItemType = Druid Pouch
      • Set IDS_Chance = 49.99
      • -------- 49.99% chance --------
      • Set IDS_Amount_Min = 1
      • -------- minimum 1 --------
      • Set IDS_Amount_Max = 4
      • -------- maximum 4 --------
      • Trigger - Run IDS Save <gen> (ignoring conditions)
  • IDS Save
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_TempInteger = udg_TempUnitType
      • Custom script: set udg_TempInteger2 = udg_TempItemType
      • For each (Integer IDS_Index) from 0 to 100, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load IDS_Index of TempInteger from IDS_Hashtable) Equal to 0
            • Then - Actions
              • Hashtable - Save TempInteger2 as IDS_Index of TempInteger in (Last created hashtable)
              • Hashtable - Save IDS_Chance as (IDS_Index + 1) of TempInteger in IDS_Hashtable
              • Hashtable - Save IDS_Amount_Min as (IDS_Index + 2) of TempInteger in IDS_Hashtable
              • Hashtable - Save IDS_Amount_Max as (IDS_Index + 3) of TempInteger in IDS_Hashtable
              • Custom script: exitwhen (true)
            • Else - Actions
              • Set IDS_Index = (IDS_Index + 3)
  • IDS Drop Item
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set TempUnitType = (Unit-type of (Triggering unit))
      • Custom script: set udg_TempInteger = udg_TempUnitType
      • For each (Integer IDS_Index) from 0 to 100, do (Actions)
        • Loop - Actions
          • Set TempInteger2 = (Load IDS_Index of TempInteger from IDS_Hashtable)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInteger2 Not equal to 0
            • Then - Actions
              • Game - Display to (All players) the text: Item found!
              • Set IDS_Chance = (Load (IDS_Index + 1) of TempInteger from IDS_Hashtable)
              • Set TempReal = (Random real number between 0.00 and 100.00)
              • Game - Display to (All players) the text: (Chance = + ((String(IDS_Chance)) + ( to + (String(TempReal)))))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • IDS_Chance Greater than or equal to TempReal
                • Then - Actions
                  • Game - Display to (All players) the text: Item created!
                  • Set IDS_Amount_Min = (Load (IDS_Index + 2) of TempInteger from IDS_Hashtable)
                  • Set IDS_Amount_Max = (Load (IDS_Index + 3) of TempInteger from IDS_Hashtable)
                  • Set TempLocation = (Position of (Triggering unit))
                  • Set TempInteger3 = (Random integer number between IDS_Amount_Min and IDS_Amount_Max)
                  • For each (Integer A) from 1 to TempInteger3, do (Actions)
                    • Loop - Actions
                      • Custom script: call CreateItem(udg_TempInteger2, GetLocationX(udg_TempLocation), GetLocationY(udg_TempLocation))
                  • Custom script: call RemoveLocation(udg_TempLocation)
                • Else - Actions
                  • Game - Display to (All players) the text: Not lucky enough!
              • Set IDS_Index = (IDS_Index + 3)
            • Else - Actions
              • Game - Display to (All players) the text: No more items found!
              • Skip remaining actions
EDIT: I added the Temp Variable map as well.
There is also one bug in it... it would be. In the first map there is still one refer to (Last created hashtable) inside the IDS Save trigger. It cannot refer to any other hashtable because the last created hashtable is always the IDS_Hashtable, but it just isnt nice to have such a statement in there.
 

Attachments

  • Item Drop System GUI.w3x
    19.1 KB · Views: 43
  • Item Drop System GUI (TempVariables).w3x
    19 KB · Views: 38

Ardenian

A

Ardenian

Wietlol said:
But here is the map.
You can find your way.

You can give every unit-type a set of items that they drop.
You can give more items to a unit-type.
You can set the drop rate/chance in percentage as a real.
You can set the minimum and maximum of how much items will be dropped if any were dropped in the first place.

Thank you so much! You made my day!
Would give +rep, but I gave already for another great assistance of you :/
 
Status
Not open for further replies.
Top