[ACS] Using CheckWeapon in a Kill Script?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Mini--Joe
Posts: 97
Joined: Sun Jul 27, 2014 10:25 am

[ACS] Using CheckWeapon in a Kill Script?

Post by Mini--Joe »

Code: Select all

#library "ammodropper"
#include "zcommon.acs"

script "AMMOdropper" KILL
{
    
	if(CheckWeapon("Chainsaw"))
	{ 
	 DropItem(0,"clip",20,255); DropItem(0,"clip",20,255); DropItem(0,"clip",20,255);
	 DropItem(0,"Shell",8,255); DropItem(0,"Shell",8,255);
	 DropItem(0,"RocketAmmo",1,255); DropItem(0,"RocketAmmo",1,255); DropItem(0,"RocketAmmo",1,255);
	 DropItem(0,"Cell",25,255); DropItem(0,"Cell",25,255); DropItem(0,"Cell",25,255);
	}
} 
I am trying to make any monster drop ammo when killed with the chainsaw, but my script doesn't seem to work.

Does CheckWeapon not work in a kill script because the activator is the slain actor? If so, is there a better way to actually do this?
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by Jarewill »

I think that's the case here.
You could try using SetActivator:

Code: Select all

SetActivator(0, AAPTR_TARGET); //Current activator's target will be the new activator
if(CheckWeapon("Chainsaw"))
{...} 
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by Arctangent »

Should be noted that using this method means that a player can shoot a mid-range rocket, then switch to the chainsaw before the rocket lands and have the monster blow up into ammo confetti. Relying on the player's currently equipped weapon for this kind of thing is only really feasible when every weapon is either literally a hitscan, or close enough to one that it takes longer to finish firing and lowering the weapon than it realistically takes for the projectiles to hit something.

Thinking about it, there's not really a good way to do this without custom death states, even in ZScript. Naively, you could use WorldThingDied to check for a lack of inflictor ( i.e. killing projectile ) and deduce that the thing died to a hitscan, then check to see if its target is a player that's using the chainsaw ... but then if the player aggros it, then it dies to environmental damage like a crusher while the player is using the chainsaw, you'll get the ammo piñata effect. I think I recall that a dying thing's DamageType is set to the damage type of the lethal damage, so maybe you could get away with using that by giving the chainsaw its own damage type, but it's still a bit surprising how many hoops something like this requires.
User avatar
Mini--Joe
Posts: 97
Joined: Sun Jul 27, 2014 10:25 am

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by Mini--Joe »

Yeah I'm realizing that this is more complicated than I was thinking.

Is it possible to add an extra state to all monsters without replacing them? Then I could simply add a chainsaw damagetype and make the pain chance 100%, then just gib any monster.

I guess I'll just make custom monsters, then. I wanted something that would function with monster replacers, but I will have to manually add states to those too.
User avatar
SanyaWaffles
Posts: 886
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by SanyaWaffles »

I don't rely on ACS for that, I just use custom death states for everything. It's so much easier.

However, it isn't universal. Some things simply won't be universal.

However, there is probably a way to check it via a DamageMobj override in ZScript based on what damage is being dealt and if the player is going to do enough damage to kill the enemy, but even then, it'd require replacing the actor anyway and there's no way of replacing the actor of type Actor.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by Dan_The_Noob »

it's probably better to make a damage type for chainsaw or something to use.

maybe use

Code: Select all

GetLevelInfo(LEVELINFO_KILLED_MONSTERS)
somehow
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by Player701 »

It's quite interesting that no one has suggested to use a puff for this. I think the following code should work. The only problem is that ALLOWPARTICLES won't function as intended. This is because that flag is checked for too early in the process of puff spawning, and PostBeginPlay is executed afterwards. Moving the code from BeginPlay to PostBeginPlay won't work either because the tracer pointer hasn't been assigned at that time.

Note that I think it's theoretically possible for multiple attacks to happen on the same tick, so if you want to run the code just once for any given monster, give them an inventory item to serve as a flag.

Code: Select all

class ChainsawPuff : BulletPuff
{
    Default
    {
        -ALLOWPARTICLES;
        +PUFFONACTORS;
        +HITTRACER;
    }

    override void PostBeginPlay()
    {
        Super.PostBeginPlay();

        if (Tracer != null)
        {
            if (Tracer.Health <= 0)
            {
                Console.Printf("%s killed by chainsaw!", Tracer.GetClassName());
            }

            if (!Tracer.bNoBlood && !Tracer.bInvulnerable && !Tracer.bDormant)
            {
                Destroy();
            }
        }
    }
}

class MyChainsaw : Chainsaw replaces Chainsaw
{
    States
    {
         Fire:
            SAWG AB 4 A_Saw(pufftype: 'ChainsawPuff');
            SAWG B 0 A_ReFire;
            Goto Ready;
    }
}
User avatar
Mini--Joe
Posts: 97
Joined: Sun Jul 27, 2014 10:25 am

Re: [ACS] Using CheckWeapon in a Kill Script?

Post by Mini--Joe »

Holy crap, that is EXACTLY what I wanted to do! Thank you very much Player701, I can even reuse this for other stuff, like gaining health when they are killed by a punch.
Post Reply

Return to “Scripting”