• 🏆 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!

Share gold with neutral player?

Status
Not open for further replies.
Level 4
Joined
Aug 2, 2015
Messages
50
Is there a easy way to make the gold you gather automatic shared to your shared neutral player?

Lets say you collect 10 gold from mine and want the neutral get 5 of those without lift a finger?
Doesnt have to cut from that 10 gold gathered.

How far off is this?
  • Share resources 2
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • If ((Player 1 (Red) Current gold) Greater than ((Player 1 (Red) Current gold) + 9)) then do (Player - Add 5 to Player 9 (Gray).Current gold) else do (Do nothing)
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
The Condition in your If Then Else will never be met. You're comparing P1's current gold with a number greater than his current gold. This is his CURRENT gold we're talking about, it can never be greater than what it CURRENTLY is. But I see where you were going with it.

Here's a good system you can use: Player Resource Monitoring v1.01
(If you copy the whole folder over to your map make sure you delete EVERY trigger besides PRM)

Then using the variables provided by that system make a trigger like this:
  • Gold Share
    • Events
      • Game - PRM_EVENT becomes Equal to 1.00
    • Conditions
      • PRM_Change Greater than 0
    • Actions
      • Player - Add (PRM_Change / 2) to ShareAlly[(Player number of PRM_Player)].Current gold
ShareAlly is a Player array I made. You'd set this beforehand for each player. The [Index] represents the Player number:
  • Events
    • Map Initialization
  • Actions
    • Set Variable ShareAlly[1] = Player 9 (Gray)
    • Set Variable ShareAlly[2] = Player 10 (Light Blue)
    • Set Variable ShareAlly[3] = Player 11 (Dark Green)
[1] = Red, [2] = Blue, [3] = Teal, etc...


Alternatively, you can track the Gold gained and only share it once it reaches an even number. This way none of the gold is lost if it gets rounded down:
  • Gold Share
    • Events
      • Game - PRM_EVENT becomes Equal to 1.00
    • Conditions
      • PRM_Change Greater than 0
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (PRM_Change mod 2) Equal to 0
        • Then - Actions
          • Player - Add (PRM_Change / 2) to ShareAlly[(Player number of PRM_Player)].Current gold
        • Else - Actions
          • Set Variable SharePN = (Player number of PRM_Player)
          • Set Variable ShareGold[SharePN] = (ShareGold[SharePN] + PRM_Change)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (ShareGold[SharePN] mod 2) Equal to 0
            • Then - Actions
              • Player - Add (PRM_Change / 2) to ShareAlly[(Player number of PRM_Player)].Current gold
              • Set Variable ShareGold[SharePN] = 0
            • Else - Actions

Mod, short for Modulo, is how you can check for Even/Odd numbers and also works nicely to get multiples of a number. In the above trigger I am giving half of the gold to the player's ally IF it's an even amount. Otherwise, I am adding it to a gold pool (ShareGold). Then I check if that gold pool is an even number, if it is then I give half of it to their ally and reset the gold pool back to 0.
 
Last edited:
Level 4
Joined
Aug 2, 2015
Messages
50
Thanks Uncle!

Just one question.
When I collect 10 gold it gives 8 to my ally? Did I get some part wrong?
The code trigger I just copy and pasted.

  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Set VariableSet PRM_EVENT = 0.00
      • Set VariableSet PRM_Change = 0
      • Set VariableSet PRM_FireEvent = True
      • Set VariableSet PRM_Player = Player 1 (Red)
      • Set VariableSet PRM_Ally = Player 9 (Gray)
  • Gold
    • Events
      • Game - PRM_EVENT becomes Equal to 1.00
    • Conditions
      • PRM_Change Greater than 0
    • Actions
      • Player - Add (PRM_Change / 2) to PRM_Ally.Current gold
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
First off, those variables in your Map Initialization trigger can be deleted (except PRM_Ally). They don't do anything in this case, the system will manage them for you.

Secondly, you haven't excluded any players from the system so whenever they gain gold it's also added to P9 (PRM_Ally). I forgot about this in my previous post so sorry for not mentioning it.

This variable does not do what you think it does:
  • Set VariableSet PRM_Player = Player 1 (Red)
PRM_Player is used inside of a PRM_EVENT trigger in order to get which Player's resource changed. The system isn't designed to work for only one player, it works for ALL players by default.

To change which Players the system works for you need to tell the system to stop monitoring them. In your Map Initialization trigger do this:
  • PRM_MonitorPlayer[2] = false
  • PRM_MonitorPlayer[3] = false
  • PRM_MonitorPlayer[4] = false
  • PRM_MonitorPlayer[5] = false
  • PRM_MonitorPlayer[6] = false
  • PRM_MonitorPlayer[7] = false
  • PRM_MonitorPlayer[8] = false
  • PRM_MonitorPlayer[9] = false
  • PRM_MonitorPlayer[10] = false
  • etc...
This will make the system ignore gold/lumber changes for players 2 to 10. If your map has more players then add them as well.

To save time you could also do it like this:
  • Actions
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Set VariableSet PRM_MonitorPlayer[(Player number of (Picked player))] = False
    • Set VariableSet PRM_MonitorPlayer[1] = True
 
Last edited:
Status
Not open for further replies.
Top