Help with my inventory system

Tawnttoo

New Member
Reaction score
36
I'm creating an inventory system to work around the limitations with items in wc3. I save the items in hashtables on picking them up, but I seem to be unable to clear the item from memory when the unit loses its item.

Map attached, problems are in the trigger 'Lose Item'
 

Attachments

  • Inventory system v.0.1.w3x
    26.1 KB · Views: 130

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
please post the system/trigger, id rather not download a map and open wc3/WE etc
 

Tawnttoo

New Member
Reaction score
36
WARNING: IMMENSE POST

If you insist:

Trigger:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Inventory = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set Inventory_Hash = (Last created hashtable)
      • Set TempPoint = (Center of (Playable map area))
      • Set TempGroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Hashtable - Save 0 as (Key bagslot) of (Key (Picked unit)) in Inventory
          • Hashtable - Save (Key itemcount) as (Key itemcount) of (Key (Picked unit)) in Inventory
          • Hashtable - Save 2 as (Key maxbags) of (Key (Picked unit)) in Inventory
          • For each (Integer TempInt) from 1 to (Load (Key maxbags) of (Key (Picked unit)) from Inventory), do (Actions)
            • Loop - Actions
              • Item - Create Bag at TempPoint
              • Item - Hide (Last created item)
              • Hashtable - Save Handle Of(Last created item) as (Key (Item + (String(((TempInt x 6) - 5))))) of (Key (Picked unit)) in Inventory
      • Custom script: call DestroyGroup (udg_TempGroup)
      • Custom script: call RemoveLocation (udg_TempPoint)


Trigger:
  • Open Bag
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Bag
    • Actions
      • Set TempPoint = (Center of (Playable map area))
      • For each (Integer TempInt) from 1 to 6, do (Actions)
        • Loop - Actions
          • Hashtable - Save Handle Of(Item carried by (Triggering unit) in slot TempInt) as (Key (Item + (String((TempInt + (6 x (Load (Key bagslot) of (Key (Triggering unit)) from Inventory))))))) of (Key (Triggering unit)) in Inventory
          • Trigger - Turn off Lose Item <gen>
          • Item - Move (Item carried by (Triggering unit) in slot TempInt) to TempPoint
          • Item - Hide (Load (Key (Item + (String(((6 x (Load (Key bagslot) of (Key (Triggering unit)) from Inventory)) + TempInt))))) of (Key (Triggering unit)) in Inventory)
          • Trigger - Turn on Lose Item <gen>
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load (Key bagslot) of (Key (Triggering unit)) from Inventory) Equal to 0
        • Then - Actions
          • Game - Display to (Player group((Owner of (Triggering unit)))) the text: Press ESC to close ...
        • Else - Actions
      • Hashtable - Save ((Load (Key bagslot) of (Key (Triggering unit)) from Inventory) + 1) as (Key bagslot) of (Key (Triggering unit)) in Inventory
      • For each (Integer TempInt) from 1 to 6, do (Actions)
        • Loop - Actions
          • Item - Show (Load (Key (Item + (String((TempInt + (6 x (Load (Key bagslot) of (Key (Triggering unit)) from Inventory))))))) of (Key (Triggering unit)) in Inventory)
          • Hero - Give (Load (Key (Item + (String((TempInt + (6 x (Load (Key bagslot) of (Key (Triggering unit)) from Inventory))))))) of (Key (Triggering unit)) in Inventory) to (Triggering unit)
      • Item - Set charges remaining in (Item carried by (Triggering unit) of type Bag) to (Load (Key bagslot) of (Key (Triggering unit)) from Inventory)
      • Custom script: call RemoveLocation (udg_TempPoint)


