A_ThrowGibs

From ZDoom Wiki
Jump to navigation Jump to search

void A_ThrowGibs (class<Actor> cls, bool down)

Details

This function can be used to spawn and throw multiple instances of the specified actor class.
The down parameter makes it apply negative Z velocity to the spawned actors.

Implementing into your mod

Add this function to your project.
The advised place to put it in would be some base class for your monsters, for example.
Note: the default values here are purely arbitrary, you should put the ones that are going to be common in your mod. Example actor provided though.

void A_ThrowGibs(class<Actor> cls = "DNGibs", bool down = false)
{
	int gibscount = random(8, 16);
	for (int i = 0; i < gibscount; i++)
	{
	//
	Actor gibs = Spawn(cls, pos);
	gibs.vel = (frandom(-8,8), frandom(-8,8), frandom(0,down?-1:16));
	}
}

Examples

The following actor shows a random animated flying flesh sprite.

class DNGibs : Actor
{
	override void Tick()
	{
		Super.Tick();
		if (ceilingz==pos.z || floorz==pos.z)
		Destroy();
	}

	Default
	{
		+NOCLIP;
	}

	States
	{
		Spawn:
			TNT1 A 0;
			TNT1 A 0 A_Jump(256, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5");
			stop;

		Spawn1:
			DGI1 ABCD 2;
			loop;

		Spawn2:
			DGI2 ABCD 2;
			loop;

		Spawn3:
			DGI3 ABCD 2;
			loop;

		Spawn4:
			DGI4 ABCD 2;
			loop;

		Spawn5:
			DGI5 ABCD 2;
			loop;
	}
}

Then, in the actor that you want to be explosive, use the function like this:

XDeath:
	TNT1 A 0 A_ThrowGibs;
	stop;