Solved Item that spawns a wave of npc entities

Question that is answered or resolved.

kimono

Well-known member
Hi dear members,

I wish to create an item that spawns a wave of NPC cats that runs from left to right on screen and damage the enemies during this time.
Is anyone knows if there is an example on how to make this? Thank you all :)

 
Will they run only one time or will them stay on the screen?
If the first case, you can create a subtype arrow. If the second case, you can use a subtype biker.

You will need a takedamage script - you can adapt the code I've wrote here http://www.chronocrash.com/forum/index.php?topic=3115.0
 
O Ilusionista : Thanks for your answer. I use them as an
Code:
enemy arrow
and they behave like a rolling drum obstacle :)
Here's how I set them:
Code:
name	        catrush
health	        10
speed           10
type	        enemy
subtype         arrow
gfxshadow       1
nolife			1
candamage       enemy
subject_to_hole 1
no_adjust_base  0
noquake 		1 1

palette 		data/chars/cat/run1.png

anim idle
    loop    1
    bouncefactor 1
	attack1 27 7 35 19 3 1 0 0 5 12
	loop	1
	delay	14
	offset	27 30
	bbox 8 -5 28 35
	frame	data/chars/cat/run1.png
	frame	data/chars/cat/run2.png
	frame	data/chars/cat/run1.png
	frame	data/chars/cat/run4.png
	frame	data/chars/cat/run5.png
	frame	data/chars/cat/run6.png	
	attack	0
	frame	data/chars/cat/run1.png

anim fall
	delay	14
	offset	27 30
	bbox 8 -5 28 35
	attack1 27 7 35 19 3 1 0 0 5 12
	frame	data/chars/cat/run1.png
	frame	data/chars/cat/run2.png
	frame	data/chars/cat/run1.png
	frame	data/chars/cat/run4.png
	frame	data/chars/cat/run5.png
	frame	data/chars/cat/run6.png

With this summoncatrush.c :
Code:
void main()
{//Script for summoning 6 alley cats
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int PIndex = getentityproperty(target,"playerindex"); // Get player's index
    int PScore = getplayerproperty(PIndex,"score"); // Get player's score
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int fX = -60; // Set distance from screen edge
    int Zenter = (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z"))/2;
    void vSpawn; //Spawn object.

    if(PScore == NULL()){
      PScore=0;
    }

    changeplayerproperty(PIndex, "score", PScore-1); // Reduce score a bit
//1st spawn
    vSpawn = spawn01("catrush", 0, 40, 40);

    changeentityproperty(vSpawn, "position", XPos+fX, Zenter);
    changeentityproperty(vSpawn, "direction", 1);
//2nd spawn
    vSpawn = spawn01("catrush1", 0, 40, 40);

    changeentityproperty(vSpawn, "position", XPos+fX, Zenter-10);
    changeentityproperty(vSpawn, "direction", 1);
//3rd spawn
    vSpawn = spawn01("catrush2", 0, 0, 40, 40);

    changeentityproperty(vSpawn, "position", XPos+fX, Zenter+10);
    changeentityproperty(vSpawn, "direction", 1);
//4th spawn
    vSpawn = spawn01("catrush", 0, 0, 40, 40);

    changeentityproperty(vSpawn, "position", XPos+fX, Zenter+20);
    changeentityproperty(vSpawn, "direction", 1);	
//5th spawn
    vSpawn = spawn01("catrush1", 0, 0, 40, 40);

    changeentityproperty(vSpawn, "position", XPos+fX, Zenter-20);
    changeentityproperty(vSpawn, "direction", 1);
//6th spawn
    vSpawn = spawn01("catrush2", 0, 0, 40, 40);

    changeentityproperty(vSpawn, "position", XPos+fX, Zenter+30);
    changeentityproperty(vSpawn, "direction", 1);
	
}

void spawn01(void vName, float fX, float fY, float fZ)
{
	//spawn01 (Generic spawner)
	//Damon Vaughn Caskey
	//07/06/2007
	//
	//Spawns entity next to caller.
	//
	//vName: Model name of entity to be spawned in.
	//fX: X location
	//fY: Y location
	//fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

	vSpawn = spawn(); //Spawn in entity
	changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location. 

	return vSpawn; //Return spawn
}
Currently, only 3 cats appear of the 6 and 2 of them don't bounce :/.
Edit: It works a little better when I set them to npc type but some of them still don't bounce.

The demo for testing purpose:
https://drive.google.com/file/d/11VBGBw0FMCAykFRuHqYG_MPI1l-olfgD/view?usp=sharing
 
I solved this by setting this entity as an npc arrow and modifiying the script like that:
Code:
void main()
{//Script for summoning 6 alley cats
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int PIndex = getentityproperty(target,"playerindex"); // Get player's index
    int PScore = getplayerproperty(PIndex,"score"); // Get player's score
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int fX = -60; // Set distance from screen edge
    int Zenter = (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z"))/2;
    void vSpawn; //Spawn object.

    if(PScore == NULL()){
      PScore=0;
    }

    changeplayerproperty(PIndex, "score", PScore-1); // Reduce score a bit
//1st spawn
    vSpawn = spawn01("catrush", 0, 20, 0);
    changeentityproperty(vSpawn, "position", XPos+fX, Zenter);
    changeentityproperty(vSpawn, "direction", 1);
//2nd spawn
    vSpawn = spawn01("catrush1", 0, 30, 0);
	changeentityproperty(vSpawn, "position", XPos+fX, Zenter-20);
    changeentityproperty(vSpawn, "direction", 1);
//3rd spawn
    vSpawn = spawn01("catrush2", 0, 20, 0);
	changeentityproperty(vSpawn, "position", XPos+fX, Zenter-40);
	changeentityproperty(vSpawn, "direction", 1);
//4th spawn
    vSpawn = spawn01("catrush", 0, 30, 20);
	changeentityproperty(vSpawn, "position", XPos+fX, Zenter +20);
    changeentityproperty(vSpawn, "direction", 1);	
//5th spawn
    vSpawn = spawn01("catrush1", 0, 20, 40);
	changeentityproperty(vSpawn, "position", XPos+fX, Zenter +40);
    changeentityproperty(vSpawn, "direction", 1);
//6th spawn
    vSpawn = spawn01("catrush2", 0, 30, 60);
	changeentityproperty(vSpawn, "position", XPos+fX, Zenter +60);
    changeentityproperty(vSpawn, "direction", 1);
	
}

void spawn01(void vName, float fX, float fY, float fZ)
{
	//spawn01 (Generic spawner)
	//Damon Vaughn Caskey
	//07/06/2007
	//
	//Spawns entity next to caller.
	//
	//vName: Model name of entity to be spawned in.
	//fX: X location
	//fY: Y location
	//fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

	vSpawn = spawn(); //Spawn in entity
	changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location. 

	return vSpawn; //Return spawn
}
Is anyone can tell me how can I set 3 waves of this 6 alley cats with a short delay between each of them activated by this milk item?
 
is anyone can tell me how can I set 3 waves of this 6 alley cats with a short delay between each of them activated by this milk item?
Make the last 3 to spawn on a different animation, where there is a small delay (like an invisible frame) on the start of the animation.
 
Hi O'Ilusionista, I show you first on wave of cats and after the desired effect (3 waves of cats spawned with a short delay between each):
https://www.youtube.com/watch?v=-kJ5FS3bJs0

How I can repeat with this short delay inside the item script?
 
As I said, you spawn the 6 things inside the script. But for 3 of them, you make them go to a different animation (a follow, for example), which has the delay with an invisible frame.

Just add this line to the ones you want:
Code:
changeentityproperty(vSpawn, "animation", "ANI_FOLLOW1");

Also, why are you using 3 different entities for that? catrush, catrush1 and catrush2?
You can use only one on different animations.
 
I use catrush1 and 2 for alternate palette 1 and 2 but you are right I can use only one entity spawned differently, so there maybye one method to simplify this. Thanks, I will try the anim follow method and let you know if I manage to have a good result 😉
 
Edit : Thanks to Kratus, the multiple waves setting is resolved. I like the way all is explained and the possibility to parameter some great stuffs like the number and the distance between each wave! It's a great work and you can be proud of it:
Code:
void main()
{//Script for summoning 18 alley cats
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int PIndex = getentityproperty(target,"playerindex"); // Get player's index
    int PScore = getplayerproperty(PIndex,"score"); // Get player's score
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int edge = 10; // Set distance from screen edge of the first wave
    int dist = 70; // Set distance from each wave
    int Zenter = (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z"))/2;
    void vSpawn; // Spawn object.
    int fX; // Calculated X position
    int maxCount = 3; // Used to define how much waves will be spawned
    int add = 1; // Used to add+1 to the wave counter

    if(PScore == NULL()){
      PScore=0;
    }

    // Start wave counter variable if null
    if(getlocalvar("catCount"+self) == NULL()){setlocalvar("catCount"+self, 0);}

    while(getlocalvar("catCount"+self) < maxCount){ // Repeat the entire script until the maximum number os waves is not reached
        fX = XPos-edge-(dist*getlocalvar("catCount"+self));// Calculate the correct distance from the screen edge and between each wave
        changeplayerproperty(PIndex, "score", PScore-1); // Reduce score a bit
    //1st spawn
        vSpawn = spawn01("catrush", 0, 20, 0);
        changeentityproperty(vSpawn, "position", fX, Zenter);
        changeentityproperty(vSpawn, "direction", 1);
    //2nd spawn
        vSpawn = spawn01("catrush1", 0, 30, 0);
        changeentityproperty(vSpawn, "position", fX, Zenter-20);
        changeentityproperty(vSpawn, "direction", 1);
    //3rd spawn
        vSpawn = spawn01("catrush2", 0, 20, 0);
        changeentityproperty(vSpawn, "position", fX, Zenter-40);
        changeentityproperty(vSpawn, "direction", 1);
    //4th spawn
        vSpawn = spawn01("catrush", 0, 30, 20);
        changeentityproperty(vSpawn, "position", fX, Zenter +20);
        changeentityproperty(vSpawn, "direction", 1);	
    //5th spawn
        vSpawn = spawn01("catrush1", 0, 20, 40);
        changeentityproperty(vSpawn, "position", fX, Zenter +40);
        changeentityproperty(vSpawn, "direction", 1);
    //6th spawn
        vSpawn = spawn01("catrush2", 0, 30, 60);
        changeentityproperty(vSpawn, "position", fX, Zenter +60);
        changeentityproperty(vSpawn, "direction", 1);
        setlocalvar("catCount"+self, getlocalvar("catCount"+self)+add); // Add +1 to the wave counter variable
    }
}

void spawn01(void vName, float fX, float fY, float fZ)
{
	//spawn01 (Generic spawner)
	//Damon Vaughn Caskey
	//07/06/2007
	//
	//Spawns entity next to caller.
	//
	//vName: Model name of entity to be spawned in.
	//fX: X location
	//fY: Y location
	//fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

	vSpawn = spawn(); //Spawn in entity
	changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location. 

	return vSpawn; //Return spawn
}
 
Thank you O Ilusionista for your concern, I know we both have so few free time. I wish a warmth welcome for your next Avengers update and I will test it (Iron Fist is my favorite :p).
 
Back
Top Bottom