KILL script: detect if killer has a MissileLauncher

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

KILL script: detect if killer has a MissileLauncher

Post by wildweasel »

Another thing for WW-Cola3, the following is my ACS-based "universal item drop" script. It is a KILL script (executed by any monster that is killed) that drops a proportional amount of ColaBubblePickup (or, randomly, DroppedMissileLauncherAmmo) based on the spawn health of the monster calling the script.

Code: Select all

// This script is for "universal" item dropping - enemies need not be replaced, this script will
// drop either a proportional amount of Cola Bubbles to enemies' HP, or (randomly) missiles, based
// on whether a Missile Launcher has been collected by the enemy's killer.
// As of 12/18/2017, though, it does NOT check for missile launchers because I kind of don't know
// how to make that happen. So things just drop missiles whenever they want. Whatever.
Script "ColaItemDropper" KILL
{
	// So first, an explanation of the "HP Multiplier."
	// In order to determine how many Cola Bubbles get dropped by a given monster,
	// I'm taking their spawn health and dividing it by a Magic Number, i.e. ColaBubbleHPMult.
	// This produces what I'm going to call the "HP factor." The int ThisMaxHealth,
	// then, takes the calling actor's spawn health and dividing it by the magic number.
	// So, for example, an Imp has a spawn health of 60, which gets divided by magic number 30,
	// resulting in an HP factor of 2.
	int ColaBubbleHPMult = 30;
	int ThisMaxHealth = ( GetMaxInventory(0, "Health") / ColaBubbleHPMult );
	// From there, I run a few checks divided into what I'm calling "tiers."
	// Small monsters - usually zombiemen - who wind up with an HP factor of 1 or below,
	// skip all the other ensuing checks and only drop one cola bubble.
	// They will never drop missiles, because that's bad for game balance.
	if ( ThisMaxHealth <= 1 )
	{
		DropItem(0, "ColaBubblePickup");
	}
	// The second tier is "medium monsters". If the enemy's HP factor is over 1,
	// but below or equal to 15, that's when we start doing some randomness.
	else if ( ThisMaxHealth > 1 && ThisMaxHealth <= 15 )
	{
		if ( random(0, 255) > 127 ) // Apparently this is "more random" than random(0, 1). Who knew?
		{
			DropItem(0, "DroppedMissileLauncherAmmo"); // Approx. half the time, a medium monster will drop a missile instead of cola bubbles.
		}
		// If we're not dropping the missile, drop a bubble for as long as ThisMaxHealth has value.
		// Essentially, the monster's HP factor is exactly the number of cola bubbles they'll drop.
		// This for loop only occurs if the monster did NOT drop a missile instead.
		// I could have done it backwards, but I have a suspicion this is slightly easier
		// on the ACS VM.
		else for ( int i1 = ThisMaxHealth; i1 >= 1; i1-- )
		{
			DropItem(0, "ColaBubblePickup");
			delay(1);
		}
	}
	// Bigger monsters, of HP factors over 15 but below 25 (everything up to an Arch-Vile)
	// do an alternate version of the check that drops more missiles but less cola bubbles.
	else if ( ThisMaxHealth > 15  && ThisMaxHealth < 25 )
	{
		if ( random(0, 255) > 127 )
		{
			DropItem(0, "DroppedMissileLauncherAmmo");
			DropItem(0, "DroppedMissileLauncherAmmo");
			DropItem(0, "DroppedMissileLauncherAmmo");
		}
		// If we're not dropping the missiles, drop a bubble approx. half the time,
		// for as long as ThisMaxHealth has value. Because otherwise, Hell Knights and
		// Cacodemons drop way too many bubbles for how threatening they are,
		// and basically become instant level ups for the lower-tier weapons.
		else for ( int i2 = ThisMaxHealth; i2 >= 1; i2-- ) // Yes, changing the name of the int because ACC complains otherwise.
		{
			DropItem(0, "ColaBubblePickup", 1, 127); // Taking advantage of DropItem's chance arg here.
			delay(1);
		}
	}
	// The biggest monsters - Barons and bosses - drop way more ammo, but still less cola bubbles.
	else if ( ThisMaxHealth >= 25 )
	{
		DropItem(0, "DroppedMissileLauncherAmmo");
		DropItem(0, "DroppedMissileLauncherAmmo");
		DropItem(0, "DroppedMissileLauncherAmmo");
		DropItem(0, "DroppedMissileLauncherAmmo");
		DropItem(0, "DroppedMissileLauncherAmmo");
		for ( int i3 = ThisMaxHealth; i3 >= 1; i3-- )
		{
			DropItem(0, "ColaBubblePickup", 1, 96); // Throttled down to about a third the drop chance.
			delay(1);
		}
	}
}
What I would LIKE to do with this script is force a monster to never drop a missile if the killing player does not have a MissileLauncher. I've experimented with a few methods of this, and at least got as far as SetActivatorToTarget being the way to shift focus to the player to check their inventory, however this has the side-effect of causing the subsequent DropItems to spawn at the player's feet instead of on the monster's corpse, which is not ideal. Assistance is welcomed.
ZzZombo
Posts: 315
Joined: Mon Jul 16, 2012 2:02 am

Re: KILL script: detect if killer has a MissileLauncher

Post by ZzZombo »

1) Victim gives its killer "I totally have no missile launcher, promise" token of any sort you can check from ACS.
2) When you deal with the victim, change the activator TID to a unique one (save it, of course), proceed as usual to check, then restore the previous activator, resume.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: KILL script: detect if killer has a MissileLauncher

Post by wildweasel »

Okay, cool, and thanks to the wiki page on UniqueTID I was able to learn enough about how it works to get it working with a minimum of fuss. Thank you for the pointer, sir.
Post Reply

Return to “Scripting”