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

Money Farms

Status
Not open for further replies.
Level 4
Joined
Feb 28, 2009
Messages
73
Hi im trying to make a game and i want to put money farms in. But im not so sure what the trigger is for money farms.

Level 1 would be 1 gold and 1 lumber every second.
Level 2 would be 3 gold and 3 lumber every second.
Level 3 would be 5 gold and 5 lumber every second.
 
Level 4
Joined
Feb 28, 2009
Messages
73
Would the trigger look like:
  • Money Farms
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Money Farm [1]) and do (Actions)
        • Loop - Actions
          • Player - Add (Number of units in (Units in Area 1 <gen> matching ((Unit-type of (Picked unit)) Equal to Money Farm [1]))) to (Owner of (Picked unit)) Current gold
?
 
Level 11
Joined
Feb 14, 2009
Messages
884
Because the farms are selected multiple times. For example, let's assume that there are 10 farms in your region. The first time your trigger runs, it will detect 10 farms. So, it's going to add 10 gold to the player. The second time it runs, the same. This will happen 10 times, so your player will get 10²=100 gold every second. What you can do is to pick every farm in the game and use an integer variable as a counter. Then, every second, your trigger will count all of your farms and add the correct amount of gold to the player, using the counter mentioned above.
 
Level 8
Joined
Jun 26, 2010
Messages
530
I love loops

Here's a better trigger

  • Events - every 1 second of the game
  • Conditions
  • Actions
  • For every Integer A from 1 to (number of players) do multiple actions:
    • loop:
      • For every Integer A from 1 to (number of farms owned by(ConvertPlayerIndexToPlayer(index:Loop Integer A))) do multiple actions
        • loop:
          • Add - X gold to (ConvertPlayerIndexToPlayer(index:Loop Integer A)) Current Gold
          • Add - X gold to (ConvertPlayerIndexToPlayer(index:Loop Integer A)) Current Lumber
You should also look for tutorials on Memory Leaks so you can fix that trigger (I'm at work and must post really fast D;)

The first loop makes the trigger run for every player and the second for every farm of the player on the current loop
 
Level 8
Joined
Nov 9, 2008
Messages
502
That's good but instead of the second loop being Integer A it should really be Integer B otherwise the loops will conflict.

You are going to need that trigger for each farm level as they are essentially different units.
 
Level 8
Joined
Jun 26, 2010
Messages
530
That's good but instead of the second loop being Integer A it should really be Integer B otherwise the loops will conflict.

Oops, that's true. Thank's for correcting.

You are going to need that trigger for each farm level as they are essentially different units.

Or make some If-Then-Else condictions in the same trigger. The level that will determine the amount of resources gained is the level of an upgrade or the level of the farm?
 
Level 8
Joined
Nov 9, 2008
Messages
502
If it's an upgrade it makes it shorter because you can use the math like 'Give gold equal to (research level*2)-1.

Most likely he is using building upgrades not research though. You don't need a condition statement, just another loop for each upgrade. E.g. the game loops through all lvl 1 farms and gives gold, then through the lvl 2s, then the 3s e.t.c.
 
Status
Not open for further replies.
Top