I find this hilarious because I made an enemy that does that very thing last night.
Alright, I made all my familiars child enemies. At the beginning of the parent enemy, I declare a random number:
let r = rand(0, 100);
This will be the name of the random CommonData we will set. We're setting the name of the CommonData as a random number so that if you plan on spawning more than one of these enemies, they won't use the same coordinates.
In the @MainLoop of the main parent enemy, we'll be setting his coordinates into the CommonData. We'll use a small array so we don't have to set two different CommonDatas.
SetCommonData(ToString(r), [GetX, GetY]);
The name of CommonData has to be a string, so we'll just quickly convert it using ToString.
Now, when we go to spawn a child enemy, how will it know what CommonData to get? We'll use it's argument to pass along the value.
CreateEnemyFromScript("familiar", GetX, GetY, 0, 0, r);
Now the familiar script knows the name of the correct CommonData to get (and not some other enemy's). Getting it is simple, to get the X coordinate, just type:
GetCommonData(ToString(GetArgument))[ 0 ];
Our first element in the CommonData array is the x coordinate of the parent enemy, so we need to get that using [ 0 ]. The y coordinate would be exactly the same, except with [ 1 ], since we're getting the second element in the array. So you're position code would look something like:
SetX(GetCommonDataDefault(ToString(GetArgument), [-9999, -9999])[ 0 ] + 50*cos(angle));
SetY(GetCommonDataDefault(ToString(GetArgument), [-9999, -9999])[ 1 ] + 50*sin(angle));
This would make the familiars rotate around the parent enemy, 50 pixels away. Well, as long as you increase angle, and set it every @MainLoop. The reason why we use GetCommonDataDefault is so that when the parent enemy gets deleted (along with all the CommonData), the child familiars will be thrown off into oblivion instantly, killing them along with the main parent.
Here's the enemy script that I wrote up last night. Note that I'm already transferring a difficulty setting through my argument parameter, so I actually use the angle parameter to transfer the CommonData name.
script_enemy_main{
#include_function "script\script_enemy\enemymisc\EnemyControl.txt"
let r = rand(0, 100);
let a = rand(0, 360);
task Attack(Difficulty){
loop(10){yield;}
if(Difficulty==1){
loop(10){
CreateEnemyFromScript("swarm", GetX, GetY, 0, r, Difficulty);
loop(10){yield;}
}
}
if(Difficulty==2){
loop(15){
CreateEnemyFromScript("swarm", GetX, GetY, 0, r, Difficulty);
loop(7){yield;}
}
}
if(Difficulty==3){
loop(20){
CreateEnemyFromScript("swarm", GetX, GetY, 0, r, Difficulty);
loop(5){yield;}
}
}
if(Difficulty==4){
loop(20){
CreateEnemyFromScript("swarm", GetX, GetY, 0, r, Difficulty);
loop(5){yield;}
}
}
loop(150){yield;}
if(GetX<224){
SetMovePosition02(500, GetY, 240);
}
if(GetX>=224){
SetMovePosition02(-50, GetY, 240);
}
}
task Attack2(Difficulty){
if(Difficulty==1){
}
if(Difficulty==2){
loop(50){
CreateShotA(0, GetX + 50*cos(a) + rand(-5, 5), GetY + 50*sin(a) + rand(-5, 5), 10);
SetShotDataA(0, 0, 7, a + rand_int(-20, 20), 0, -0.5, 1.8, BLUE12);
FireShot(0);
CreateShotA(0, GetX + 50*cos(a + 2) + rand(-5, 5), GetY + 50*sin(a + 2) + rand(-5, 5), 10);
SetShotDataA(0, 0, 7, a + rand_int(-20, 20), 0, -0.5, 1.8, BLUE12);
FireShot(0);
a+=12;
loop(5){yield;}
}
}
if(Difficulty==3){
loop(70){
CreateShotA(0, GetX + 50*cos(a) + rand(-5, 5), GetY + 50*sin(a) + rand(-5, 5), 10);
SetShotDataA(0, 0, 7, a + rand_int(-20, 20), 0, -0.5, 2, BLUE12);
FireShot(0);
CreateShotA(0, GetX + 50*cos(a + 2) + rand(-5, 5), GetY + 50*sin(a + 2) + rand(-5, 5), 10);
SetShotDataA(0, 0, 7, a + rand_int(-20, 20), 0, -0.5, 2, BLUE12);
FireShot(0);
a+=10;
loop(4){yield;}
}
}
if(Difficulty==4){
loop(140){
CreateShotA(0, GetX + 50*cos(a) + rand(-5, 5), GetY + 50*sin(a) + rand(-5, 5), 10);
SetShotDataA(0, 0, 7, a + rand_int(-20, 20), 0, -0.5, 2.5, BLUE12);
FireShot(0);
CreateShotA(0, GetX + 50*cos(a + 2) + rand(-5, 5), GetY + 50*sin(a + 2) + rand(-5, 5), 10);
SetShotDataA(0, 0, 7, a + rand_int(-20, 20), 0, -0.5, 2.5, BLUE12);
FireShot(0);
a+=5;
loop(2){yield;}
}
}
}
@Initialize{
SetInvincibility(10);
SetMovePosition03(GetX, 150, 10, 3);
SetLife(130);
Attack(GetArgument);
Attack2(GetArgument);
}
@MainLoop{
DeathCheck;
SetCommonData(ToString(r), [GetX, GetY]); //Set coordinates for the familiar to get.
SetCollisionA(GetX, GetY, 16);
SetCollisionB(GetX, GetY, 4);
yield;
}
@DrawLoop{
DrawBigEnemy;
}
@Finalize{
DeadEnemy(GetX, GetY, 5, 0, 5, 50); //x, y, points, power, IE, dispersion radius.
}
}
script_enemy swarm{
#include_function "script\script_enemy\enemymisc\EnemyControl.txt"
let a = rand(0, 360);
let radius = 0;
let xvar = rand(0, 90);
let yvar = rand(0, 90);
let maxrad = rand_int(50, 100);
let Difficulty = GetArgument;
let frames = rand_int(2, 30);
let gg = GetAngle;
task Attack{
if(Difficulty==1){
loop(frames){yield;}
loop{
let ran = rand(-90, 90);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran, RED12, 0);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran + 1, RED12, 0);
loop(80){yield;}
}
}
if(Difficulty==2){
loop(frames){yield;}
loop{
let ran = rand(-90, 90);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran, RED12, 0);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran + 1, RED12, 0);
loop(60){yield;}
}
}
if(Difficulty==3){
loop(frames){yield;}
loop{
let ran = rand(-90, 90);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran, RED12, 0);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran + 1, RED12, 0);
let ran = rand(-90, 90);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran, RED12, 0);
CreateShot01(GetX, GetY, 2, GetAngleToPlayer + ran + 1, RED12, 0);
loop(50){yield;}
}
}
if(Difficulty==4){
loop(frames){yield;}
loop{
let ran = rand(-90, 90);
CreateShot01(GetX, GetY, 2.2, GetAngleToPlayer + ran, RED12, 0);
CreateShot01(GetX, GetY, 2.2, GetAngleToPlayer + ran + 1, RED12, 0);
CreateShot01(GetX, GetY, 2.2, GetAngleToPlayer + ran - 1, RED12, 0);
let ran = rand(-90, 90);
CreateShot01(GetX, GetY, 2.2, GetAngleToPlayer + ran, RED12, 0);
CreateShot01(GetX, GetY, 2.2, GetAngleToPlayer + ran + 1, RED12, 0);
CreateShot01(GetX, GetY, 2.2, GetAngleToPlayer + ran - 1, RED12, 0);
loop(40){yield;}
}
}
}
@Initialize{
SetLife(10);
SetDamageRateEx(100, 100, 10, 10);
Attack;
}
@MainLoop{
SetCollisionA(GetX, GetY, 16);
SetCollisionB(GetX, GetY, 4);
DeathCheck;
SetX(GetCommonDataDefault(ToString(gg), [-2000, -2000])[0] + radius*cos(a + xvar));
SetY(GetCommonDataDefault(ToString(gg), [-2000, -2000])[1] + radius*sin(a + yvar));
if(radius<maxrad){
radius++;
}
a+=3;
yield;
}
@DrawLoop{
DrawSmallGreenEnemy;
}
@Finalize{
DeadEnemy(GetX, GetY, 1, 0, 0, 10); //x, y, points, power, IE, dispersion radius.
}
}
God I hope I explained this clearly :<