• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to make an "item group"?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Hey guys. How to make an "item group", which is similar to unit group? Because I want to create an item pool and makes the enemies to randomly drop items from that item group after being killed.
Now I am using an array to store all the items, but the problem with this method is that I cannot remove the item from the item array when I need to.
Any idea, guys? Thanks a lot.

Edit: I would like to make the item unique, thats why I want to remove the item from the item array
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
If you want to remove items from an array it is better to use a hashtable to store them.

But if you want an Item Drop System there are several on this site.
One of them is in my sig. Just click the systems tab then click Item Drop System.

Mine allows items to be dropped based on a weight. (works same as percent just a lot easier to manage)
There are examples in the test map.
 
Level 11
Joined
Oct 11, 2012
Messages
711
If you want to remove items from an array it is better to use a hashtable to store them.

But if you want an Item Drop System there are several on this site.
One of them is in my sig. Just click the systems tab then click Item Drop System.

Mine allows items to be dropped based on a weight. (works same as percent just a lot easier to manage)
There are examples in the test map.

Thanks for the reply. How to do it with a hashtable? I mean how to randomly get an item from hashtable?

I will also check your system. :)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
There are several ways to do it.

You store all items that you want a unit to drop based on the units id.
To do this without overwriting you use something like this.

Save itemId as unitID of 1 in hashtable

The 1 is the first item in the hashtable.
You can use the 0 to determine how many items that unit can drop.

You do that for each unit type and item type for that unit.
Then if you want each item to drop at the specific rate you simply load the value at 0 to determine how many items that unit can drop. Then you pick a random integer in that value and put that item on the ground near the dead unit.

Example on how to drop a random item:

integer temp = Load unitID of 0 in hashtable
itemId = Load unitID of (RandomInteger from 1 to temp) in hashtable.
Create item at dead unit using itemId
 
Level 11
Joined
Oct 11, 2012
Messages
711
There are several ways to do it.

You store all items that you want a unit to drop based on the units id.
To do this without overwriting you use something like this.

Save itemId as unitID of 1 in hashtable

The 1 is the first item in the hashtable.
You can use the 0 to determine how many items that unit can drop.

You do that for each unit type and item type for that unit.
Then if you want each item to drop at the specific rate you simply load the value at 0 to determine how many items that unit can drop. Then you pick a random integer in that value and put that item on the ground near the dead unit.

Example on how to drop a random item:

integer temp = Load unitID of 0 in hashtable
itemId = Load unitID of (RandomInteger from 1 to temp) in hashtable.
Create item at dead unit using itemId

Got it! For clarification, I should use the unit's ID (GetUnitUserData()) as parent key to restore items, right? Then GetRandomInt when I LoadInteger. Is that what you were saying? :)

Edit: But how to remove the dropped item from hashtable?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
You can't use GetUnitUserData ( that is the units custom value)
You need to use the units unit type id.

To remove the item from hashtable you use a deIndexing method.

Save the random integer into a temp integer variable.

You will already have the max items in the hashtable for that unit.
You take the item in the last place put it in the place were the item that was dropped is then reduce the number of items by lowering the counter at 0.

Example;

integer temp1 = Load unitID of 0 in hashtable
integer temp2 = RandomInteger from 1 to temp
itemId = Load unitID of temp2 in hashtable
Create item at dead unit using itemId
// Now de-index
integer temp3 = Load unitID of temp1 in hashtable
Save temp3 as unitID of temp2 in hashtable
Save temp3 - 1 as unitId of 0 in hashtable
 
Level 11
Joined
Oct 11, 2012
Messages
711
You can't use GetUnitUserData ( that is the units custom value)
You need to use the units unit type id.

To remove the item from hashtable you use a deIndexing method.

Save the random integer into a temp integer variable.

You will already have the max items in the hashtable for that unit.
You take the item in the last place put it in the place were the item that was dropped is then reduce the number of items by lowering the counter at 0.

Example;

integer temp1 = Load unitID of 0 in hashtable
integer temp2 = RandomInteger from 1 to temp
itemId = Load unitID of temp2 in hashtable
Create item at dead unit using itemId
// Now de-index
integer temp3 = Load unitID of temp1 in hashtable
Save temp3 as unitID of temp2 in hashtable
Save temp3 - 1 as unitId of 0 in hashtable

Thanks for the idea and the detailed example. +Rep!
 
Status
Not open for further replies.
Top