- Joined
- Jun 26, 2020
- Messages
- 1,928
Hello, I wanna know how to change the owner of a item to the player who bought it, not the owner of the adquiring unit, the player who press the button to buy, like hiring a hero in a tabern using an ally unit.
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.what does owning an item mean if someone else's unit is holding it? what are you trying to do?
Ok i will prove it for see if that works.
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?Use an Item Indexer and link the owning Player to the Item upon creation.
Item Indexer v1.4.0 [GUI friendly]
Example:
ItemOwner = Player (Array)
Create an Item
Set Variable ItemOwner[custom value of last created item] = Player 1
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:
Note that the triggers will look slightly different in the actual Trigger Editor.
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
I did that and when I bought an item I got the owner of the shop.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.
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?
If not, there might be another way of doing it but I don't think it's going to be a pretty solution.
(Owner of (Item being manipulated)) Equal to Player 1 (Red)
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.
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.