Hashtable help

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi! I made this trigger for a quest. There are several 'Dust' in the area, and heroes have to pick them. But If a hero picks one, I need to disable the pick of that dust for that hero/player. Also, the hero has to pick them all without dying. If the hero dies, I have to set to DustCount for that hero to 0, and re-enable the pick of the dust for that hero.

Managed to do this:
  • Quest2DustFind
    • Events
      • Unit - A unit begins casting an ability
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Ability being cast) Equal to Explore
      • DustCollected[Player number of (Owner of (Triggering Unit))] Less than 20
    • Actions
      • Set tempPoint = (Position of (Triggering unit))
      • Destructible - Pick every destructible within 100.00 of tempPoint and do (Actions)
        • Loop - Actions
          • Set TempBool = (Load (Key (Picked destructible)) of (Player number of (Triggering player)) from DustHashtable)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TEmpBool Equal to False
              • (Destructible-type of (Picked destructible)) Equal to Removable Dust
            • Then - Actions
              • Set DustCollected[Player number of (Owner of (Triggering Unit))] = (DustCollected[Player number of (Owner of (Triggering Unit))] + 1)
              • Hashtable - Save True as (Key (Picked destructible)) of (Player number of (Triggering player)) in DustHashtable
            • Else - Actions
      • Custom script: call RemoveLocation(udg_tempPoint)
 
  • (Owner of (Triggering Unit)
Could be replaced with (Triggering player), just like your TempBool loading.

You will need some integers here:
  • Actions
    • Set Point = (Position of (Triggering unit))
    • Custom script: set udg_Id = GetHandleId (GetTriggerUnit())
    • Destructible - Pick every destructible within 200.00 of Point and do (Actions)
      • Loop - Actions
        • Custom script: set udg_DesType = GetDestructableTypeId (GetEnumDestructable())
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (DesType is stored as a Integer of Id in Hash) Equal to True
          • Then - Actions
            • Game - Display to (All players) the text: You have already co...
          • Else - Actions
            • Hashtable - Save DesType as DesType of Id in Hash
            • Game - Display to (All players) the text: This is a new type ...
    • Custom script: call RemoveLocation (udg_Point)
  • Death
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Conditions here)
    • Actions
      • Custom script: set udg_Id = GetHandleId (GetTriggerUnit())
      • Hashtable - Clear all child hashtables of child Id in Hash
Please read: In the test map, I made the whole thing activate on the hold position command. Just go near a destructible and press the hold position button. If the destructible is not saved, it will bring up a message that you have already gathered that specific type. If it is saved, it will still inform you (for testing purposes) that it is not saved, but it will be saved now.
 

Attachments

  • CollectDust.w3x
    17.6 KB · Views: 142
Level 20
Joined
Jul 14, 2011
Messages
3,213
Ok... I already don't understand HASHtables.. and now you're using them in custom scripts xD

  • DustFind
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Ability being cast) Equal to Explore
      • LifeDustCount[(Player number of (Owner of (Triggering unit)))] Less than or equal to 20
    • Actions
      • Set PNOBU = (Player number of (Owner of (Triggering unit)))
      • Set Point = (Position of (Triggering unit))
      • Custom script: set udg_Id = GetHandleId (GetTriggerUnit())
      • Destructible - Pick every destructible within 120.00 of Point and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Removable Dust
            • Then - Actions
              • Custom script: set udg_DesType = GetHandleId (GetEnumDestructable())
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (DesType is stored as a Integer of Id in Hash) Equal to False
                • Then - Actions
                  • Hashtable - Save DesType as DesType of Id in Hash
                  • Set LifeDustCount[PNOBU] = (LifeDustCount[PNOBU] + 1)
                  • Game - Display to (All players) the text: (Life Dust collected: |cffffcc00 + ((String(LifeDustCount[PNOBU])) + |r.))
                • Else - Actions
                  • Game - Display to (All players) the text: |cffff0000You have ...
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LifeDustCount[PNOBU] Equal to 20
        • Then - Actions
          • Game - Display to (All players matching ((Owner of (Triggering unit)) Equal to (Matching player))) the text: Main Quest Updated!
        • Else - Actions
      • Custom script: call RemoveLocation(udg_Point)
All the dusts are the same destructible type. I can pick any of them the first time, but after that, the game detects any of the dust as an already picked destructible.

EDIT: Ok, It works now: excluded all the other destructibles and changed:
'GetDestructableTypeId (GetEnumDestructable())'
for
'GetHandleId (GetEnumDestructable())
 
Last edited:
Status
Not open for further replies.
Top