Trigger:
  • Close Bag
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set TempPoint = (Center of (Playable map area))
      • Set TempGroup = (Units currently selected by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • For each (Integer TempInt) from 1 to 6, do (Actions)
            • Loop - Actions
              • Hashtable - Save Handle Of(Item carried by (Picked unit) in slot TempInt) as (Key (Item + (String((TempInt + (6 x (Load (Key bagslot) of (Key (Picked unit)) from Inventory))))))) of (Key (Picked unit)) in Inventory
              • Trigger - Turn off Lose Item <gen>
              • Item - Move (Item carried by (Picked unit) in slot TempInt) to TempPoint
              • Item - Hide (Load (Key (Item + (String(((6 x (Load (Key bagslot) of (Key (Picked unit)) from Inventory)) + TempInt))))) of (Key (Picked unit)) in Inventory)
              • Trigger - Turn on Lose Item <gen>
              • Item - Show (Load (Load (Key (Item + (String(TempInt)))) of (Key (Picked unit)) from Inventory) of (Key (Picked unit)) in Inventory)
              • Hero - Give (Load (Key (Item + (String(TempInt)))) of (Key (Picked unit)) in Inventory) to (Picked unit)
          • Hashtable - Save 0 as (Key bagslot) of (Key (Picked unit)) in Inventory
      • Custom script: call DestroyGroup (udg_TempGroup)
      • Custom script: call RemoveLocation (udg_TempPoint)


Trigger:
  • Lose Item
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Not equal to Bag
    • Actions
      • For each (Integer TempInt) from 1 to (6 + ((Load (Key maxbags) of (Key (Triggering unit)) from Inventory) x 6)), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item being manipulated) Equal to (Load (Key (Item + (String(TempInt)))) of (Key (Triggering unit)) in Inventory)
            • Then - Actions
              • Hashtable - Save Handle OfNo item as (Key (Item + (String(TempInt)))) of (Key (Triggering unit)) in Inventory
            • Else - Actions




Trigger:
  • FIS Trigger
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Target item of issued order) Not equal to No item
      • (Issued order) Equal to (Order(smart))
    • Actions
      • Hashtable - Save Handle Of(Target item of issued order) as (Key kohde) of (Key (Triggering unit)) in Inventory_Hash
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load (Key itemcount) of (Key (Triggering unit)) from Inventory) Equal to (6 x ((Load (Key maxbags) of (Key (Triggering unit)) from Inventory) + 1))
        • Then - Actions
          • For each (Integer A) from 1 to ((Load (Key maxbags) of (Key (Triggering unit)) from Inventory) x 6), do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Charges remaining in (Load (Key kohde) of (Key (Triggering unit)) in Inventory_Hash)) Not equal to 0
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Item-type of (Load (Key (Item + (String((Integer A))))) of (Key (Triggering unit)) in Inventory)) Equal to (Item-type of (Load (Key kohde) of (Key (Triggering unit)) in Inventory_Hash))
                    • Then - Actions
                      • Trigger - Turn off FIS Cancel <gen>
                      • Unit - Order (Triggering unit) to Move To (Target item of issued order)
                      • Trigger - Turn on FIS Cancel <gen>
                    • Else - Actions
                      • Game - Display to (All players) the text: Inventory full
                      • Unit - Order (Triggering unit) to Stop
                • Else - Actions
                  • Game - Display to (All players) the text: Inventory full
                  • Unit - Order (Triggering unit) to Stop
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of items carried by (Triggering unit)) Equal to 6
            • Then - Actions
              • Trigger - Turn off FIS Cancel <gen>
              • Unit - Order (Triggering unit) to Move To (Target item of issued order)
              • Trigger - Turn on FIS Cancel <gen>
            • Else - Actions


Trigger:
  • FIS Cancel
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Target item of issued order) Not equal to (Load (Key kohde) of (Key (Triggering unit)) in Inventory_Hash)
      • (Load (Key kohde) of (Key (Triggering unit)) in Inventory_Hash) Not equal to No item
    • Actions
      • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in Inventory_Hash


