[Solved] Loading item handle with item-class restrictions issue

Status
Not open for further replies.
Level 13
Joined
Feb 5, 2018
Messages
567
On this trigger I save the item handle and other stats required for my map to work.

  • Save Unit Data
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet StatsPlayerNumber = (Player number of (Picked player))
          • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of HeroUnit[StatsPlayerNumber])) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Not equal to Peasant
                • Then - Actions
                  • Set VariableSet StatsPlayerNumber = (Player number of (Owner of (Picked unit)))
                  • Set VariableSet HeroUnit[StatsPlayerNumber] = (Picked unit)
                  • Set VariableSet Level[StatsPlayerNumber] = (Level of (Picked unit))
                  • Hashtable - Save Handle Of(Item carried by HeroUnit[StatsPlayerNumber] in slot 1) as 1 of StatsPlayerNumber in HeroHash.
                  • Hashtable - Save Handle Of(Item carried by HeroUnit[StatsPlayerNumber] in slot 2) as 2 of StatsPlayerNumber in HeroHash.
                  • Hashtable - Save Handle Of(Item carried by HeroUnit[StatsPlayerNumber] in slot 3) as 3 of StatsPlayerNumber in HeroHash.
                  • Hashtable - Save Handle Of(Item carried by HeroUnit[StatsPlayerNumber] in slot 4) as 4 of StatsPlayerNumber in HeroHash.
                  • Hashtable - Save Handle Of(Item carried by HeroUnit[StatsPlayerNumber] in slot 5) as 5 of StatsPlayerNumber in HeroHash.
                  • Hashtable - Save Handle Of(Item carried by HeroUnit[StatsPlayerNumber] in slot 6) as 6 of StatsPlayerNumber in HeroHash.
                • Else - Actions

This is my respawn trigger, since my map runs no hero units == the unit has to be created from scratch, this is where I load my items.

  • Sadge
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Peasant
      • (Owner of (Triggering unit)) Not equal to Neutral Hostile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) slot status) Equal to Is playing
        • Then - Actions
          • Wait 15.00 seconds
          • Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at (Center of Myria Village <gen>) facing Default building facing degrees
          • Set VariableSet StatsPlayerNumber = (Player number of (Owner of (Triggering unit)))
          • Set VariableSet HeroUnit[StatsPlayerNumber] = (Last created unit)
          • Unit - Set Unit: HeroUnit[StatsPlayerNumber]'s Integer Field: Level ('ulev') to Value: Level[StatsPlayerNumber]
          • -------- --------
          • Unit - Set Max HP of HeroUnit[StatsPlayerNumber] to (10 + (Toughness[StatsPlayerNumber] x 7))
          • Unit - Set Armor of HeroUnit[StatsPlayerNumber] to ((Real(Agility[StatsPlayerNumber])) + ((Real(Toughness[StatsPlayerNumber])) / 2.00))
          • Unit - Set Max Mana of HeroUnit[StatsPlayerNumber] to (Intelligence[StatsPlayerNumber] x (4 + (Focus[StatsPlayerNumber] / 2)))
          • -------- --------
          • Unit - Set Unit: HeroUnit[StatsPlayerNumber]'s Real Field: Mana Regeneration ('umpr') to Value: ((Real(Focus[StatsPlayerNumber])) / 10.00)
          • Unit - Set Unit: HeroUnit[StatsPlayerNumber]'s Real Field: Hit Points Regeneration Rate ('uhpr') to Value: HpReg_Total[StatsPlayerNumber]
          • Unit - Set Base Damage of HeroUnit[StatsPlayerNumber] to (Strength[StatsPlayerNumber] + (Focus[StatsPlayerNumber] / 2)) for weapon index: 0
          • -------- Load Items --------
          • Trigger - Turn off Testing <gen>
          • Trigger - Turn off Testing2 <gen>
          • Hero - Create (Item-type of (Load 1 of StatsPlayerNumber in HeroHash.)) and give it to HeroUnit[StatsPlayerNumber]
          • Hero - Create (Item-type of (Load 2 of StatsPlayerNumber in HeroHash.)) and give it to HeroUnit[StatsPlayerNumber]
          • Hero - Create (Item-type of (Load 3 of StatsPlayerNumber in HeroHash.)) and give it to HeroUnit[StatsPlayerNumber]
          • Hero - Create (Item-type of (Load 4 of StatsPlayerNumber in HeroHash.)) and give it to HeroUnit[StatsPlayerNumber]
          • Hero - Create (Item-type of (Load 5 of StatsPlayerNumber in HeroHash.)) and give it to HeroUnit[StatsPlayerNumber]
          • Hero - Create (Item-type of (Load 6 of StatsPlayerNumber in HeroHash.)) and give it to HeroUnit[StatsPlayerNumber]
          • Trigger - Turn on Testing <gen>
          • Trigger - Turn on Testing2 <gen>
          • Multiboard - Set the text for PlayerMultiBoards[StatsPlayerNumber] item in column 2, row 7 to (String((Level of HeroUnit[StatsPlayerNumber])))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of HeroUnit[StatsPlayerNumber]) Current lumber) Greater than 0
            • Then - Actions
              • Player - Enable Level Up for (Owner of HeroUnit[StatsPlayerNumber])
            • Else - Actions
        • Else - Actions

