I have a couple game mechanic that I want to implement in my map and I am having trouble with them. I think it's pretty complicated, so I need some help.
I will begin with the first one on this post. Okay so, I have a unit (created with dialogue at the biginning of the map) that can use an ability to create multiple units at once. Right now (still work in progress) it create 4 units and then I have an upgrad that can increase this number (3 times, going up to 10 units).
What I want to do is to be always controlling the units created as one, like a group. What i mean is if I select one of the unit created, I select the others with it, so they are always together, moving, attacking etc... I cant use one individually, unless the others dies of course.
For example, I use my ability and create my 4 units, If I select one of them, I select the 3 other with it, so I am only able to use them as a group, I cant send one in a direction and 1 in another. I want this everytime I use my ability for every group of units created.
Is there a way to do this properly? Even not with triggers?
Will there be problems? Like with selection? deselection? With drag, selection box? With control group?
You will probably need to add the units to a unique Unit Group variable to keep track of them. Do this when they are created.
I believe there is a Unit Is Selected event that you could use to start things off. If a unit from your unit group (we'll call it Squad for now) triggers the event, select all units in unit group Squad.
Under conditions, use a check to see if (Selected Unit) is in Squad == true.
Under actions, pick each unit in Squad and add them to the triggering player's selection.
Yea about the unit group, that what I was thinking off, I started this way creating a unit group for my squad when created and then when I select a unit inside the squad, it select the squad. thx for the condition I forgot about that.
But now there are some problems.
The first one is that every units created are added to the same group. I want each squad added to their own group. How can I do that effectively?
The second one is when I select one unit, it select the all group as planed but when I select it again (when all units selected) it select only the one unit.
How can I deal with that?
Make the variable Squad an array. Set the size of the array to the maximum number of squads that would exist on the map at any given time. So if each player can have a maximum of 5 squads and there are 10 players, set it to 50. Then when a squad is created, create a loop that checks every Squad unit group from 1 to 50 and when it finds one that is empty (number of units in Squad[x] = 0) assign the squad to that Squad variable and break the loop.
For the selection, try completely clearing the player's selection before selecting all of the units in the group. There's an action called "Clear Selected Units" or something similar that will do this.
Selecting a single unit from a group may not count as a selection event (strangely.) You can try having a running loop check the number of units selected. If the number of units selected = 1, check which squad the selected unit belongs to and add all of those units in that squad to the player's selection.
Here's a basic rundown of setting up a loop:
By the way, these are all off of the top of my head so the phrasing might be a bit different in the editor.
For checking a squad array and then adding a unit group to that variable:
You should make any running loops operate in their own thread, which means either put it in an action definition and check the Create Thread option or create a separate trigger for it.
Okay, for the first loop, I only need one variable unit group empty with array, right? I think I do all correctly except for the squadunit thing, I dont understand, instead I put units created here but it doesnt work. Also, for pick each integer there is no increment, however there is increment for each integer, action. You sure that I use the right action or it was just a mistake?
For checking the unit selection, the problem is not only with one unit, it can happened with more than one too. I cant take a value for number of units selected by player. Is there another way or am I doing something wrong? And I dont understand Get Squad ID? How can I do that, I cant find add picked unit to selection.
Sorry but it is really complicated for me. Its harder to not have the right name, I am not very good using the editor plus mine is in french so that doesnt help. Maybe if you have time you could test your ideas, copy your code for me if it work? That may be faster or just tell me whats wrong if it is simple.
In any case really appreciate your help.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hi everyone,
I have a couple game mechanic that I want to implement in my map and I am having trouble with them. I think it's pretty complicated, so I need some help.
I will begin with the first one on this post. Okay so, I have a unit (created with dialogue at the biginning of the map) that can use an ability to create multiple units at once. Right now (still work in progress) it create 4 units and then I have an upgrad that can increase this number (3 times, going up to 10 units).
What I want to do is to be always controlling the units created as one, like a group. What i mean is if I select one of the unit created, I select the others with it, so they are always together, moving, attacking etc... I cant use one individually, unless the others dies of course.
For example, I use my ability and create my 4 units, If I select one of them, I select the 3 other with it, so I am only able to use them as a group, I cant send one in a direction and 1 in another. I want this everytime I use my ability for every group of units created.
Is there a way to do this properly? Even not with triggers? Will there be problems? Like with selection? deselection? With drag, selection box? With control group?
You will probably need to add the units to a unique Unit Group variable to keep track of them. Do this when they are created.
I believe there is a Unit Is Selected event that you could use to start things off. If a unit from your unit group (we'll call it Squad for now) triggers the event, select all units in unit group Squad.
Under conditions, use a check to see if (Selected Unit) is in Squad == true.
Under actions, pick each unit in Squad and add them to the triggering player's selection.
Try that and see how it goes.
@BasharTeg: Go
Thx for the reply,
Yea about the unit group, that what I was thinking off, I started this way creating a unit group for my squad when created and then when I select a unit inside the squad, it select the squad. thx for the condition I forgot about that.
But now there are some problems. The first one is that every units created are added to the same group. I want each squad added to their own group. How can I do that effectively?
The second one is when I select one unit, it select the all group as planed but when I select it again (when all units selected) it select only the one unit. How can I deal with that?
Make the variable Squad an array. Set the size of the array to the maximum number of squads that would exist on the map at any given time. So if each player can have a maximum of 5 squads and there are 10 players, set it to 50. Then when a squad is created, create a loop that checks every Squad unit group from 1 to 50 and when it finds one that is empty (number of units in Squad[x] = 0) assign the squad to that Squad variable and break the loop.
For the selection, try completely clearing the player's selection before selecting all of the units in the group. There's an action called "Clear Selected Units" or something similar that will do this.
@BasharTeg: Go
Ok I knew it was something to do with arrays and loops but I am not really good at this.
I know how to make the variable an array but I have some troubles with loops can you detailed more on how to do this with triggers?
For the selction, I try what you said and it didnt work. I noticed that it also happened when I select one unit in the UI panel (when all selected)
I think the problem cant be solved like this. I cant find a way to do this, have you another idea?
BasharTeg can you detailed what I need to do? Or somebody else can help me with loops and the selection pb?
@TGCID281: Go
Selecting a single unit from a group may not count as a selection event (strangely.) You can try having a running loop check the number of units selected. If the number of units selected = 1, check which squad the selected unit belongs to and add all of those units in that squad to the player's selection.
Here's a basic rundown of setting up a loop: By the way, these are all off of the top of my head so the phrasing might be a bit different in the editor. For checking a squad array and then adding a unit group to that variable:
Creating a running loop (for checking the unit selection):
You should make any running loops operate in their own thread, which means either put it in an action definition and check the Create Thread option or create a separate trigger for it.
@BasharTeg: Go
Okay, for the first loop, I only need one variable unit group empty with array, right? I think I do all correctly except for the squadunit thing, I dont understand, instead I put units created here but it doesnt work. Also, for pick each integer there is no increment, however there is increment for each integer, action. You sure that I use the right action or it was just a mistake?
For checking the unit selection, the problem is not only with one unit, it can happened with more than one too. I cant take a value for number of units selected by player. Is there another way or am I doing something wrong? And I dont understand Get Squad ID? How can I do that, I cant find add picked unit to selection.
Sorry but it is really complicated for me. Its harder to not have the right name, I am not very good using the editor plus mine is in french so that doesnt help. Maybe if you have time you could test your ideas, copy your code for me if it work? That may be faster or just tell me whats wrong if it is simple. In any case really appreciate your help.