• 🏆 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 can I make items bound to a player?

Status
Not open for further replies.
Level 2
Joined
Feb 6, 2020
Messages
6
Like the title says. Trying to make it so that if someone picks up an item, no one else can pick that item up if they drop it or try to give it to someone else.
 
Level 39
Joined
Feb 27, 2007
Messages
4,989
A hashtable storing the owner of the item will be simplest here. You read from the table and if it doesn't match the player stored there make the unit drop the item.
  • Hashtable - Create a new hashtable
  • Set ItemHash = (Last created hashtable)
  • -------- do that in an init trigger --------
  • Events
    • Unit - A unit acquires an item
  • Conditions
    • ((Item-type of (Item being manipulated)) is A powerup) Equal to False //tomes don't matter since they get used when picked up
  • Actions
    • Set TempItem = (Item being manipulated)
    • Set OwnPlayer = (Load Key("owner") of Key(TempItem) in ItemHash)
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • OwnPlayer equal to (Picked Player)
        • -------- a note about the above line: Picked Player does NOT exist here and I'm not using it to mean "Picked Player". The hashtable load function will return a null player if the item has no owner, but for some godforsaken reason Blizzard doesn't allow us to compare if a player variable is = no player (null) like you can with units or items. --------
        • -------- By using Picked Player in this way it will return null and we can compare to it. There is no player being picked. You could instead create a player variable and set it = null on map init and compare vs that. --------
      • Then - Actions
        • Hashtable - Save Handle of (Owner of (Triggering Unit)) as Key("owner") of Key(TempItem) in ItemHash
        • Skip remaining actions
      • Else - Actions
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • OwnPlayer not equal to (Owner of (Triggering Unit)
      • Then - Actions
        • Hero - Drop TempItem from (Triggering Unit)
      • Else - Actions
It's not strictly necessary but it's probably nice to clear the hashtable of unnecessary data when items are destroyed/pawned/removed, so you can do that too:

  • Events
    • Unit - A unit pawns an item
    • -------- there are no generic item death events or remove events, but if you are doing these yourself then you know when it happens and can do what this trigger does then --------
  • Conditions
  • Actions
    • Hashtable - Flush all child hashtables of Key(Item being manipulated)
 
Level 2
Joined
Feb 6, 2020
Messages
6
Had to change the hero - drop line to 'item being manipulated' rather than the TempItem variable, but other than that seems to work perfectly. Thanks +rep'd
 
Last edited:
Status
Not open for further replies.
Top