Staredit Network > Forums > SC1 UMS Mapmaking Assistance > Topic: Counting # of Units/Buildings
Counting # of Units/Buildings
Dec 6 2009, 7:31 am
By: Kimaru  

Dec 6 2009, 7:31 am Kimaru Post #1



I have a system in my map that subtracts 1 gas per unit controlled per second and 1 gas per building controlled per second, but I need a way to let the map know how many units/buildings the player has. The full proof method I know is to say "Current Player commands exactly 1 [men], subtract 1 gas" but I'd have to copy and modify that trigger 250 times (if I want the unit limit to be 250), and then around 50ish times for buildings. Does anyone know of a better, more efficient way to handle this? because the method I mentioned is really tedious and last resort. Thanks in advance.



None.

Dec 6 2009, 7:50 am Neki Post #2



Uh, if you don't mind losing control of all your units and buildings for a couple of seconds, create a trigger which cycles through all your men and buildings, giving them to a neutral player while subtracting one gas until the player controls no more units or buildings, then give them all back. That's the only way I could think of doing it, but I don't think it would work practically if all your units and buildings are actively being used.

Edit: Another method is just to actively keep track of when buildings are made and when units are made, and then just use it from there. Assuming units are created from triggers, and you can keep track of buildings with burrowed units. Otherwise, I see no feasible method.


Post has been edited 1 time(s), last time on Dec 6 2009, 9:04 am by Ultimo.



None.

Dec 6 2009, 8:12 am JrOSTAD Post #3



I agree with what Ultimo said, this method works pretty good, except of course, the fact that you want to do it every second, and that they are being actively used, this could be a problem.



None.

Dec 6 2009, 9:27 am SelfPossessed Post #4



http://www.staredit.net/wiki/Binary_Countoffs



None.

Dec 6 2009, 5:58 pm JaFF Post #5



If you're unhappy about using some trigger duplicator software, you can do the following:

-Each time a unit is built via a factory, add one to deathcounter X
-Each time a unit dies, subtract one from deathcounter X
-Each time a unit is created via triggers, add one to deathcounter X
-Each time a unit is removed/killed via triggers, subtract one from deathcounter X

All of that is easy and elegant except for the first one: detecting when a unit has been built. There are two methods that allow you to achieve this. Both have advantages and disadvantages.

METHOD 1: Using hero units.
All the units you control are hero units. You build usual units in factories and use several very simple triggers to replace them as soon as they leave the factory with a hero counterpart. This is a very simple method, but it limits the units you can use.

METHOD 2: Resource detection.
Make each unit cost a unique amount of resources. Make sure that amount is not equal to any multiple of the resources one worker harvests in one go (8 by default). This allows you to detect when you start/cancel building a unit of a specific kind by detecting the change in the resources you have. Make a deathcounter for each unit type, call them N1, N2, N3 and so on. Each time you start building a unit, add one to the corresponding deathcounter. Each time you cancel a unit - subtract. You know the build time of each unit type; for example, the unit type that corresponds to N1 has a build time of b1 (trigger loops). So, every b1 trigger loops, if N1 is non-zero, you subtract one from N1 and add one to the deathcounter that holds the total number of units - X. This method is very rough and will not give accurate results. Also, it potentially requires a lot of deathcounters. I can see almost no practical use for it.

So, to make a long story short: copy those 250 triggers and be done with it. >_<



None.

Dec 6 2009, 7:46 pm Kimaru Post #6



Thanks guys, I like Ultimo's and Jaff's idea of whenever a unit is created by a trigger, add 1 for death counter X, since every unit will be created by triggers. As for the buildings, I'll just copy the trigger 50 times since it's not that much and it'll require more trouble.



None.

Dec 7 2009, 1:52 am Falkoner Post #7



Here's a little tutorial on transferring buildings to cash, but it seems that concept isn't your problem, so instead, I would recommend using Binary Count-Offs to remove the units, of course, there are some problems with using it on units, because Bring won't update correctly, so it puts a twist on the solution.

So, to transfer 15 units in a single trigger cycle, your binary count-offs would look like this:

Conditions:
Player x brings at least 8 [any unit] to Anywhere
Switch Transfer is set
Actions:
Give 8 [any unit] to (Unused Computer)
Add 8 Gas to Player x
Remove (Unused Unit)
Preserve Trigger

Conditions:
Player x brings at least 4 [any unit] to Anywhere
Rest is same as above, use 4 instead of 8

Conditions:
Player x brings at least 2 [any unit] to Anywhere
Rest is same as above, use 2 instead of 8

Conditions:
Player x brings at least 1 [any unit] to Anywhere
Rest is same as above, use 1 instead of 8

The Remove at the bottom is necessary to ensure Bring updates, otherwise you'll get extra gas each time it runs. Then just keep going up by powers of 2 depending on how many units you think you'll need to transfer at once.

However, you do have the problem of how often to do it, because each time you do that, you'll lose selection of all your units, so perhaps you'd need to use some way of detecting when to use it, rather than constantly doing it, it would also create excessive lag doing it constantly.



None.

Dec 7 2009, 1:58 am Kimaru Post #8



I'm not sure that would work, since the units are actively being used, and it may be upsetting for someone to wonder what happened to their units :bye1:



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[07:46 am]
RIVE -- :wob:
[2024-4-22. : 6:48 pm]
Ultraviolet -- :wob:
[2024-4-21. : 1:32 pm]
Oh_Man -- I will
[2024-4-20. : 11:29 pm]
Zoan -- Oh_Man
Oh_Man shouted: yeah i'm tryin to go through all the greatest hits and get the runs up on youtube so my senile ass can appreciate them more readily
You should do my Delirus map too; it's a little cocky to say but I still think it's actually just a good game lol
[2024-4-20. : 8:20 pm]
Ultraviolet -- Goons were functioning like stalkers, I think a valk was made into a banshee, all sorts of cool shit
[2024-4-20. : 8:20 pm]
Ultraviolet -- Oh wait, no I saw something else. It was more melee style, and guys were doing warpgate shit and morphing lings into banelings (Infested terran graphics)
[2024-4-20. : 8:18 pm]
Ultraviolet -- Oh_Man
Oh_Man shouted: lol SC2 in SC1: https://youtu.be/pChWu_eRQZI
oh ya I saw that when Armo posted it on Discord, pretty crazy
[2024-4-20. : 8:09 pm]
Vrael -- thats less than half of what I thought I'd need, better figure out how to open SCMDraft on windows 11
[2024-4-20. : 8:09 pm]
Vrael -- woo baby talk about a time crunch
[2024-4-20. : 8:08 pm]
Vrael -- Oh_Man
Oh_Man shouted: yeah i'm tryin to go through all the greatest hits and get the runs up on youtube so my senile ass can appreciate them more readily
so that gives me approximately 27 more years to finish tenebrous before you get to it?
Please log in to shout.


Members Online: lil-Inferno, C(a)HeK, Dem0n, No-Name-Needed-II