Trigger:
  • FIS Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set TempGroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Hashtable - Save Handle Of(Position of (Picked unit)) as (Key unit) of (Key (Picked unit)) in Inventory_Hash
          • Hashtable - Save Handle Of(Position of (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash)) as (Key item) of (Key (Picked unit)) in Inventory_Hash
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash) Not equal to No item
              • (Distance between (Load (Key unit) of (Key (Picked unit)) in Inventory_Hash) and (Load (Key item) of (Key (Picked unit)) in Inventory_Hash)) Less than or equal to 150.00
            • Then - Actions
              • For each (Integer TempInt) from 1 to (Load (Key maxbags) of (Key (Picked unit)) from Inventory), do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Load (Key (Item + (String(((Integer A) + (6 x TempInt)))))) of (Key (Picked unit)) in Inventory)) Equal to (Item-type of (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash))
                          • (Charges remaining in (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash)) Not equal to 0
                        • Then - Actions
                          • Item - Set charges remaining in (Load (Key (Item + (String(((Integer A) + (6 x TempInt)))))) of (Key (Picked unit)) in Inventory) to ((Charges remaining in (Load (Key (Item + (String(((Integer A) + (TempInt x 6)))))) of (Key (Picked unit)) in Inventory)) + (Charges remaining in (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash)))
                          • Item - Hide (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash)
                          • Unit - Order (Picked unit) to Stop
                          • Skip remaining actions
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Load (Key (Item + (String(((Integer A) + (TempInt x 6)))))) of (Key (Picked unit)) in Inventory) Equal to No item
                        • Then - Actions
                          • Hashtable - Save Handle Of(Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash) as (Key (Item + (String(((Integer A) + (6 x TempInt)))))) of (Key (Picked unit)) in Inventory
                          • Item - Hide (Load (Key kohde) of (Key (Picked unit)) in Inventory_Hash)
                          • Unit - Order (Picked unit) to Stop
                          • Skip remaining actions
                        • Else - Actions
            • Else - Actions
      • Custom script: call DestroyGroup (udg_TempGroup)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
what i would do is set all values when it is made to 0 or something like it, so it can be saved to 0 when dropped, and when an item is dropped u need to save all empty slots as 0 not just the slot it was in, because its no longer in a slot when dropped that doesnt define a slot
 

HydraRancher

Truth begins in lies
Reaction score
197
Just curious, I see you use TempInt a lot. Where do you actually save it as a variable?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
did you check whether or not one of your variables had; event - unit drops an item; and used item slot of item being manipulated? if it does it wont work because once the event triggers it has no item slot
 

Tawnttoo

New Member
Reaction score
36
@Hydra: I use it on loops, it works just fine.

The only problem I'm having here is with the 'Lose Item' trigger, I have checked everything, it works just as intended besides it fails to replace the dropped/sold/expired item slot with No Item in the hashtable. I repeat, everything else works as intended.

Code:
Lose Item
Events
Unit - A unit Loses an item
Conditions
(Item-type of (Item being manipulated)) Not equal to Bag
Actions
For each (Integer TempInt) from 1 to (6 + ((Load (Key maxbags) of (Key (Triggering unit)) from Inventory) x 6)), do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Item being manipulated) Equal to (Load (Key (Item + (String(TempInt)))) of (Key (Triggering unit)) in Inventory)
Then - Actions
[COLOR="red"]Hashtable - Save Handle OfNo item as (Key (Item + (String(TempInt)))) of (Key (Triggering unit)) in Inventory[/COLOR]
Else - Actions

[del]EDIT: for some reason, it saves the item back to the inventory, but a page further. There must be a conflict with another trigger.[/del]
[del]EDIT 2: it does it only on the first time, and that time it doesn't run the trigger. I tried to turn off every other trigger in the system and still it doesn't work.[/del] I'm clueless.
[del]EDIT 3: I found the conflict, it works now.[/del]

One more question though: If I wanted to check if the unit had full inventory (on all pages), could I go about it like this?
  • Loop through all the item slots
  • Check if the item slot is occupied (not equal to no item)
  • Check if the number of occupied slots is equal to 6x number of pages
 

Tawnttoo

New Member
Reaction score
36
Bump. I didn't get it to work after all. There is indeed somthing wrong with the 'Lose Item' trigger. It stops working properly as soon as the unit picks up something in a bag slot that isn't the main inventory, opens a bag and closes it. Seems random enough, I need help.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top