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

Income system

Status
Not open for further replies.
Level 12
Joined
Jun 1, 2010
Messages
747
I need a special income system. The income=gold every 30 seconds is determined by the numbers of buildings=town halls a player posesses. Two buildings=200 gold, one building 100 gold, three 300 gold and so on. I need somebody to make the trigger it is not hard but I can not figure out what way to do it. Post a map or trigger.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Add the town halls to a unit group:
  • Income
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units owned by (Player((Player number of (Picked player)))) of type Town Hall) and do (Actions)
            • Loop - Actions
              • Unit Group - Add (Picked unit) to income[(Player number of (Picked player))]
Add newly built town halls to the same group:
  • income add
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Town Hall
    • Actions
      • Unit Group - Add (Triggering unit) to income[(Player number of (Picked player))]
Looping trigger that adds the gold:
  • Command
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in income[(Player number of (Picked player))] and do (Actions)
            • Loop - Actions
              • Player - Add 100 to (Picked player) Current gold
 
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Why not just:
  • Trigger
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Town Hall) and do (Actions)
        • Loop - Actions
          • Player - Add 100 to (Owner of (Picked unit)) Current gold
Greetings and Peace
Dr. Boom
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Check the system Income Generator at my Signature.
This method of "picking every unit in map" prove to be quite powerful function if you have many units in the map (first pick every unit, then filter it out)

My system just pick units inside the unit group (if you build 3 Town Halls, you would only be picking 3 Town Halls instead 453 units).

I may sound badass advertising my own resource (again), but I'm just helping him to guide him to use system which is more efficient.
 
Last edited:
Level 20
Joined
Jul 6, 2009
Messages
1,885
Pick every unit from (units of type) leaks. At least, that's what i've heard.

I thought so too at first, but this function destroys the group.
JASS:
function CountLivingPlayerUnitsOfTypeId takes integer unitId, player whichPlayer returns integer
    local group g
    local integer matchedCount

    set g = CreateGroup()
    set bj_livingPlayerUnitsTypeId = unitId
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterLivingPlayerUnitsOfTypeId)
    set matchedCount = CountUnitsInGroup(g)
    call DestroyGroup(g)

    return matchedCount
endfunction
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Guys? I have a great idea!
Let us continue this pointless discussion about efficiency when a poor guy just asked about a simple income system.


Anyway, I think this is the most efficient:
  • Build Town Hall
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Town Hall
    • Actions
      • Set tempInt = (Player number of (Owner of (Triggering unit)))
      • Set countTownHalls[tempInt] = (countTownHalls[tempInt] + 1)
  • Gather Income
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Player - Add (100 x countTownHalls[(Integer A)]) to (Player((Integer A))) Current gold
To the inexperienced eye it may look like it's a lot more than Dr. Boom's or MortAr's suggestions, but do not let that fool you.
This does not use unit groups (which are horribly inefficient in GUI).
The most horrible function would be "Player - Add (gold)" in this method.
tempInt is to avoid running unnecessary functions multiple times.

This is actually quite similar to Defskull's system, though mine is not flexible at all.
If you have multiple building types that add different amounts of gold, choose that one.
If you have only 1 building type, or have several but they all add the same gold amount, pick mine :D

Unless someone could prove me wrong about the entire efficiency-thing of course.



(No unit groups were created in the making of this comment)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
No man, you have to make all this into a single trigger.
If we used 2, it'd have been quite easy, as your example shows it.
Your wish is my command.

  • Build Town Hall + Income!
    • Events
      • Unit - A unit Finishes construction
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A structure) Equal to False
        • Then - Actions
          • For each (Integer A) from 1 to 12, do (Actions)
            • Loop - Actions
              • Player - Add (100 x countTownHalls[(Integer A)]) to (Player((Integer A))) Current gold
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Town Hall
            • Then - Actions
              • Set tempInt = (Player number of (Owner of (Triggering unit)))
              • Set countTownHalls[tempInt] = (countTownHalls[tempInt] + 1)
            • Else - Actions
