Staredit Network > Forums > SC2 Assistance > Topic: [Solved] Create Unit Type at Multiple Points
[Solved] Create Unit Type at Multiple Points
This topic is locked. You can no longer write replies here.
Jun 27 2011, 5:18 am
By: Veta  

Jun 27 2011, 5:18 am Veta Post #1



Hi there,

I've been struggling with this and I just can figure out what would be the best system to use. For a map I am making I have laid out a variety of points at which I would like to spawn certain unit types, say for 50 different points I would like to spawn building X. for another 50 points I would like to spawn building Y and for a final 100 I would like to spawn building Z. I've tried messing around with variable/arrays but I really don't have a grasp of them yet.

Could anyone help me figure out an efficient way to do this other than making 200 triggers or actions for each individual point?



None.

Jun 27 2011, 8:31 am Roy Post #2

An artist's depiction of an Extended Unit Death

You'll want to put all points in one array, or each group of points into their own array. Then you can use a for loop to iterate through all points and do a specific action. Here's an example:

ExampleLoop
      Events
            Game - Map initialization
      Local Variables
            idx = 0 <Integer>
      Conditions
      Actions
            General - For each integer idx from 1 to 50 with increment 1, do (Actions)
                  Actions
                        Unit - Create 1 Barracks for player 1 at buildingXpoints[idx] using default facing (No Options)
            General - For each integer idx from 1 to 50 with increment 1, do (Actions)
                  Actions
                        Unit - Create 1 Missile Turret for player 1 at buildingYpoints[idx] using default facing (No Options)
            General - For each integer idx from 1 to 100 with increment 1, do (Actions)
                  Actions
                        Unit - Create 1 Pylon for player 1 at buildingZpoints[idx] using default facing (No Options)


In the above example, I'm using three global variables (buildingXpoints, buildingYpoints, buildingZpoints) that are point arrays (size 50, 50, and 100 respectively).

Note that arrays technically start at index 0, but SC2 creates an extra index on the array for people unfamiliar with coding standards, which means an array of size 50 actually has 51 indexes (0-50), so it's perfectly safe to do a loop from 1 to 50 if you have 50 points. I would link to a wiki page explaining arrays in full in case you need more details, but it appears GWN is down right now. Basically it's just holding many point variables inside of one variable, and you specify a number to get a particular point.

Of course, if you need your design to be a bit more flexible and want help with this, please provide a bit more detail on what you're doing and what you want to accomplish.




Jun 28 2011, 2:02 am Veta Post #3



That was extremely helpful in it of itself Roy, thank you for your response. To elaborate a little bit I'm in the process of placing a lot of points all over a 256x256 map (it's tedious). Each point will represent a city and fall into 1 of 3 categories: large medium and small. Ultimately this will be around 200+ points but for now I have say 20-30 to work with. This may be wrong but I am assuming your system takes into consideration that I have already placed, categorized and grouped all the points I will use. Since this is indeed a tedious process and since I will be adding the points as I go, am correct in assuming I will have to alter my arrays each time I alter the amount of points and what type of city I want on them for the trigger to run properly? That is to say, if I decide to change a large city to a medium city or remove a city all together I will have to indicate this change in my arrays in order for the cities to spawn correctly?

If that's the best way to do it I think I can manage, it'll probably be easier to simply test the trigger out and see if it works on the say 30 points I have right now and then simply alter my trigger accordingly once I have my final counts, right?

If you're curious I'm working with a team on a diplomacy-type map that depicts the preamble to world war 1 (1870-1900).


Edit: How do I set up an array variable (global) and add points to it? I understand the trigger part.

Post has been edited 1 time(s), last time on Jun 28 2011, 2:18 am by Veta.



None.

Jun 28 2011, 3:36 am Roy Post #4

An artist's depiction of an Extended Unit Death

You have to manually add each point to the array by setting the variable (buildingXpoints[1] = Point 1, buildingXpoints[2] = Point 2, etc.), which is a tedious task within itself. In this sense, you can build the arrays as you go, so you don't need all 200+ points to test the triggers. You will have to categorize the existing points, however, and putting them into the arrays will be your way of grouping them. You will have to alter the arrays as you go, but the only thing you need to do is add to them (increase array size, add new points).

I'm just curious, though: why do you need these points? Couldn't you preplace the buildings themselves and maybe use regions if you need a city-wide change? To get the location of a building, you can use "Position of Unit," which returns a point.




Jun 28 2011, 4:52 am Veta Post #5



Well there are 3 of us working on the project, 1 data, 1 triggers/balance/terrain (me), 1 data/balance/dialogs. Since our data will go through a dependency (so we don't have to share the map to do data changes) I don't even have the units to place yet. We will however tag each city with its respective name so setting down the points for reference (at least) and to label them is necessary. If they can be used to spawn the cities as well (does that cause more lag than just placing them?) then we hope we can save ourselves some trouble that way too then.

So I've got these 3 array variables, do I then use trigger actions to set all the points I want to each array and then use a local variable in another trigger to keep track of this? sorry I'm sort of confused :)

but thank you for your help so far

Edit: I got it to work after all, your code example of the trigger helped a lot. I ended up defining the array variables with another trigger upon map initialization (not sure if that's the best way to do it) but I can now just add each city as i go and it works fine. Then once I want those new points to actually spawn cities all i have to do is change the integral range of each city-type's spawn action.

Anyhow I think I've got the hang of it, thanks a bunch and sorry for being slow at first :)

Post has been edited 2 time(s), last time on Jun 28 2011, 5:53 am by Veta.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[09:24 pm]
Moose -- denis
[05:00 pm]
lil-Inferno -- benis
[10:41 am]
v9bettel -- Nice
[01:39 am]
Ultraviolet -- no u elky skeleton guy, I'll use em better
[2024-4-18. : 10:50 pm]
Vrael -- Ultraviolet
Ultraviolet shouted: How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
hey cut it out I'm getting all the minerals
[2024-4-18. : 10:11 pm]
Ultraviolet -- :P
[2024-4-18. : 10:11 pm]
Ultraviolet -- How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
[2024-4-17. : 11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
Please log in to shout.


Members Online: Oh_Man