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

Extensive income system

Status
Not open for further replies.
Level 4
Joined
Dec 19, 2015
Messages
52
It's been quite a few years since I've been around the hive. I need help creating an income system that gives gold and lumber every 2 minutes. The system would check which player owns which buildings and give income accordingly. There would probably be about 100 different income buildings with very few of them being multiples.

I've done a few searches and have the code to a couple of different systems. I'm specifically looking for something that is lag/leak free for a system of that size (80+ different income buildings). If anyone could help me out on the beginning of my journey, it'd be greatly appreciated. :ogre_haosis:

-redbaron
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Use a hashtable to store a boolean for each unit type. (true if it is an income structure)
Then you can load if that unit type of the picked unit is an income structure.

Ofcourse this wont tell you how much income you get from it... so it is better to store a real (the value of the income) for it.

Try to use an existing hashtable that has 1 unused row.... that means all hashtables in your map :D
 
Level 4
Joined
Dec 19, 2015
Messages
52
Thanks for the quick reply. I have searched and found a few examples and defskul's system seems like it would be the easiest to modify to my needs.
 
Level 4
Joined
Dec 19, 2015
Messages
52
Sorry for the double post. This is the system currently in the game that I was looking to improve upon. I tends to lag towards the late game, 1-2 hours in and I was wondering if Defskull's System would be a better alternative.
 

Attachments

  • Help Income Triggers.w3x
    36.6 KB · Views: 28
Level 12
Joined
May 22, 2015
Messages
1,051
A hashtable is a good idea to make the lookups quick (O(1)).

Basically, you should have the income for each player. Then, when they make a building, you do a quick look up to see how much income the building adds, and add that to the player's income. You should have a similar trigger for when buildings get destroyed if that is possible in your map.

The periodic trigger will only look at the value each player has. This allows it to be fast and avoids looking at all the buildings in the map.

You should have 3 main triggers:
Initialisation:
You create the hashtable and save all the building income values in this trigger. It should happen early in the game before anything important is happening but I think it needs to happen after Map Initialisation (the actual loading of the map) due to something with hashtables not working if you create them at that time (I could be remembering wrong, but just in case).

Then it should basically be a bunch of SaveInteger calls to save income values to unit types. The default value retrieved will be 0, so you can ignore all non-income buildings.

Building Created
I think there is a "A unit completes construction" even or something like that. You basically want to get the unit type of the completed structure and use it to look up the income value saved in the table. Then add that value to the owner of the unit's income (this can be done with an array where each player has an index).

You can create a matching one that subtracts checking on unit death. This will allow the income to go back down if the unit dies.

Income
This one is easy. Every two minutes, loop over the income array and add the value there to the matching player's gold (something like convert integer to player).
 
Status
Not open for further replies.
Top