• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Show Item based on gold ammount

Status
Not open for further replies.
Level 4
Joined
May 12, 2022
Messages
22
I have 5 items placed on the ground(hidden) for each player(6). When a player's gold reaches 100 or more, one of the 5 items should become visible. When it reaches 200 or more gold, two of the items should be visible.. and so on ..
When a player's gold gets bellow 100, all items should become invisible. If for example: the player has 250 gold and then spends 100g remaining with 150g, then only 1 item should remain visible.

1678294169882.png

This is what I got so far ..
  • Untitled Trigger 012
    • Events
      • Player - Player 1 (Red)'s Current gold becomes Greater than or equal to 0.00
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player 1 (Red) Current gold) Greater than or equal to 100
        • Then - Actions
          • Item - Show 'item'
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Player 1 (Red) Current gold) Less than 200
            • Then - Actions
              • Item - Hide 'item'
            • Else - Actions
I know this trigger doesn't make much sense, but I just can't figure out how to do this properly.


Please help if you can,
Thanks!
 
Last edited:
Level 20
Joined
Aug 29, 2012
Messages
829
I think your idea is a good starting point but I would only use it to reveal items. In order to hide them, that depends on what ways players can spend their gold in your map. Here's an example:

  • Hide Items
    • Events
    • Unit - A unit Finishes training a unit
    • Unit - A unit Finishes an upgrade
    • Unit - A unit Pawns an item (to shop)
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Current gold) Less than 200
        • Then - Actions
          • Item - Hide YourItem
        • Else - Actions

Etc. I think you get the idea. You'd need to consider all possible events that might lead to a player losing gold, then you can easily hide their items based on the amount remaining
 
Level 39
Joined
Feb 27, 2007
Messages
5,019
There’s no need to account for every way to lose gold. You can just check the player’s current gold every 0.5s. This is an integer-returning function that is called “Player - Property” instead of something that directly references gold/lumber/food.

How many players should this work for? If more than one, do they all have the same set of items or a separate one for each player? The items could be hidden locally as long as no units can directly interact with them (that includes attacking them to kill them or targeting them in any way).
 
Level 4
Joined
May 12, 2022
Messages
22
In order to hide them, that depends on what ways players can spend their gold in your map.
They spend gold in the shop (on items but also for casting some abilities)

How many players should this work for?
For up to 6 players.

If more than one, do they all have the same set of items or a separate one for each player?
The item is of the same type (Gold Coin) as you can see in the image I attached above. Each player has a set of 5 items for a total of 30.


Also, I think the event might be relevant only lag wise in this case. I'm fine with every 0.5s event or every 1.0 so long it doesn't lag too much.
I'm not actually sure how to make the whole trigger or how many triggers are needed.

How would you guys go about doing this?
 
Level 20
Joined
Feb 27, 2019
Messages
592
  • Gold Indicator Init
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- Player 1 Items --------
      • Set VariableSet GoldItem[11] = Gold Coins 0027 <gen>
      • Set VariableSet GoldItem[12] = Gold Coins 0028 <gen>
      • Set VariableSet GoldItem[13] = Gold Coins 0029 <gen>
      • Set VariableSet GoldItem[14] = Gold Coins 0030 <gen>
      • Set VariableSet GoldItem[15] = Gold Coins 0031 <gen>
      • -------- Player 2 Items --------
      • Set VariableSet GoldItem[21] = Gold Coins 0027 <gen>
      • Set VariableSet GoldItem[22] = Gold Coins 0028 <gen>
      • Set VariableSet GoldItem[23] = Gold Coins 0029 <gen>
      • Set VariableSet GoldItem[24] = Gold Coins 0030 <gen>
      • Set VariableSet GoldItem[25] = Gold Coins 0031 <gen>
      • -------- and so on --------
      • Player Group - Pick every player in YourPlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet PN = (Player number of (Picked player))
          • -------- Set to the gold amount the players start with --------
          • Set VariableSet PrevGoldL[PN] = ((Player(PN)) Current gold)
          • -------- MdaPN = Multi-dimensional array Player Number --------
          • Set VariableSet MdaPN = (PN x 10)
          • For each (Integer GoldL) from 1 to 5, do (Actions)
            • Loop - Actions
              • Item - Hide GoldItem[(MdaPN + GoldL)]
          • -------- Set to True since its not used otherwise it causes a minor issue --------
          • Set VariableSet IsGoldShown[MdaPN] = True