Last here are the item restriction triggers.

  • Testing
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • 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 being manipulated) Not equal to (Item carried by (Triggering unit) in slot (Integer A))
              • (Custom value of (Item being manipulated)) Equal to (Custom value of (Item carried by (Triggering unit) in slot (Integer A)))
            • Then - Actions
              • Hero - Drop (Item being manipulated) from (Triggering unit).
              • Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Game:|r Y...
              • Custom script: exitwhen true
            • Else - Actions

  • Testing2
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to |cff0000ffDefender|r (Hero)
          • (Custom value of (Item being manipulated)) Equal to 3
        • Then - Actions
          • Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Game:|r Y...
          • Hero - Drop (Item being manipulated) from (Triggering unit).
        • Else - Actions

So what happend first was, the unit could not equip the loaded items back, it said the unit already had that item. Even thought the inventory was empty.

So I disabled the Item Restriction triggers when the unit loads it's items and its almost fine. He gets the items now and can equip them, but when he drops any item and tries to equip it back, he cannot pick it up anymore, even if the unit had no item of the type currently equipped.
 
Level 13
Joined
Feb 5, 2018
Messages
567
hmm, do you use 0 as custom value? I guess it returns 0 if there is no item in item slot[index]
  • (Custom value of (Item being manipulated)) Equal to (Custom value of (Item carried by (Triggering unit) in slot (Integer A)))

Forgot to mention I index the items based on their class when they are created. Currently 0 is nothing.

I use values from 1-3 at the time, I didn't make it farther, since I am in a deadlock, because of this current issue at hand.
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
Conditions in GUI are called in a seperate function. Certain local variables are not known inside this function (such as Triggering Unit).
This might cause the issue.

