• 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.

Giving item tables to spawned units.

Status
Not open for further replies.
Level 4
Joined
Sep 8, 2008
Messages
73
Well, what can i say.. is it possible?
I've been looking for ages for a way to give an item table to units spawned after the game has started, and seriously, there must be a way!
Anything else would be plain stupid.
 
You can use a variable array.

Set Table[0] = Claws of Attack
Set Table[1] = Pendant
Set Table[2] = Wirt's Leg

Then, when a unit dies:

Set integer = Random integer between 0 and 2
Set point = (Position of (Triggering Unit))
Item - Create Table[integer] at point
Custom script: call RemoveLocation( udg_point )

If you want a chance of dropping items, add the condition:

(Random integer between 1 and 100) less than or equal to <your %>

Chance to drop items would be like this:

Set Table[0] = ItemA
Set Table[1] = ItemB
Set Table[2] = ItemB
Set Table[3] = ItemC
Set Table[4] = ItemC

A has 20%, B and C has 40% chance of dropping :p
 
Level 2
Joined
Feb 1, 2009
Messages
11
It really depends on how your game is set up.

If each of the units travels down set paths, you might get away with setting up a region that passes out the items as they enter it (checking to make sure that they haven't already been given the items).

The alternative is to set up a series of triggers that creates the units after the game has started, rather than having them placed in the editor. Then you simply give item to last created unit.

A bad solution would be to select random units on the map and if they haven't got the items, give it to them. Run the sequence for a good 2 - 3 minutes and hope that chance allows all the troops to get an item set. A bad solution, that could work if everything else fails.

Edit - I think I've got the wrong idea here. On more than one account :p
 
Level 4
Joined
Sep 8, 2008
Messages
73
It really depends on how your game is set up.

If each of the units travels down set paths, you might get away with setting up a region that passes out the items as they enter it (checking to make sure that they haven't already been given the items).

The alternative is to set up a series of triggers that creates the units after the game has started, rather than having them placed in the editor. Then you simply give item to last created unit.

A bad solution would be to select random units on the map and if they haven't got the items, give it to them. Run the sequence for a good 2 - 3 minutes and hope that chance allows all the troops to get an item set. A bad solution, that could work if everything else fails.

Edit - I think I've got the wrong idea here. On more than one account :p

Well, actually, my intention was to be able to distribute the built in item tables that can be found under advanced options to respawning units of the same type as the ones who has been given it by deafult. It would really be a pain in the ass having to initialize a new array for every units drop rate, really (even if you could aswell make it without variables, it's more the triggering i'm refering to).
Stupid blizzard for not supporting this.
 
Level 4
Joined
Sep 8, 2008
Messages
73
You can use a variable array.

Set Table[0] = Claws of Attack
Set Table[1] = Pendant
Set Table[2] = Wirt's Leg

Then, when a unit dies:

Set integer = Random integer between 0 and 2
Set point = (Position of (Triggering Unit))
Item - Create Table[integer] at point
Custom script: call RemoveLocation( udg_point )

If you want a chance of dropping items, add the condition:

(Random integer between 1 and 100) less than or equal to <your %>

Chance to drop items would be like this:

Set Table[0] = ItemA
Set Table[1] = ItemB
Set Table[2] = ItemB
Set Table[3] = ItemC
Set Table[4] = ItemC

A has 20%, B and C has 40% chance of dropping :p

Thanks, but i think you missed my point.
Yet, i guess i'll have to settle triggering everything since the built in item tables can't be reached through triggering.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Well, I observed the code when you create an itemtable in the editor, and saw that they actually can be more efficient.

For instance, in 'clean' Jass you can be able to do ItemPools. The cons about that method is that it may seen clumpsy together with GUI. But anyways, it is better than the standard table.

Okay, so how do we use it?
Take a look at the custom script section, where you can write functions without needing triggers, located here:

2hodwtz.jpg


Note that I am not using the standard world editor. But it doesnt really matter here.

Step 2: Create your own itempool function.
I will just go through the function briefly, as you can find a very good tutorial of itempools here

Our function may look like this:
JASS:
//First table example
function ItemPoolTableAlpha takes unit u returns nothing
    local itempool ip = CreateItemPool() //Creates an itempool
    
    call ItemPoolAddItemType(ip, 'ratc', 3.0)   //Adds the item 'ratc' also known as Claws of Attack +12 to the itempool.
                                                //The value 3.0 decides the "weight" of the item.
    call ItemPoolAddItemType(ip, 'cnob', 1.0)   //Here we add the Circlet of Nobility to the pool.
    call ItemPoolAddItemType(ip, 'I000', 2.0)   //And the final one in this example would be a custom made one.
    //Notice that I set the weight different on each item on purpose. For instance for the first item, the chance will be 3/(3+1+2)
    //Or with a general formula that 'DropChance' = 'ItemWeight'/'TotalWeight'.
    
    //Now, we want the table to drop the item on the position of the unit u (which in our case, later will be the dying unit).
    call PlaceRandomItem(ip, GetUnitX(u), GetUnitY(u)) //Drops a random item in the pool on the spot where we have our unit.
    
    //The downside as I said, is that we must create the itempool and destroy it afterwards when it is used in the way we are using it.
    call DestroyItemPool(ip)
    set ip = null //Dont forget to null this variable
endfunction

//Second Table example
function ItemPoolTableBeta takes unit u returns nothing
    local itempool ip = CreateItemPool()
    call ItemPoolAddItemType(ip, 'I001', 1.0)
    call ItemPoolAddItemType(ip, 'I002', 2.0)
    call PlaceRandomItem(ip, GetUnitX(u), GetUnitY(u))
    call DestroyItemPool(ip)
    set ip = null
endfunction

If you dont know how to find the rawcode of the item (like example 'ratc') open up Item Editor, press the "View" tab at the top of the window, and mark "Display values as raw data".

Now, final step, how shall we use it?
It can have different conditions determining if your itempool should be for a specific player or a specific unit type or something like that. But I will show with unittype conditions here:

We make a trigger with the Event - Unit Dies. Then some if conditions will decide what itempool which should be used.
For instance:

  • Place Item Upon Death
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • -------- We check if the unit is a footman. If it is, call the first table. Notice: TriggeringUnit in GUI is GetTriggerUnit() in Jass --------
          • Custom script: call ItemPoolTableAlpha( GetTriggerUnit() )
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Priest
            • Then - Actions
              • Custom script: call ItemPoolTableBeta( GetTriggerUnit() )
            • Else - Actions
If there is any conditions you would like to add, just add them. If you need more ItemPools, don't hesitate to user the custom script section.
 
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
It is a real value, that is correct. And yeah, the weight is the chance, depending on the total amount of items you got in the itempool, and how much weight they have.

For instance, we add some items with some weight

ItemWeight

Claws of Attack
1.5

Mask of Death
3.0

Tome of Power
0.5

Will give a 1.5/(1.5+3.0+0.5) = 1.5/5 = 3/10 = 30% chance of dropping Claws of Attack,
3.0/(1.5+3.0+0.5) = 3/5 = 60% chance of dropping Mask of Death, and
10% chance of dropping tome of power.

The input weight does not really matter, whether you set item 1 to 40 and item 2 to 30, or set them to 4.0 respectively 3.0 The chance will be the same.
Just remember the chance equals 'item weight'/'total weight'
 

Ham

Ham

Level 5
Joined
Jan 16, 2009
Messages
132
wow i have been looking for this, but is there a way to make a non drop? like 20% chances to drop nothing at all? and like 10% chances to do an action instead of dropping?
 
Level 4
Joined
Sep 8, 2008
Messages
73
It is a real value, that is correct. And yeah, the weight is the chance, depending on the total amount of items you got in the itempool, and how much weight they have.

For instance, we add some items with some weight

ItemWeight

Claws of Attack
1.5

Mask of Death
3.0

Tome of Power
0.5

Will give a 1.5/(1.5+3.0+0.5) = 1.5/5 = 3/10 = 30% chance of dropping Claws of Attack,
3.0/(1.5+3.0+0.5) = 3/5 = 60% chance of dropping Mask of Death, and
10% chance of dropping tome of power.

The input weight does not really matter, whether you set item 1 to 40 and item 2 to 30, or set them to 4.0 respectively 3.0 The chance will be the same.
Just remember the chance equals 'item weight'/'total weight'

Thanks, just noticed you had actually written that in a comment. :)
Still, like someone just asked, is it possible to leave the item ID field blank to drop, well.. no item att all as a chance? Or will that cause errors?

Still, i will give you +rep for your pedagogical approach.
Even though i'm very familiar with Flash AS, Jass has always seemed so hard to undersrtand with all its built-in functions to keep in mind, but now suddenly it doesen't.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
wow i have been looking for this, but is there a way to make a non drop? like 20% chances to drop nothing at all? and like 10% chances to do an action instead of dropping?
Insert a weight such that the chance will be 20% with an item id of 0.

Ex.

JASS:
local itempool ip = CreateItemPool()
call ItemPoolAddItemType(ip,'ratc',4.)
call ItemPoolAddItemType(ip,0,1.)

Will have an 80% chance to yield claws of attack and 20% to yield nothing when told to make an item.

PS. Use global itempools, no sense in recreating them all the time.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
PurplePoot, there is a reason why it has to be local, if you want it to work with GUI compatibility. There is no way to create global itempools with the variable editor.

//The downside as I said, is that we must create the itempool and destroy it afterwards when it is used in the way we are using it.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Well yeah that is correct.

So guys, if you dont have JassNewGenPack or Weu (Weu is totally not up to date though) do it like I said. If you have JassNewGenPack, you could just create a global block instead.
 
Level 6
Joined
Sep 5, 2007
Messages
264
For a random chance to drop nothing just use:
JASS:
    local real chance = GetRandomReal(0,100)
    local real chance_to_drop = 80

    if (chance <= chance_to_drop) then
        call Function_That_Does_The_Item_Drop()
    endif
In this example, there is an 80% chance to drop an item, otherwise it drops nothing (and doesn't waste CPU on the "Null Item Drop")

This way is best if you want a constant chance to drop nothing. The other way, using itempools & weights, works well... but, you'd have to constantly change the weight of null everytime you add a new item.
 
Status
Not open for further replies.
Top