Current gold is divided by 100 which is the amount each gold coin is suppose to indicate.
MdaPN is a multi-dimensional array. You can read about it on chapter 16 here, along with a lot of other useful stuff Things You Should Know When Using Triggers / GUI The number 10 is the size each players has in the array. In this system it needs to be higher than the amount of gold coins for each player (5).
The system only changes the relevant coin/s so you can track the exact coin/s that is/are shown/hidden. If no change are to be done the system doesnt do many unneeded actions but if the gold amount changes a lot its probably still better to use a player group in conjunction with a periodic event.
I didnt try it in multiplayer but I dont see why it shouldnt work.
Hopefully there arnt any bugs I didnt find.
  • Gold Indicator
    • Events
      • Player - Player 1 (Red)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 2 (Blue)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 3 (Teal)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 4 (Purple)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 5 (Yellow)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 6 (Orange)'s Current gold becomes Greater than or equal to 0.00
    • Conditions
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet CurrGoldL = (((Player(PN)) Current gold) / 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrGoldL Equal to PrevGoldL[PN]
        • Then - Actions
          • -------- no change --------
        • Else - Actions
          • Set VariableSet MdaPN = (PN x 10)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CurrGoldL Greater than PrevGoldL[PN]
            • Then - Actions
              • -------- show gold --------
              • For each (Integer GoldL) from PrevGoldL[PN] to CurrGoldL, do (Actions)
                • Loop - Actions
                  • Custom script: exitwhen udg_GoldL > 5
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • IsGoldShown[(MdaPN + GoldL)] Equal to False
                    • Then - Actions
                      • Set VariableSet IsGoldShown[(MdaPN + GoldL)] = True
                      • Item - Show GoldItem[(MdaPN + GoldL)]
                      • Game - Display to (All players) the text: (Show item + (String((MdaPN + GoldL))))
                    • Else - Actions
            • Else - Actions
              • -------- hide gold --------
              • For each (Integer GoldL) from (CurrGoldL + 1) to (PrevGoldL[PN] + 1), do (Actions)
                • Loop - Actions
                  • Custom script: exitwhen udg_GoldL > 5
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • IsGoldShown[(MdaPN + GoldL)] Equal to True
                    • Then - Actions
                      • Set VariableSet IsGoldShown[(MdaPN + GoldL)] = False
                      • Item - Hide GoldItem[(MdaPN + GoldL)]
                      • Game - Display to (All players) the text: (Hide item + (String((MdaPN + GoldL))))
                    • Else - Actions
      • Set VariableSet PrevGoldL[PN] = CurrGoldL
 
Level 4
Joined
May 12, 2022
Messages
22
Thank you, I'll try to remake the trigger and replay here after test. It looks very promising. 😄

Edit:
  • Gold indicator Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- Player 1 --------
      • Set VariableSet ItemArrayGold[1] = Gold Coins 0179 <gen>
      • Set VariableSet ItemArrayGold[2] = Gold Coins 0176 <gen>
      • Set VariableSet ItemArrayGold[3] = Gold Coins 0177 <gen>
      • Set VariableSet ItemArrayGold[4] = Gold Coins 0180 <gen>
      • Set VariableSet ItemArrayGold[5] = Gold Coins 0178 <gen>
      • -------- Player 2 --------
      • Set VariableSet ItemArrayGold[6] = Gold Coins 0174 <gen>
      • Set VariableSet ItemArrayGold[7] = Gold Coins 0171 <gen>
      • Set VariableSet ItemArrayGold[8] = Gold Coins 0172 <gen>
      • Set VariableSet ItemArrayGold[9] = Gold Coins 0175 <gen>
      • Set VariableSet ItemArrayGold[10] = Gold Coins 0173 <gen>
      • -------- Player 3 --------
      • Set VariableSet ItemArrayGold[11] = Gold Coins 0169 <gen>
      • Set VariableSet ItemArrayGold[12] = Gold Coins 0166 <gen>
      • Set VariableSet ItemArrayGold[13] = Gold Coins 0167 <gen>
      • Set VariableSet ItemArrayGold[14] = Gold Coins 0170 <gen>
      • Set VariableSet ItemArrayGold[15] = Gold Coins 0168 <gen>
      • -------- Player 4 --------
      • Set VariableSet ItemArrayGold[16] = Gold Coins 0154 <gen>
      • Set VariableSet ItemArrayGold[17] = Gold Coins 0151 <gen>
      • Set VariableSet ItemArrayGold[18] = Gold Coins 0152 <gen>
      • Set VariableSet ItemArrayGold[19] = Gold Coins 0155 <gen>
      • Set VariableSet ItemArrayGold[20] = Gold Coins 0153 <gen>
      • -------- Player 5 --------
      • Set VariableSet ItemArrayGold[21] = Gold Coins 0149 <gen>
      • Set VariableSet ItemArrayGold[22] = Gold Coins 0145 <gen>
      • Set VariableSet ItemArrayGold[23] = Gold Coins 0146 <gen>
      • Set VariableSet ItemArrayGold[24] = Gold Coins 0150 <gen>
      • Set VariableSet ItemArrayGold[25] = Gold Coins 0147 <gen>
      • -------- Player 6 --------
      • Set VariableSet ItemArrayGold[26] = Gold Coins 0144 <gen>
      • Set VariableSet ItemArrayGold[27] = Gold Coins 0143 <gen>
      • Set VariableSet ItemArrayGold[28] = Gold Coins 0141 <gen>
      • Set VariableSet ItemArrayGold[29] = Gold Coins 0142 <gen>
      • Set VariableSet ItemArrayGold[30] = Gold Coins 0139 <gen>
      • -------- --------
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet PN = (Player number of (Picked player))
          • -------- Set to the gold amount the players start with --------
          • Set VariableSet PrevGold[PN] = ((Player(PN)) Current gold)
          • -------- Multi dimentional array Player number --------
          • Set VariableSet MdaPN = (PN x 10)
          • For each (Integer GoldL) from 1 to 5, do (Actions)
            • Loop - Actions
              • Item - Hide ItemArrayGold[(MdaPN + GoldL)]
          • Set VariableSet IsGoldShown[MdaPN] = True
  • Gold Indicator
    • Events
      • Player - Player 1 (Red)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 2 (Blue)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 3 (Teal)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 4 (Purple)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 5 (Yellow)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 6 (Orange)'s Current gold becomes Greater than or equal to 0.00
    • Conditions
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet CurrentGold = (((Player(PN)) Current gold) / 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentGold Equal to PrevGold[PN]
        • Then - Actions
          • -------- Nothing --------
        • Else - Actions
          • Set VariableSet MdaPN = (PN x 10)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CurrentGold Greater than PrevGold[PN]
            • Then - Actions
              • -------- Show Gold --------
              • For each (Integer GoldL) from PrevGold[PN] to CurrentGold, do (Actions)
                • Loop - Actions
                  • Custom script: exitwhen udg_GoldL > 5
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • IsGoldShown[(MdaPN + GoldL)] Equal to False
                    • Then - Actions
                      • Set VariableSet IsGoldShown[(MdaPN + GoldL)] = True
                      • Item - Show GoldItem[(MdaPN + GoldL)]
                    • Else - Actions
            • Else - Actions
              • -------- Hide Gold --------
              • For each (Integer GoldL) from (CurrentGold + 1) to (PrevGold[PN] + 1), do (Actions)
                • Loop - Actions
                  • Custom script: exitwhen udg_GoldL > 5
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • IsGoldShown[(MdaPN + GoldL)] Equal to True
                    • Then - Actions
                      • Set VariableSet IsGoldShown[(MdaPN + GoldL)] = False
                      • Item - Hide GoldItem[(MdaPN + GoldL)]
                    • Else - Actions
      • Set VariableSet PrevGold[PN] = CurrentGold
So, I managed to reproduce the triggers and test in my map as well as in a new map(just in case it was messing with other triggers), unfortunately it doesn't seem to work.At map initialization I start with 0 gold. If I gain gold after that It doesn't show/hide any coins.

Could you please let me know if I'm missing anything?

This is how I set the variables:

GoldItem = Item array [1]
CurrentGold - Integer
IsGoldShown = Bolean array [1] (initial value false)
GoldL = Integer
MdaPN = Integer
PrevGold = Integer array [1]
PN = Integer

Could you attach a map where it works if you still have it? That might help me understand why it's not working for me.
 
Level 20
Joined
Feb 27, 2019
Messages
592
It just seems that you missed how the multi dimensional array works.
MdaPN gets set to PN x 10
That means that inside the loop, MdaPN + GoldL (if Player number is 1 and GoldL is 1) will be 11.
So when you set up the ItemArrayGold the array must be set with this in mind.
Player 1 has array 11-15
Player 2 has array 21-25
Player 3 has array 31-35
and so on

I forgot to mention that the Custom script: exitwhen udg_GoldL > 5 inside the loop is used to limit the loop to the 5 arrays available for each player, so if you wanted to add more gold coins you should change that to the amount of gold coins available for each player.
 

Attachments

  • gold indicator.w3m
    20.6 KB · Views: 2
Level 4
Joined
May 12, 2022
Messages
22
Oh, I didn't realise it worked like that..

I forgot to mention that the Custom script: exitwhen udg_GoldL > 5 inside the loop is used to limit the loop to the 5 arrays available for each player, so if you wanted to add more gold coins you should change that to the amount of gold coins available for each player.
I will keep that in mind but for now 5 of them is enough.

I'll test it a bit and later add it to my map to check for any bad interactions. (just in case)
Thanks for pointing this out, also for the map. It's much appreciated! 😅
 
Level 20
Joined
Feb 27, 2019
Messages
592
Glad to help.

Even though the original trigger works fine I found a way to improve it.

This can be removed from Gold Indicator Setup.
  • Set VariableSet IsGoldShown[MdaPN] = True
Change this in Gold Indicator Setup. I advice you create a new integer variable array as you replace the old MdaPN to the new MdaPN[PN]
  • Set VariableSet MdaPN[PN] = (PN x 10)
Make these changes to Gold Indicator.
  • For each (Integer GoldL) from (PrevGoldL[PN] + 1) to CurrGoldL, do (Actions)
  • For each (Integer GoldL) from (CurrGoldL + 1) to PrevGoldL[PN], do (Actions)
Remove these if you dont have any other use for the boolean variable.
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • IsGoldShown[(MdaPN + GoldL)] Equal to False
    • Then - Actions
      • Set VariableSet IsGoldShown[(MdaPN + GoldL)] = True
    • Else - Actions
Improved trigger.
  • Gold Indicator
    • Events
      • Player - Player 1 (Red)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 2 (Blue)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 3 (Teal)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 4 (Purple)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 5 (Yellow)'s Current gold becomes Greater than or equal to 0.00
      • Player - Player 6 (Orange)'s Current gold becomes Greater than or equal to 0.00
    • Conditions
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet CurrGoldL = (((Player(PN)) Current gold) / 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrGoldL Equal to PrevGoldL[PN]
        • Then - Actions
          • -------- no change --------
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CurrGoldL Greater than PrevGoldL[PN]
            • Then - Actions
              • -------- show gold --------
              • For each (Integer GoldL) from (PrevGoldL[PN] + 1) to CurrGoldL, do (Actions)
                • Loop - Actions
                  • Custom script: exitwhen udg_GoldL > 5
                  • Item - Show GoldItem[(MdaPN[PN] + GoldL)]
            • Else - Actions
              • -------- hide gold --------
              • For each (Integer GoldL) from (CurrGoldL + 1) to PrevGoldL[PN], do (Actions)
                • Loop - Actions
                  • Custom script: exitwhen udg_GoldL > 5
                  • Item - Hide GoldItem[(MdaPN[PN] + GoldL)]
      • Set VariableSet PrevGoldL[PN] = CurrGoldL
 
Last edited:
Level 4
Joined
May 12, 2022
Messages
22
This seems to work as well but is it more lag efficient? By the way, when I try to test it in world editor, I only have 2 (players/computer).. So, I can only test it for 2 no matter what, and I don't know why. I tried to change this in player properties/ forces .. but it doesn't seem to work.

Also, as an off topic ..
I'm trying to make a trigger that adds 10 gold for each gold coin you have(visible) every 5 seconds.
So, if you have for example: 340 gold, then you should have a 30 gold income every 5 seconds.
  • Events
    • Player - Player 1 (Red)'s Current gold becomes Greater than or equal to 100.00
    • Player - Player 2 (Blue)'s Current gold becomes Greater than or equal to 100.00
    • Player - Player 3 (Teal)'s Current gold becomes Greater than or equal to 100.00
    • Player - Player 4 (Purple)'s Current gold becomes Greater than or equal to 100.00
    • Player - Player 5 (Yellow)'s Current gold becomes Greater than or equal to 100.00
    • Player - Player 6 (Orange)'s Current gold becomes Greater than or equal to 100.00
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • And - All (Conditions) are true
          • Conditions
            • ((Triggering player) Current gold) Greater than or equal to 100
            • ((Triggering player) Current gold) Less than 200
      • Then - Actions
        • Player - Add 10 to (Triggering player).Current gold
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • And - All (Conditions) are true
          • Conditions
            • ((Triggering player) Current gold) Greater than or equal to 200
            • ((Triggering player) Current gold) Less than 300
      • Then - Actions
        • Player - Add 20 to (Triggering player).Current gold
      • Else - Actions
I was thinking to make it like this but seeing as it has the same event as the trigger you made I was thinking to incorporate it somehow to futher avoid lag. Do you think it's better to make this trigger separately or is it better to try to incorporate them together? And as it is right now, would you change anything about it? Also, I haven't tested this yet but i'm guessing it works.😅
 
Level 39
Joined
Feb 27, 2007
Messages
5,019
There should be no concerns about latency or visual lag for anything used in this thread. You could do all of these things 100 times a second and never notice an effect on the game performance.

Why are you not using a 5s periodic event to add gold? What you are have done is add gold every time they gain gold, which is an infinite loop and will crash the game. You will need to check PrevGold[] to figure out how many coins are currently visible to the player and then multiply that by 10 to add:
  • Events
    • Time - Every 5.00 seconds of game-time
  • Conditions
  • Actions
    • Player Group - Pick every player in (All Players) and do (Actions)
      • Loop - Actions
        • Player - Add (PrevGold[(Player number of (Picked Player))] x 10) to (Picked Player) Current Gold
 
Level 20
Joined
Feb 27, 2019
Messages
592
In player properties you should be able to change players controller status. Did you change players to Computers and it still doesnt work? Additional User slots will be empty when you test the map in world editor.

You can do what Pyrogasm said but PrevGold[] can be greater than 5 so youd need a boolean check to make sure no more than 50 gold is added.
if PrevGold is greater than 5 then
add 50 gold to Player
else
add PrevGold x 10 to Player
endif
 
Level 4
Joined
May 12, 2022
Messages
22
I seems to work with the trigger you suggested and it even caps at 50, which is great. 🙂
In player properties you should be able to change players controller status. Did you change players to Computers and it still doesnt work? Additional User slots will be empty when you test the map in world editor.
1678629491756.png
1678629465485.png

As you can see it only loads 2 players. This happens when I test in editor. I'm guessing it would be different if I were to open the map normally but in editor at least, it only shows 2 players.
 
Level 4
Joined
May 12, 2022
Messages
22
I did try to set it to 1 or 2 forces but it doesn't change anything. But it's fine, I'll just need to test in game I guess.
 
Level 4
Joined
May 12, 2022
Messages
22
Oh, I didn't try that, I must've missed what you said Chaosium .. My bad
That "Fixed Player Settings" also tends to solve a lot of player-related stuff

It seems to work now when I add computer slots. Thanks to you both, I can get back to testing now. Cheers! :peasant-cheers-back:
 
Status
Not open for further replies.
Top