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.
[10:53 pm]
Oh_Man -- https://youtu.be/MHOZptE-_-c are yall seeing this map? it's insane
[01:05 am]
Vrael -- I won't stand for people going around saying things like im not a total madman
[01:05 am]
Vrael -- that's better
[12:39 am]
NudeRaider -- can confirm, Vrael is a total madman
[2024-5-03. : 10:18 pm]
Vrael -- who says I'm not a total madman?
[2024-5-03. : 2:26 pm]
UndeadStar -- Vrael, since the ad messages get removed, you look like a total madman for someone that come late
[2024-5-02. : 1:19 pm]
Vrael -- IM GONNA MANUFACTURE SOME SPORTBALL EQUIPMENT WHERE THE SUN DONT SHINE BOY
[2024-5-02. : 1:35 am]
Ultraviolet -- Vrael
Vrael shouted: NEED SOME SPORTBALL> WE GOT YOUR SPORTBALL EQUIPMENT MANUFACTURING
Gonna put deez sportballs in your mouth
[2024-5-01. : 1:24 pm]
Vrael -- NEED SOME SPORTBALL> WE GOT YOUR SPORTBALL EQUIPMENT MANUFACTURING
[2024-4-30. : 5:08 pm]
Oh_Man -- https://youtu.be/lGxUOgfmUCQ
Please log in to shout.


Members Online: Oh_Man