Wednesday, April 18, 2012

Hero can only pick up one of X item.

So I ran into this ridicculously simple problem that I can't seem to figure out.

In my map there is a particular creep that always drops a particular item when killed. Said creep is set to respawn at regular intervals, so he can be killed for the item over and over.

The dropped item is one that the hero who acquires it cannot drop and it never expires/gets used. (working as intended)

Now here's the catch: when the creep is killed again, a hero who already has this item must not be able to pick up another one.

Also, the map involves standard warcraft 3 shops and items, so messing with the heroes' ability to use and carry those is not an option. Each player may also have up to three heroes like normal, and the item is specific to the hero, not the player who owns them. (so more than one hero of the same player may have the item, which works since they cannot drop/trade it to each other)

Needless to say, the item itself MUST be undroppable as it has a permanent unreversable effect on the carrier. It can only be acquired by defeating this creep. It's not for sale anywhere.

Any ideas how to pull this simple thing off?|||How about just using remove item: if a player picks up the item and they already have one, remove it (from the game) and create a new item of the same type at their current location. This way you skip the need to worry about preventing units from picking up the item and you don't need to use droppable items.|||As a matter of fact, that's what I thought of too. As it turned out, however, I couldn't find a trigger condition to count the number of items of a specific type that a specific unit has. As a result, all I managed to accomplish was to prevent any hero from picking up the item at all, since "acquires item" seems to fire only once the item is already placed in the unit's inventory, making my "unit has item of type" -condition read it as an item the hero already has by the time the trigger tests for that.

If someone could point me in the right direction to find my missing condition for that, It'd be appreciated. Keep in mind that the item is supposed to be unique to a unit, not a player.

I also figured that a variable-counter workaround wouldn't really work either since each of the several players involved may have a variable number of heroes at their disposal, all of which are trained from an altar or tavern, at a time chosen by each player, like in a normal game, not through a global hero selection at the start of the map, or anything of the like that would obviously make it easy to track all active heroes the players have.

After taking all that into account and trying to think of what kinda trigger it would take to make it work that way, it just seems like way too much code for one small item.|||The item pickup is probably too rare to bother with storing how many each unit might have - although if you wanted to go that route and you don't know how to use hashtables, you could easily use custom values to store that information on the units.

I'd recommend something that looks like:


Code:
E: Unit manipulates item
C: Item type of (item being manipulated = item type X)
C: Or (multiple)
Unit has item of type X in slot 1 = true
Unit has item of type X in slot 2 = true
...
Unit has item of type X in slot 6 = true
A: Remove (item being manipulated)

For reference, that is an item type comparison and 6 boolean hero inventory slot comparisons.

No comments:

Post a Comment