• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

hashtable, what am I supposed to be doing?

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
Edit: Icemanbo helped me out and I think I can manage the rest.

I put together some trigger for testing how I would allow a unit to basically browse a shop and go through categories/lists of abilities to learn (in a single shop). since it was just for testing i quickly made some if statements and got it to work

  • CusAbi 2
    • Events
      • Unit - A unit Sells a unit
    • Conditions
    • Actions
      • Set tempUnit = (Sold unit)
      • Set tempUtype = (Unit-type of tempUnit)
      • Unit - Remove tempUnit from the game
      • Set tempUnit = (Buying unit)
      • Set tempPlayer = (Owner of tempUnit)
      • -------- Find player number --------
      • For each (Integer i) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player(i)) slot status) Equal to Is playing
              • tempPlayer Equal to (Player(i))
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • tempUtype Equal to Return to the all catagories tab (dummy unit)
                • Then - Actions
                  • -------- Clear --------
                  • Neutral Building - Remove Return to the all catagories tab (dummy unit) from cusAbi_unit_shop[i]
                  • Neutral Building - Remove Berserk (no target dummy) from cusAbi_unit_shop[i]
                  • ETC
                  • -------- Add Categories --------
                  • Neutral Building - Add No target abilities tab (dummy unit) to cusAbi_unit_shop[i] with 0 in stock and a max stock of 1
                  • Neutral Building - Add PBAoE abilities tab (dummy unit) to cusAbi_unit_shop[i] with 0 in stock and a max stock of 1
                  • ETC
                • Else - Actions
                  • -------- Check which category was selected --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • tempUtype Equal to No target abilities tab (dummy unit)
                    • Then - Actions
                      • -------- Clear --------
                      • Neutral Building - Remove No target abilities tab (dummy unit) from cusAbi_unit_shop[i]
                      • Neutral Building - Remove PBAoE abilities tab (dummy unit) from cusAbi_unit_shop[i]
                      • ETC
                      • -------- Add Categories --------
                      • Neutral Building - Add Berserk (no target dummy) to cusAbi_unit_shop[i] with 0 in stock and a max stock of 1
                      • -------- Return & Next page --------
                      • Neutral Building - Add Return to the all catagories tab (dummy unit) to cusAbi_unit_shop[i] with 0 in stock and a max stock of 1
                    • Else - Actions
                      • -------- Continue Forever and Ever --------
                        • -------- No category was selected --------
                        • -------- An ability dummy is bought --------
                        • Set cusAbi_Int_AbiAmount[i] = (cusAbi_Int_AbiAmount[i] + 1)
                        • -------- Check which ability was picked --------
                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • tempUtype Equal to Berserk (no target dummy)
                          • Then - Actions
                            • -------- Check if Ability hasn't already been picked --------
                            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • If - Conditions
                                • (Level of Berserk (Engineering 1-5) for tempUnit) Equal to 0
                              • Then - Actions
                                • -------- add ability --------
                                • Player - Disable Berserk (Spellbook 1-5) for tempPlayer
                                • Unit - Add Berserk (Spellbook 1-5) to tempUnit
                                • Unit - Set level of Berserk (Engineering 1-5) for tempUnit to cusAbi_Int_AbiAmount[i]
                                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                  • If - Conditions
                                    • cusAbi_Int_AbiAmount[i] Equal to 1
                                  • Then - Actions
                                    • Unit - Add Berserk (slot 1) to tempUnit
                                  • Else - Actions
                                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                      • If - Conditions
                                        • cusAbi_Int_AbiAmount[i] Equal to 2
                                      • Then - Actions
                                        • Unit - Add Berserk (slot 2) to tempUnit
                                      • Else - Actions
                                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                          • If - Conditions
                                            • cusAbi_Int_AbiAmount[i] Equal to 3
                                          • Then - Actions
                                            • Unit - Add Berserk (slot 3) to tempUnit
                                          • Else - Actions
                                            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                              • If - Conditions
                                                • cusAbi_Int_AbiAmount[i] Equal to 4
                                              • Then - Actions
                                                • Unit - Add Berserk (slot 4) to tempUnit
                                              • Else - Actions
                                                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                  • If - Conditions
                                                    • cusAbi_Int_AbiAmount[i] Equal to 5
                                                  • Then - Actions
                                                    • Unit - Add Berserk (slot 5) to tempUnit
                                                  • Else - Actions
                              • Else - Actions
                                • -------- Already have ability --------
                                • Set cusAbi_Int_AbiAmount[i] = (cusAbi_Int_AbiAmount[i] - 1)
                                • Game - Display to (Player group(tempPlayer)) the text: You can't have more...
