Problem with spawning random enemies

Matute2175

New member
Hello friends!! I have a doubt, I use a script to summon random enemies in the scenarios, and it works correctly, but I am not able to make the command map or item work (they always appear with the default palette, and I would like to put other random palettes on them with the map command ). It looks like I would have to include it in the script, can someone help me? Thanks a lot!!

This is the script:



void main()
{
randomenem();
}

void randomenem()
{//Spawn random Enemy
int  pCount = openborvariant("count_players");

if(pCount == 1){
EnemyX(-20, 220, 0);
}else if(pCount == 2){
EnemyX(-20, 220, 0);
}else if(pCount == 3){
EnemyX(-20, 220, 0);
EnemyX(-20, 220, 00);
}else if(pCount == 4){
EnemyX(-20, 220, 0);
EnemyX(-20, 220, 0);
}
}

void EnemyX(float dx, float dy, float dz)
{ //Spawns random enemy next to caller.
//fX: X location adjustment.
//fZ: Y location adjustment.
//fY: Z location adjustment.

void self = getlocalvar("self"); //Get calling entity.
void vSpawn; //Spawn object.
    void vRName = getentityproperty(self,"defaultname"); // Get caller's real name.
int  iDir = getentityproperty(self,"direction"); // Get caller's direction.
int  iR = rand()%99;

if (iR >= 0 && iR <= 7){
vRName = "abobo";
} else if (iR >= 8 && iR <= 14){
vRName = "afrobo";
    } else if (iR >= 15 && iR <= 21){
vRName = "bolo";
    }
else if (iR >= 22 && iR <= 28){
vRName = "abobo";
    } else if (iR >= 29 && iR <= 35){
vRName = "afrobo";
    }
else if (iR >= 36 && iR <= 42){
vRName = "bolo";
    } else if (iR >= 43 && iR <= 49){
vRName = "afrobo";
    }
else if (iR >= 50 && iR <= 56){
vRName = "abobo";
    } else if (iR >= 57 && iR <= 63){
vRName = "eliza";
    }
else if (iR >= 64 && iR <= 70){
vRName = "eliza";
    } else if (iR >= 71 && iR <= 77){
vRName = "abobo";
    }
else if (iR >= 78 && iR <= 84){
vRName = "afrobo";
    } else if (iR >= 85 && iR <= 91){
vRName = "badguy";
    }
else if (iR >= 92 && iR <= 99){
vRName = "badguy";
    }

clearspawnentry(); //Clear current spawn entry.
setspawnentry("name", vRName); //Acquire spawn entity by name.

vSpawn = spawn();

bindentity(vSpawn, self, dx, dz, dy, iDir);

return vSpawn; //Return spawn.
}
 
Hello Matute2175  :D

First of all, I don't know how to modify item drop with script but I do know how to modify map for spawned enemy.
About the script, I can see strangeness there ??? but it seems to be working for you  :o. I have some guesses on how this script is declared  ::).
Anyways, to solve the strangeness while adding map input, you can try this functions:
Code:
void randomenem()
{//Spawn random Enemy based on number of active players
   int pCount = openborvariant("count_players");
   
   if(pCount == 1){
     EnemyX(-20, 220, 0);
   } else if(pCount == 2){
     EnemyX(-20, 220, 0);
   } else if(pCount == 3){
     EnemyX(-20, 220, 0);
     EnemyX(-20, 220, 0);
   } else if(pCount == 4){
     EnemyX(-20, 220, 0);
     EnemyX(-20, 220, 0);
   }
}

