- Joined
- Aug 3, 2004
- Messages
- 710
This is a tutorial I decided to make, because from what i've experienced, very few people actually know about the itempool natives, and even fewer knows how to use them.
Itempools are an internal system, just like a normal units droptable, you know, the ones where you doubleclick a unit, and sets it's droptable.
Short explanation of the natives:
That's the natives from Common.j.
Here's some examples:
This creates an item pool, with 1/2(50%) chance of dropping item
This creates an item pool, with 1/3(33%) chance of dropping item
This creates an item pool, with 1/5(20%) chance of dropping item
As you can see it's pretty simple actually, the "weight" determines the chance of how often an item will drop. The easiest way to get the drop chance of an itempool, is to add the weight's together and divide the individual weight. Like the last example there's 1+2+2 which is 5, then
To create an item using an itempool, you just use the PlaceRandomItem native, like this:
This will place a random item from the itempool created, and return the item created, incase you want to do something with it.
An example of using the returned item would be the following function i use in hero rewards:
Leaks: You should always remember to destroy itempools that you don't use. And also, remember to null any itempool variabels after you're done using them.
Hope this tutorial helps someone understanding itempools.
- MindWorX
Itempools are an internal system, just like a normal units droptable, you know, the ones where you doubleclick a unit, and sets it's droptable.
Short explanation of the natives:
JASS:
//Creates an itempool.
native CreateItemPool takes nothing returns itempool
//Destroys an itempool.
native DestroyItemPool takes itempool whichItemPool returns nothing
//Adds an item to an itempool.
native ItemPoolAddItemType takes itempool whichItemPool, integer itemId, real weight returns nothing
//Removes an item from an itempool.
native ItemPoolRemoveItemType takes itempool whichItemPool, integer itemId returns nothing
//Creates a random item from an itempool.
native PlaceRandomItem takes itempool whichItemPool, real x, real y returns item
Here's some examples:
This creates an item pool, with 1/2(50%) chance of dropping item
'I001'
and 1/2(50%) chance of dropping item 'I002'
.
JASS:
local itempool ip = CreateItemPool()
call ItemPoolAddItemType(ip, 'I001', 1)
call ItemPoolAddItemType(ip, 'I002', 1)
This creates an item pool, with 1/3(33%) chance of dropping item
'I001'
and 2/3(66%) chance of dropping item 'I002'
.
JASS:
local itempool ip = CreateItemPool()
call ItemPoolAddItemType(ip, 'I001', 1)
call ItemPoolAddItemType(ip, 'I002', 2)
This creates an item pool, with 1/5(20%) chance of dropping item
'I001'
, 2/5(40%) chance of dropping item 'I002'
and 2/5(40%) chance of dropping item 'I003'
.
JASS:
local itempool ip = CreateItemPool()
call ItemPoolAddItemType(ip, 'I001', 1)
call ItemPoolAddItemType(ip, 'I002', 2)
call ItemPoolAddItemType(ip, 'I003', 2)
As you can see it's pretty simple actually, the "weight" determines the chance of how often an item will drop. The easiest way to get the drop chance of an itempool, is to add the weight's together and divide the individual weight. Like the last example there's 1+2+2 which is 5, then
'I001'
has 1 as weight, then you just do 1/5 which is 0.20, then you multiply by 100, and you have 20%.To create an item using an itempool, you just use the PlaceRandomItem native, like this:
JASS:
local itempool ip = CreateItemPool()
call ItemPoolAddItemType(ip, 'I001', 1)
call ItemPoolAddItemType(ip, 'I002', 2)
call ItemPoolAddItemType(ip, 'I003', 2)
call PlaceRandomItem(ip,x,y)
An example of using the returned item would be the following function i use in hero rewards:
JASS:
function GiveUnitRandomItem takes unit u, itempool ip returns nothing
local item i = PlaceRandomItem(ip,0,0)
call UnitAddItem(u,ip)
set i = null
endfunction
Leaks: You should always remember to destroy itempools that you don't use. And also, remember to null any itempool variabels after you're done using them.
Hope this tutorial helps someone understanding itempools.
- MindWorX
Attachments
Last edited: