• 🏆 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!

Owner of item

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
what does owning an item mean if someone else's unit is holding it? what are you trying to do?
There is a courier that have the ability of give items to a hero, but it can be shared to your allies and I want the courier only gives the items to the hero that are owned to the owner of that item and who issue the order.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Use an Item Indexer and link the owning Player to the Item upon creation.

Item Indexer v1.4.0 [GUI friendly]

Example:
  • Create an Item
  • Set Variable ItemOwner[custom value of last created item] = Player 1
ItemOwner = Player (Array)

Whenever you reference ItemOwner[custom value of some item], it will return the owning Player for that item.

Example of looping through an inventory of items and checking each item's owner:
  • Set Variable Hero = the unit carrying the items
  • Set Variable HeroPlayer = Owner of Hero
  • For each Integer A from 1 to 6 do:
  • If ItemOwner[custom value of item carried by Hero in slot Integer A] equal to HeroPlayer then we know that the item belongs to this player
Note that the triggers will look slightly different in the actual Trigger Editor.
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
Use an Item Indexer and link the owning Player to the Item upon creation.

Item Indexer v1.4.0 [GUI friendly]

Example:
  • Create an Item
  • Set Variable ItemOwner[custom value of last created item] = Player 1
ItemOwner = Player (Array)

Whenever you reference ItemOwner[custom value of some item], it will return the owning Player for that item.

Example of looping through an inventory of items and checking each item's owner:
  • Set Variable Hero = the unit carrying the items
  • Set Variable HeroPlayer = Owner of Hero
  • For each Integer A from 1 to 6 do:
  • If ItemOwner[custom value of item carried by Hero in slot Integer A] equal to HeroPlayer then we know that the item belongs to this player
Note that the triggers will look slightly different in the actual Trigger Editor.
I already know that I must assign a value or something similar to the object, what I want to know is how to make that value relate to the player who bought it?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Hmm? Is that not what I showed you?

You reference ItemOwner, plug the item's custom value in the Index, and it will return you the Player that owns the item.

Edit:

Oh I see, you want the purchasing PLAYER not the owner of the unit that acquired the item. That's tricky...

Not sure if this works?
  • (Owner of (Item being manipulated)) Equal to Player 1 (Red)
If not, there might be another way of doing it but I don't think it's going to be a pretty solution.

The only Events revolving around items are "A unit manipulates an item", so all you have access to is the unit, not the player that gave the actual purchase order.

Perhaps you could keep track of a Player's gold to determine the REAL purchasing player. Have two variables, PreviousGold and CurrentGold. So when Player 2 spends gold, their CurrentGold is updated to their new gold amount, and their PreviousGold remains as what their gold was prior to the purchase.

Then you can make some comparison checks to see which player's gold has changed by the gold cost of the item. So if the item cost 200 gold, and you loop through all of the players, you'll know that whichever player has lost 200 gold (by comparing their prev to current gold) was the one to purchase the item.

There would be a bit more to it than just that, as you'd have to account for gold changes unrelated to items and you'd have to handle PreviousGold/CurrentGold correctly. PreviousGold should be updated AFTER you've compared the two values in the Acquiring Item trigger.
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
Hmm? Is that not what I showed you?

You reference ItemOwner, plug the item's custom value in the Index, and it will return you the Player that owns the item.

Edit:

Oh I see, you want the purchasing PLAYER not the owner of the unit that acquired the item. That's tricky...

Not sure if this works?
  • (Owner of (Item being manipulated)) Equal to Player 1 (Red)
If not, there might be another way of doing it but I don't think it's going to be a pretty solution.

The only Events revolving around items are "A unit manipulates an item", so all you have access to is the unit, not the player that gave the actual purchase order.

Perhaps you could keep track of a Player's gold to determine the REAL purchasing player. Have two variables, PreviousGold and CurrentGold. So when Player 2 spends gold, their CurrentGold is updated to their new gold amount, and their PreviousGold remains as what their gold was prior to the purchase.

Then you can make some comparison checks to see which player's gold has changed by the gold cost of the item. So if the item cost 200 gold, and you loop through all of the players, you'll know that whichever player has lost 200 gold (by comparing their prev to current gold) was the one to purchase the item.

There would be a bit more to it than just that, as you'd have to account for gold changes unrelated to items and you'd have to handle PreviousGold/CurrentGold correctly. PreviousGold should be updated AFTER you've compared the two values in the Acquiring Item trigger.

Thank you, but what you say is complicated and I think it can cause bugs since any player who loses gold can be taken and I also have a detonator that gives players 1 gold every 0.8 seconds. But well, I had already fixed the problem, I just wanted to know if there was a way to make it easier.

For do that I made instead to buy an item, you buy a unit and then create the item change the owner of the item to the owner of the sold unit and then eliminate the unit, but I wanna know if there is a direct way to do that.
 
Status
Not open for further replies.
Top