void EnemyX(float dx, float dy, float dz)
{ //Spawns random enemy next to caller.
   void self = getlocalvar("self");
   float x = getentityproperty(self, "x");
   float y = getentityproperty(self, "y");
   float z = getentityproperty(self, "z");
   int Health = getentityproperty(self,"health");
   int Map = getentityproperty(self,"map");
   int iDirection = getentityproperty(self, "direction");
   int iR = rand()%50+50;
   char vRName; void vSpawn;

   if(iDirection==0){
     dx = -dx;
   }

   if(iR >= 0 && iR <= 7){
     vRName = "Lesus";
   } else if (iR >= 8 && iR <= 14){
     vRName = "Bred";
   } else if (iR >= 15 && iR <= 21){
     vRName = "Polx";
   } else if (iR >= 22 && iR <= 28){
     vRName = "Jay";
   } else if (iR >= 29 && iR <= 35){
     vRName = "Clown";
   } else if (iR >= 36 && iR <= 42){
     vRName = "Clown2";
   } else if (iR >= 43 && iR <= 49){
     vRName = "Clown3";
   } else if (iR >= 50 && iR <= 56){
     vRName = "Clown4";
   } else if (iR >= 57 && iR <= 63){
     vRName = "Flau";
   } else if (iR >= 64 && iR <= 70){
     vRName = "Lesus";
   } else if (iR >= 71 && iR <= 77){
     vRName = "Bred";
   } else if (iR >= 78 && iR <= 84){
     vRName = "Tesuni";
   } else if (iR >= 85 && iR <= 91){
     vRName = "Flau";
   } else if (iR >= 92 && iR <= 100){
     vRName = "Lesus";
   }

   clearspawnentry(); //Clear current spawn entry.
   setspawnentry("name", vRName); //Acquire spawn entity by name

   vSpawn = spawn(); //Spawn in entity.

   changeentityproperty(vSpawn, "maxhealth", Health);
   changeentityproperty(vSpawn, "health", Health);
   changeentityproperty(vSpawn, "position", x+dx, z+dz, y+dy); //Set spawn location
   changeentityproperty(vSpawn, "direction", iDirection); //Set direction
   changeentityproperty(vSpawn, "map", Map);
}
void suicide()
{ // Suicide!!
    void self = getlocalvar("self");

    killentity(self); //Suicide!
}

I've changed enemy names to make it working on my test mod, you can change them later :)
I've included suicide cause it's needed in entity using those functions. Here's an example:
Code:
name	Randomer
type	none
animationscript	data/scripts/enemy.c
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png


anim	idle
	delay	10
	offset	1 1
	frame	data/chars/misc/empty.png
	@cmd	randomenem
	frame	data/chars/misc/empty.png
	@cmd	suicide
	frame	data/chars/misc/empty.png

I showed this example also to show that in order for map setting to work, this entity must have same number of maps or more maps from to be spawned enemy.
The function also apply set health and direction so you can set those also in level  8), like this:
Code:
spawn	Randomer
health	20
map	2
coords	410 210
at	200

spawn	Randomer
health	30
map	3
coords	410 210
at	200

HTH
 
It works perfectly!!!! Thank you very much  Bloodbane, without your help I would not have been able to get it, it was impossible for me !! now I can control the alternate palettes and not depend only on the one that comes by default  ;D
 
You're welcome  8)

Oh I've just remembered something important. OpenBoR will load enemy, NPC or obstacle if they are spawned in level text. However OpenBoR won't load them if they are spawned by script or spawn commands.
Therefore you have to add load command in Randomer to load to be spawned enemy to ensure the latter will be spawned.
For example:
Code:
name	Randomer
type	none
animationscript	data/scripts/enemy.c
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
alternatepal	data/chars/misc/empty.png
load		Clown
load		Clown2
load		Clown3
load		Clown4
load		Bred
load		Polx
load		Lesus
load		Flau
load		Tesuni
load		Jay


anim	idle
	delay	10
	offset	1 1
	frame	data/chars/misc/empty.png
	@cmd	randomenem
	frame	data/chars/misc/empty.png
	@cmd	suicide
	frame	data/chars/misc/empty.png

Those names loaded with load command are names in EnemyX function.
 
Back
Top Bottom