Acquiring and losing items not displaying correct count

Status
Not open for further replies.
Level 5
Joined
Dec 29, 2008
Messages
61
Whenever my hero acquires an item the count starts from -1. So say the Hero acquires a Stolen Sack. The first time the item is acquired the item count increments from -1 to 0.

Whenever my hero drops an item the count actually increases by 1. Say I have 4 Stolen Sacks. If I drop one the count goes up to 5.

I cant explain this behaviour at all. I feel like I'm making a simple mistake somewhere.

  • Events
    • Unit - A unit Acquires an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Stolen Sack
    • ((Hero manipulating item) is A Hero) Equal to True
  • Actions
    • Set VariableSet QuestingPlayerNumber = (Player number of (Owner of (Hero manipulating item)))
    • Set VariableSet StolenSacksItemCount[QuestingPlayerNumber] = (StolenSacksItemCount[QuestingPlayerNumber] + 1)
    • Game - Display to (Player group(mPlayer[QuestingPlayerNumber])) the text: ((String(StolenSacksItemCount[QuestingPlayerNumber])) + /4 Sacks Collected)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • StolenSacksItemCount[QuestingPlayerNumber] Greater than or equal to 4
      • Then - Actions
        • Set VariableSet StolenSacksQuestStep[QuestingPlayerNumber] = 2
      • Else - Actions
  • Events
    • Unit - A unit Loses an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Stolen Sack
    • ((Hero manipulating item) is A Hero) Equal to True
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • StolenSacksQuestStep[PlayerNumber] Equal to 2
      • Then - Actions
        • Set VariableSet QuestingPlayerNumber = (Player number of (Owner of (Hero manipulating item)))
        • Set VariableSet StolenSacksItemCount[QuestingPlayerNumber] = (StolenSacksItemCount[QuestingPlayerNumber] - 1)
        • Game - Display to (Player group(mPlayer[QuestingPlayerNumber])) the text: ((String(StolenSacksItemCount[QuestingPlayerNumber])) + /4 Sacks Collected)
      • Else - Actions
Edit: This script works as intended.
 
Last edited:
Level 5
Joined
Dec 29, 2008
Messages
61
It suddenly started working which means that there was some kind of interference going on but unfortunately I was unable to isolate it.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Oh, you're checking PlayerNumber again before setting it. You can't do that!
  • StolenSacksQuestStep[PlayerNumber] Equal to 2
  • Events
    • Unit - A unit Loses an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Stolen Sack
    • ((Hero manipulating item) is A Hero) Equal to True
  • Actions
    • Set VariableSet QuestingPlayerNumber = (Player number of (Owner of (Hero manipulating item)))
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • StolenSacksQuestStep[QuestingPlayerNumber] Equal to 2
      • Then - Actions
        • Set VariableSet StolenSacksItemCount[QuestingPlayerNumber] = (StolenSacksItemCount[QuestingPlayerNumber] - 1)
        • Game - Display to (Player group(mPlayer[QuestingPlayerNumber])) the text: ((String(StolenSacksItemCount[QuestingPlayerNumber])) + /4 Sacks Collected)
      • Else - Actions
But I'm not entirely following what you're trying to do here.

This looks like it will break if you lose a Sack during step 1 since StolenSacksItemCount won't get reduced by 1.
 
Last edited:
Level 5
Joined
Dec 29, 2008
Messages
61
I made it so quest items are un-droppable so that shouldn't affect my game, but I don't think I understand what you're saying either way. If I have 1 Stolen Sack, and remove it shouldn't it just go to 0?
 
Level 5
Joined
Dec 29, 2008
Messages
61
But there's no way to lose a sack if you don't have one already? And there's no way to have one without picking one up.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I'm not even sure if you're still having an issue or not after applying my suggested fix, but here's a Quest example map. Bring the four Chickens to the farm to finish the quest. You can drop the Chickens without breaking the Quest. Also, this could easily be made to use Item Charges so that you only need 1 Item slot for the Quest items.

You could also toggle the Quest Turn In trigger to be Off by default and On while someone has a Chicken in their inventory, this way it's only running when necessary.
 

Attachments

  • Quest Item Example 1.w3m
    22.1 KB · Views: 5
Level 5
Joined
Dec 29, 2008
Messages
61
Thanks for the tutorial. Very helpful. As for turning them into charges, that would be idea. Is there a way to make an item with charges that can't be consumed?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
So charges were a little bit more complicated than I remembered but I got it working. In the Gameplay Constants menu you need to turn on Enable Item Stacking under the Inventory category. Then in the Object Editor you need to set your Item's Number of Charges and Max Stacks to the proper values.

The way I designed the system is that your Max Stacks should go beyond the actual limit that you want. This is because I trigger the limit myself. To do this, I created some Jass functions which when called make your Unit drop any excess item charges that they may have. You can see this being done in the Lost Chickens Acquire Item trigger.

So if your unit has 4/4 Chickens and then let's say your Ally walks up and gives you another 3, the function kicks in and detects that you now have 7 charges on your single Chicken, and "drops" 3 of the Chickens on the ground.

However, it doesn't actually drop any items on the ground, it just appears to do that. This is because the two items have already combined into one by the time the "A unit Acquires an item" Event has fired. To get around this I create a new Item on the ground whose charges are equal to the excess number of charges (7 - 4 = 3) and then adjust the number of charges on your combined item to be equal to the max stack size that you defined in the trigger (4).

The four functions I created allow you to either drop the excess item charges at the position of a Unit or at a given Point. You can also choose whether it drops a single Item with all of the excess charges or 1 item per excess charge. In the map I'm using DropExcessCharges() which simply drops a single Item at the position of the Unit. DropExcessChargesSplit() will split them up into multiple items.

These are the four functions:
  • Custom script: call DropExcessCharges( the unit, the item, the max stacks allowed )
  • Custom script: call DropExcessChargesSplit( the unit, the item, the max stacks allowed )
  • Custom script: call DropExcessChargesAtLoc( the point, the item, the max stacks allowed )
  • Custom script: call DropExcessChargesSplitAtLoc( the point, the item, the max stacks allowed )
You need to supply the correct data in the (parenthesis) when calling them.
 

Attachments

  • Quest Item Example 2.w3m
    23.1 KB · Views: 5
Last edited:
Status
Not open for further replies.
Top