Create a global integer variable and replace (Integer A) with your custom variable (not required, but i'd do it anyway)
Create a global unit variable for your triggering unit
Create a global item variable for your item manipulated (i'm not sure if this is required, but i'd do it anyway)
  • Set VariableSet udgIndex = 0
  • Set VariableSet udgUnit = (Triggering Unit)
  • Set VariableSet udgItem = (Item being manipulated)
put them at the top of your actions, and fill them into your trigger. Deactivate your "testing 2" for now, we can fix that later
 
Last edited:
Level 13
Joined
Feb 5, 2018
Messages
567
  • Testing
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet StatsPlayerNumber = (Player number of (Owner of (Triggering unit)))
      • Set VariableSet HeroUnit[StatsPlayerNumber] = (Triggering unit)
      • Set VariableSet TempItem[StatsPlayerNumber] = (Item being manipulated)
      • 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
              • TempItem[StatsPlayerNumber] Not equal to (Item carried by HeroUnit[StatsPlayerNumber] in slot (Integer A))
              • (Custom value of TempItem[StatsPlayerNumber]) Equal to (Custom value of (Item carried by HeroUnit[StatsPlayerNumber] in slot (Integer A)))
            • Then - Actions
              • Hero - Drop TempItem[StatsPlayerNumber] from HeroUnit[StatsPlayerNumber].
              • Game - Display to (Player group((Owner of HeroUnit[StatsPlayerNumber]))) the text: |cffff0000Game:|r Y...
              • Custom script: exitwhen true
            • Else - Actions

Code:
Testing
    Events
        Unit - A unit Acquires an item
    Conditions
    Actions
        Set VariableSet StatsPlayerNumber = (Player number of (Owner of (Triggering unit)))
        Set VariableSet HeroUnit[StatsPlayerNumber] = (Triggering unit)
        Set VariableSet TempItem[StatsPlayerNumber] = (Item being manipulated)
        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
                        TempItem[StatsPlayerNumber] Not equal to (Item carried by HeroUnit[StatsPlayerNumber] in slot (Integer A))
                        (Custom value of TempItem[StatsPlayerNumber]) Equal to (Custom value of (Item carried by HeroUnit[StatsPlayerNumber] in slot (Integer A)))
                    Then - Actions
                        Hero - Drop TempItem[StatsPlayerNumber] from HeroUnit[StatsPlayerNumber].
                        Game - Display to (Player group((Owner of HeroUnit[StatsPlayerNumber]))) the text: |cffff0000Game:|r Y...
                        Custom script:   exitwhen true
                    Else - Actions

I got a bit lost on which trigger on you wanted me to implement this, but I've put it here and nothing changed :)
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
like this ->

  • Set VariableSet udgIndex = 0
  • Set VariableSet udgUnit = (Triggering Unit)
  • Set VariableSet udgItem = (Item being manipulated)
  • For each udgIndex from 1 to 6, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • udgItem Not equal to (Item carried by udgUnit in slot udgIndex)
          • (Custom value of udgItem) Equal to (Custom value of (Item carried by udgUnit in slot udgIndex))
        • Then - Actions
          • Hero - Drop udgItem from udgUnit.
          • Game - Display to (Player group((Owner of udgUnit))) the text: |cffff0000Game:|r Y...
          • Custom script: exitwhen true
        • Else - Actions
 
Level 13
Joined
Feb 5, 2018
Messages
567
like this ->

  • Set VariableSet udgIndex = 0
  • Set VariableSet udgUnit = (Triggering Unit)
  • Set VariableSet udgItem = (Item being manipulated)
  • For each udgIndex from 1 to 6, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • udgItem Not equal to (Item carried by udgUnit in slot udgIndex)
          • (Custom value of udgItem) Equal to (Custom value of (Item carried by udgUnit in slot udgIndex))
        • Then - Actions
          • Hero - Drop udgItem from udgUnit.
          • Game - Display to (Player group((Owner of udgUnit))) the text: |cffff0000Game:|r Y...
          • Custom script: exitwhen true
        • Else - Actions

It has the same outcome :(

  • Testing
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet TempInteger = 0
      • Set VariableSet TempItem2 = (Item being manipulated)
      • Set VariableSet TempUnit = (Triggering unit)
      • For each (Integer TempInteger) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempItem2 Not equal to (Item carried by TempUnit in slot TempInteger)
              • (Custom value of TempItem2) Equal to (Custom value of (Item carried by TempUnit in slot TempInteger))
            • Then - Actions
              • Hero - Drop TempItem2 from TempUnit.
              • Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Game:|r Y...
              • Custom script: exitwhen true
            • Else - Actions
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
The trigger seems fine to me now.
Here is what you could do:
-Copy paste the trigger into a seperate map. this way, you can check if it conflicts with other triggers
-Test it on a hero unit, maybe there is a bug with unit inventory

if it still refuses to work, i'll take a look at it later when i have access to world editor
 
Level 13
Joined
Feb 5, 2018
Messages
567
Nope, nope and nope. I am sorry my friend, it's not working :(

I even added a another condition check on the save unit data
  • ((Picked unit) is alive) Equal to True
So it wouldn't load items from beyond the grave.
 
Level 13
Joined
Feb 5, 2018
Messages
567
This still does not help with the issue that the unit cannot equip any of the items when it loads them back, when it should.

The unit has item 1, 2 and 3. These numbers also indicate the custom values.

Yes it works preventing to have 2 of the same items.

But when the unit dies, it's created from scratch == it loads the items back from hashtable.

Now it also has items 1,2 and 3, but cannot use any of them, because the game thinks it already has those items and/or items with same custom value.

And that is what I wanted to be solved :)

Maybe you misunderstood my issue.

Good effort thought.
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
I understood what you wanted to do, and i still think this is the correct solution to your problem.
The "Testing" trigger does not care what data is inside your hashtable. It does only care about the current inventory of the unit. Which is empty, and thus the item pickup should work.
 
Level 13
Joined
Feb 5, 2018
Messages
567
I understood what you wanted to do, and i still think this is the correct solution to your problem.
The "Testing" trigger does not care what data is inside your hashtable. It does only care about the current inventory of the unit. Which is empty, and thus the item pickup should work.

Oh noo, oh no. Fu*k. Something just occured to me, maybe I need to save the custom value of the items?

Since I create the items from hashtable, does it remember their custom value? I think all the items drawn from the hashtable might have custom value of 0.
 
Status
Not open for further replies.
Top