Say, for example, that I want every marine to have a zergling as a "pet". Is there anyway I can create a zergling with the marine when the marine is done being trained? Also, how would I make the zergling keep following the marine?
Maybe the Galaxy Editor has a better way to do this, but here's a solution that I have used.
When the marine is constructed (unit enters Entire Map), create a zergling unit at the position of the marine and link them together. You can "link" them by having a global counter that starts at 1, and every time you make a new marine that index is increased. Give the marine a custom value (any index you want, doesn't matter) of the current counter value. Then, you can set the new zergling unit into a global data table with the an identifier plus the custom value of the marine, like "zerglingPet1", you just have to append your marine's custom value with a constant string ID "zerglingPet".
Then, using triggers, whenever your marine attacks an enemy, order the zergling to attack that enemy as well. You can make this happen by grabbing the correct zergling unit back out of the data table using "zerglingPet" + the attacking marine's custom value. Whenever you order a marine to move, find that zerglingPet unit again and order it to move to the marine.
Post back here if you need more help on how to actually implement this with triggers.
I did something like this in WC3, along with what Skrow said, you can alternatively make the zergling patrol the marine. I think they might have changed the function of patrol in SC2 but in any case, you will have to make a custom script for this command.
You can always give the marine a hangar ability with a pre-built zergling as its magazine unit. It will leash to the marine anytime it's not attacking, and act like a carrier's interceptor, attacking whatever the marine attacks. It will also attack any hostiles nearby. If you want to switch targets before the current target is dead, you need to order a stop with the master unit, and then order the attack on the new unit.
So I added what you had in your map WildPickles and it's working great. However, there's one little bug that randomly occurs. If you tell the marine to move somewhere, the marine will sometimes keep going after reaching its destination
Only thing I can really think of that would cause that is if the push priority of the pet unit is equal or higher to the push priority of the marine, and causing it to move out of the way. You can make sure the pet has a lower push priority, and also set its default distance from the marine higher than 0 (it's in the Info+ of the hangar ability). If it's not that, I'm not sure - I haven't been able to replicate the problem.
Say, for example, that I want every marine to have a zergling as a "pet". Is there anyway I can create a zergling with the marine when the marine is done being trained? Also, how would I make the zergling keep following the marine?
Maybe the Galaxy Editor has a better way to do this, but here's a solution that I have used.
When the marine is constructed (unit enters Entire Map), create a zergling unit at the position of the marine and link them together. You can "link" them by having a global counter that starts at 1, and every time you make a new marine that index is increased. Give the marine a custom value (any index you want, doesn't matter) of the current counter value. Then, you can set the new zergling unit into a global data table with the an identifier plus the custom value of the marine, like "zerglingPet1", you just have to append your marine's custom value with a constant string ID "zerglingPet".
Then, using triggers, whenever your marine attacks an enemy, order the zergling to attack that enemy as well. You can make this happen by grabbing the correct zergling unit back out of the data table using "zerglingPet" + the attacking marine's custom value. Whenever you order a marine to move, find that zerglingPet unit again and order it to move to the marine.
Post back here if you need more help on how to actually implement this with triggers.
Wow that's a solid setup, thanks I'll definitely give that a shot :)
Hmm, how do I give the marine a custom value?
@Zurom: Go
I did something like this in WC3, along with what Skrow said, you can alternatively make the zergling patrol the marine. I think they might have changed the function of patrol in SC2 but in any case, you will have to make a custom script for this command.
You can always give the marine a hangar ability with a pre-built zergling as its magazine unit. It will leash to the marine anytime it's not attacking, and act like a carrier's interceptor, attacking whatever the marine attacks. It will also attack any hostiles nearby. If you want to switch targets before the current target is dead, you need to order a stop with the master unit, and then order the attack on the new unit.
That's amazing, thanks WildPickles! (and everyone else who helped :D )
So I added what you had in your map WildPickles and it's working great. However, there's one little bug that randomly occurs. If you tell the marine to move somewhere, the marine will sometimes keep going after reaching its destination
@Zurom: Go
Only thing I can really think of that would cause that is if the push priority of the pet unit is equal or higher to the push priority of the marine, and causing it to move out of the way. You can make sure the pet has a lower push priority, and also set its default distance from the marine higher than 0 (it's in the Info+ of the hangar ability). If it's not that, I'm not sure - I haven't been able to replicate the problem.
That did it, thanks again! :D