What's next? :p
(Though it did lose all beauty it had before :( ).
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I don't want to brag, but;

- My system has an individual timer per interval per building finished constructed (this what makes it different from method suggested above)
- As I said, my system just assess the units that is in the Unit Group (while your trigger, is to assess all Player Unit (1 ~ 12)). Imagine if Player 6 ~ 12 does not build any building-type income yet, you would still have to loop it each time the trigger run.
- Player Loop -> Unit Loop, once you loop each Player, in that function, you loop through each building, making it a double-loop, quite unefficient if you ask me
- The more you can configure in a system, the more freedom you will have.
- My system has an easy configuration setup :/

That's all I think.

But it's up to him if he want to resort to the most simple way, don't use my system.
But if you feel that you have many players playing your map (12) and your map gonna lasts a long game duration (1 ~ 2 hours), you can use my system.

Again, it is up to you.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I don't want to brag, but;

- My system has individual timer per interval per building finished constructed
- As I said, my system just assess the units that is in the Unit Group (while your trigger, is to assess all Player Unit (1 ~ 12)). Imagine if Player 6 ~ 12 does not build any building-type income yet, you would still have to loop it each time the trigger run.
- Player Loop -> Unit Loop, once you loop each Player, in that function, you loop through each building, making it a double-loop, quite unefficient if you ask me
- The more you can configure in a system, the more freedom you will have.
- My system has an easy configuration setup :/

That's all I think.

But it's up to him if he want to resort to the most simple way, don't use my system.
But if you feel that you have many players playing your map (12) and your map gonna lasts a long game duration (1 ~ 2 hours), you can use my system.

Again, it is up to you.

The "12" is temporary. If there only are 6 players, he can make it loop from 1 to 6, right?
And you are right that it does indeed fire the actions for every player, whether that player actually built something or not.
You could circumvent this by adding an ITE with condition countTownHalls > 0.

Yes, your system is way more configurable :D
I made mine as short as possible, that means 0 configuration (not even a "MAX_PLAYERS" variable exists).

- Player Loop -> Unit Loop, once you loop each Player, in that function, you loop through each building, making it a double-loop, quite unefficient if you ask me
I didn't get this. It doesn't loop through any units. Players, yes. Units, no.
It only loops once, and that is for all players.
Or am I missing something? :S


Edit: YOU STAY OUT OF THIS RULEROFIRON99! ( :D )
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I responded first
Doesn't mean the thread starter always follow the first person that gives solution to their problems, could be wrong.

He's probably using my system right now
Probably, been inactive in his own thread for such a long time.

I got rep for it (most important point)
This would be in contradiction with point A.

Naah I just leave this thread alone, let alone he decide which he will use (probably ruler's trigger by now).

@apo
Let's PM ! Haha
 
Level 16
Joined
May 1, 2008
Messages
1,605
If I may be so bold as to rejoin this turd-flinging contest:
  • I responded first
  • He's probably using my system right now
  • I got rep for it (most important point)

Someone is egoistic here .. guys you are not allowed to post here anymore!! Get it!!

@ ap0: Well as I said, I don't think its a good way to use 2 variables for just a simple thing like this ^^
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Someone is egoistic here .. guys you are not allowed to post here anymore!! Get it!!

@ ap0: Well as I said, I don't think its a good way to use 2 variables for just a simple thing like this ^^


You understand me! :)

For what it's worth, I think your trigger was the best.

"Things should be as simple as they need to be - and no simpler."
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Your wish is my command.

  • Build Town Hall + Income!
    • Events
      • Unit - A unit Finishes construction
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A structure) Equal to False
        • Then - Actions
          • For each (Integer A) from 1 to 12, do (Actions)
            • Loop - Actions
              • Player - Add (100 x countTownHalls[(Integer A)]) to (Player((Integer A))) Current gold
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Town Hall
            • Then - Actions
              • Set tempInt = (Player number of (Owner of (Triggering unit)))
              • Set countTownHalls[tempInt] = (countTownHalls[tempInt] + 1)
            • Else - Actions
What's next? :p
(Though it did lose all beauty it had before :( ).

  • Set tempInt = (Player number of (Owner of (Triggering unit)))
Owner of (Triggering unit) -> (Triggering player), calls less function.

You should cache (Triggering unit) as you call it more than once.

Your trigger could be problem if he wants to have more than one building-type, I mean like 10 building or something, you're going to do a 10 I/T/E calls lol.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
"Things should be as simple as they need to be - and no simpler."
But... :sad:
I thought mine was more simple when converted to JASS.

Animalpower: I am sorry for taking some of your free time and destroying it with useless... words and... sentences and all that.
You can use any system you deem best, after all: 1 trigger (or 2 if you use mine - hint hint) won't make the difference, certainly not when all your other triggers are probably GUI as well.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Although I am not flexible, if you have more than one type of construction, adding different amount of gold that choice.
Do you mean different gold gain for different building ?
Yeah my system does that, also, if you're gonna use the "simplest method", you will have to do a check like 10 times (O(n) search is bad) for 10 different types of building.
 
Level 2
Joined
Nov 29, 2012
Messages
8
Dr boom realy helped me too. I was searching for a way creating income/unit for a loooonggggggg time..(3 days:)) and I never tough that the solution was that simple.I min, 1 SINGLE TRIGGER!! Thats great!!:)
 
Level 1
Joined
Apr 26, 2013
Messages
4
nice

Add the town halls to a unit group:
  • Income
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units owned by (Player((Player number of (Picked player)))) of type Town Hall) and do (Actions)
            • Loop - Actions
              • Unit Group - Add (Picked unit) to income[(Player number of (Picked player))]
Add newly built town halls to the same group:
  • income add
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Town Hall
    • Actions
      • Unit Group - Add (Triggering unit) to income[(Player number of (Picked player))]
Looping trigger that adds the gold:
  • Command
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in income[(Player number of (Picked player))] and do (Actions)
            • Loop - Actions
              • Player - Add 100 to (Picked player) Current gold

This trigger works excellent, of all my searching online this week and stamping of feet and smoking of cigarettes, this is it! This trigger is simple, easy to learn, and easy to change.

I found necessary to include a trigger that removes the income building from income if it is destroyed, and included it the attached map with ruleofiron99's trigs as well, all working.

If using different types of buildings for different types of income/amounts, then create variables and triggers for each using same format.

For instance Im making a map where if you capture a marketplace you get 1k gold, if you capture a lumber mill, you get 500 lumber, and my nubness found it best to make new trigs and variables following same format.

Sounds tedious but copy and paste is good and change what you need.

Does my method seem spammy or leaky? I have seen some snappy looking triggers balling this all into one, but I dont think they achieve what I need.

Maybe some overlord reading this has some advice?

I grew tired of tampering with tables and custom scripts and WE crashing after following step by step instructions from people on forums, so please try to be extra specific here.

Im new with incom triggers but have been moding for a decade, so spare me the insults, if I had not spent a week searching online and testing and tinkering already and smoking myself to death in front of my computer I wouldnt be asking this.
 

Attachments

  • INCOME.w3x
    17.8 KB · Views: 42
Status
Not open for further replies.
Top