(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Tutorials > JASS/AI Scripts Tutorials

JASS/AI Scripts Tutorials Contains tutorials regarding JASS scripting and the AI editor.
Read the Rules before posting.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-11-2007, 11:38 AM   #1 (permalink)
 
MindWorX's Avatar

Wulfy loves Nex!
 
Join Date: Aug 2004
Posts: 288

MindWorX has a spectacular aura about (121)MindWorX has a spectacular aura about (121)MindWorX has a spectacular aura about (121)MindWorX has a spectacular aura about (121)

PayPal Donor: This user has donated to The Hive. Hosted Project of the Year 2007: Reinventing the Craft 

Itempools Guide

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:

//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
That's the natives from Common.j.

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'.
 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'.
 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'.
 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:
 local itempool ip = CreateItemPool()
    call ItemPoolAddItemType(ip, 'I001', 1)
    call ItemPoolAddItemType(ip, 'I002', 2)
    call ItemPoolAddItemType(ip, 'I003', 2)
    call PlaceRandomItem(ip,x,y)
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:
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
Attached Files
File Type: w3x itempool_example.w3x (12.7 KB, 93 views)

Last edited by MindWorX; 06-13-2007 at 05:30 PM.
MindWorX is offline  
Old 06-13-2007, 02:30 AM   #2 (permalink)
 
PurgeandFire111's Avatar

User Title
 
Join Date: Nov 2006
Posts: 1,059

PurgeandFire111 is a jewel in the rough (153)


Short but good tutorial. It is descriptive as well. This tutorial actually gave me an understanding of JASS itempools. Gj and +rep!
__________________
Vote For The Hive Workshop!
Funny but the TRUTH! :
Quote:
Originally Posted by Sopho
Unprotecting maps is not right its like crime and YOU GO MAKE YOUR OWN MAP AND BE HAPPY! Don't be gay n00b!

1. You can if it is yours but you should not if it is not. It is like stealing information and using it as if it is your own. It si gay stuff and people who unprotect maps are gay themselves.
PurgeandFire111 is offline  
Old 06-13-2007, 04:38 PM   #3 (permalink)
Spell and Map Moderator
 
Dr Super Good's Avatar

The Helpful Personage
 
Join Date: Jan 2005
Posts: 4,416

Dr Super Good is a name known to all (650)Dr Super Good is a name known to all (650)


Only reason I see this not being approved is that it has no demo map showing how to use it to make a basic system, but next to that this should definatly be approved. Also you should add a warning that they can leak unless you destroy them if you use them only once as a local.
Dr Super Good is offline  
Old 06-13-2007, 05:30 PM   #4 (permalink)
 
MindWorX's Avatar

Wulfy loves Nex!
 
Join Date: Aug 2004
Posts: 288

MindWorX has a spectacular aura about (121)MindWorX has a spectacular aura about (121)MindWorX has a spectacular aura about (121)MindWorX has a spectacular aura about (121)

PayPal Donor: This user has donated to The Hive. Hosted Project of the Year 2007: Reinventing the Craft 

Quote:
Originally Posted by Dr Super Good View Post
Only reason I see this not being approved is that it has no demo map showing how to use it to make a basic system, but next to that this should definatly be approved. Also you should add a warning that they can leak unless you destroy them if you use them only once as a local.
Done and Done.
__________________
"Wulfy loves Nex!"
MindWorX is offline  
Old 06-27-2007, 12:46 AM   #5 (permalink)
Overall Site Manager
 
Wolverabid's Avatar

 
Join Date: Oct 2006
Posts: 8,756

Wolverabid has much of which to be proud (1208)Wolverabid has much of which to be proud (1208)

Respected User: This user has been given the respected user award. User of the Year: 2007 

Thumbs up Tutorial Approved!

~ Thread moved to JASS/AI Scripts Tutorials.
__________________
SuperSecretSearchSystem .......Netiquette....... Posting And You..........Read Me.......Vote

Antivirus Chat Dictionary Games Hoaxes Links Music News Quotations Reference Software

[timquote]blah[/timquote]
Wolverabid is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Install Guide MindWorX Tutorials 18 08-24-2008 07:29 AM
English Guide brad.dude03 Off-Topic 14 12-28-2006 04:40 AM
My Guide Healingpoison Off-Topic 0 08-18-2006 01:00 AM
Noob Guide Torn Off-Topic 18 04-21-2005 12:05 AM
[JASS] JASS guide??? shady-x Triggers & Scripts 2 06-08-2004 05:20 PM

All times are GMT. The time now is 05:59 PM.






Your link here 
Best Credit Cards | Shares | Online Loans | Michigan Flag | MPAA
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Copyright©Ralle