I thought if I used a Hashtable and then predetermine what each dummy ID would have for values bound to them I could load the value(s) I needed from the IDs instead of using billions of ifs or looping through arrays.

From tutorials I had read it was usually just about making abilities mui and not really getting lots of different values from one value in the way I intend, at least I don't think so.

So I put together something I thought would kind of do something like it, although I don't really know what I'm doing tbh.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Sells a unit
    • Conditions
    • Actions
      • Custom script: local unit u = GetSoldUnit()
      • Custom script: local player p = GetTriggerPlayer()
      • Custom script: local integer uType = LoadInteger(udg_hash, GetUnitTypeId(u), 0)
      • Custom script: if uType != 0 then
      • Custom script: set i = uType - 12 (number of dummies per page)
      • Custom script: loop
      • Custom script: exitwhen i == uType
      • Custom script: call AddUnitToStock(udg_cusAbi_unit_shop[(GetConvertedPlayerId(p)], udg_cusAbi_uType[i], 0, 1)
      • Custom script: set i = i + 1
      • Custom script: endloop
      • Custom script: else
udg_cusAbi_uType is supposed to be a unit type of different dummies that would represent either a category in a shop, return to main page or learn an ability.

If uType would be 0 it should mean that the unit type of the sold unit represented an ability (instead of a category) and it would not change what units are being sold
 
Last edited:
Level 12
Joined
Nov 3, 2013
Messages
989
Your loop doesn't make much sense, it's same as you directly would do the AddUnitToStock function but with uType instead of i.

Also, do you know player "p" is the player who owns the shop, not thw owner of sold unit?

udg_cusAbi_unit_shop[(GetConvertedPlayerId(p)] would be the players own shop that sells the dummy units.

as for the loop, it should have been like set i = uType - 12 instead of integer i = 0 (so it should make a loop and place all 12 dummies per page), but it still isn't really what im trying to get.

What I think I should be doing is to have the parent key represent which page should be shown and then it would loop through all the child keys under that parent and they would be added, but I don't know.
 
I don't exactly know the settings but what you always do is adding cusAbi_uType[0-11] to cusAbi_unit_shop[(GetConvertedPlayerId(p)].

- always same units are added to stock
- units never get removed from stock

If you want to use uType as key, then loading should look something like:

loop 12 times --> AddUnitToStock(whichShop, LoadInteger(hash, uType, loopIndex), currentStock, stockMax)
 
Level 12
Joined
Nov 3, 2013
Messages
989
I think this will give a better idea of what I'm trying to make

  • Hashtable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: local integer i = 0
      • Custom script: local integer a = 11
      • -------- Parent Keys --------
      • Set custom_uTypeCategory[0] = No target abilities tab (dummy unit)
      • Set custom_uTypeCategory[1] = PBAoE abilities tab (dummy unit)
      • Set custom_uTypeCategory[2] = Passive abilities tab (dummy unit)
      • Set custom_uTypeCategory[3] = Single target abilities tab (dummy unit)
      • Set custom_uTypeCategory[4] = Summon abilities tab (dummy unit)
      • Set custom_uTypeCategory[5] = Target point AoE abilities tab (dummy unit)
      • Set custom_uTypeCategory[6] = Target point cone & projectile abilities tab (dummy unit)
      • -------- uTypeCategory[0] Child --------
      • Set custom_uTypeAbility[0] = Berserk (no target dummy)
      • Set custom_uTypeAbility[1] = Immolation (no target dummy)
      • -------- uTypeCategory[1] Child --------
      • Set custom_uTypeAbility[13] = Thunderclap (no target dummy)
      • -------- uTypeCategory[0] Value --------
      • set ability[0] = Berserk (Spellbook)
      • set ability[1] = Immolation (Spellbook)
      • -------- uTypeCategory[1] Value --------
      • set ability[13] = Immolation (Spellbook)
      • Custom script: loop
      • Custom script: exitwhen udg_custom_uTypeCategory[i] == 0
      • Custom script: loop
      • Custom script: exitwhen a == (i + 1) x 12
      • Custom script: call SaveAbilityHandle( udg_hash, custom_uTypeCategory[i], custom_uTypeAbility[a - 12], ability[a - 12] )
      • Custom script: set a = a + 1
      • Custom script: endloop
      • Custom script: set i = i + 1
      • Custom script: endloop
2nd trigger

Event - Sell unit

sold unit type ID == category dummy type (e.g. custom_uTypeCategory[0]) -> remove all category unit type IDs from shop and add all child keys unit ID to shop

sold unit type id is ability dummy (e.g. custom_uTypeAbility[0]) -> give buying unit spellbook (ability[0])
 
Status
Not open for further replies.
Top