Checking monsters health for a weapon

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
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Checking monsters health for a weapon

Post by nekostuffing »

I need to get a weapon, to enter a custom state, when firing, if the monster has a certain amount of health left, i tried using A_JumpIfHealthLower
with AAPTR_TARGET as the pointer, but the weapon enters the new state when firing, regardless of weather there is a monster in sight or not, and i dont think its checking my health either since even if im at full health it keeps entering the custom state.

Code: Select all

    States
    Fire:
	TNT1 A 0 A_JumpIfHealthLower(40, "ChainSwordGloryKill", AAPTR_TARGET) //Hoping this checks for monsters health
        SWRG BC 2
        TNT1 A 0 A_PlaySound("weapons/Chainsaw/loop")
        TNT1 A 0 A_Saw("weapons/chainsaw/loop", "weapons/chainsaw/cut", 26, "SSawPuff")
        SWRG EFGHIJKA 2 A_WeaponReady(1)
        Goto ReadyLoop
        
     ChainSwordGloryKill: //The custom state
	    TNT1 A 0 A_Jump(80,"ChainsawGloryKill2","ChainsawGloryKill3")
	    TNT1 A 0 A_PlaySound("weapons/sawfull")
	    SWRG BC 2
	    SWRG E 2 A_Saw("", "CSAWFLESH", 4, "SSawPuff",0,120,32)
	    SWRG F 4 A_Saw("", "CSAWFLESH", 4, "SSawPuff",0,90,32)
	    SWRG G 4 A_Saw("", "CSAWFLESH", 4, "SSawPuff",0,90,32)
	    SWRG H 4 A_Saw("", "CSAWFLESH", 4, "SSawPuff",0,90,32)
	    SWRG I 4 A_Saw("", "CSAWFLESH", 4, "SSawPuff",0,90,32)
	    SWRG J 4 A_Saw("", "CSAWFLESH", 4, "SSawPuff",0,90,32)
	    SWRG K 4 A_Saw("", "CSAWFLESH", 40, "SSawPuff",0,90,32)
	    SWRG A 2 A_WeaponReady(1)
	    Goto Ready
        
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Checking monsters health for a weapon

Post by Jarewill »

I don't know about doing this in DECORATE, but you can use LineTrace for it in ZScript.
For example, if you inherit your DECORATE weapon from this base class, you will gain access to this custom function which should do what you want:

Code: Select all

Class WeaponBase : Weapon
{
	Action state A_CheckMonsterHealth(int hp, statelabel state)
	{ //The custom function
		FLineTraceData h;
		LineTrace(angle,1024,pitch,0,height/2,data: h); //Fire a line trace and save the data as "h"
		If(h.HitActor != null && h.HitActor.health <= hp)
		{ //If it hit an actor and if the actor's health is less than specified amount, jump to the state
			Return ResolveState(state);
		} //Otherwise do nothing
		Else{Return null;}
	}
}
Then you can use this function freely in DECORATE, like this:

Code: Select all

	TNT1 A 0 A_CheckMonsterHealth(10,"FireShotgun")
I hope this helps.
User avatar
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Checking monsters health for a weapon

Post by nekostuffing »

Jarewill wrote: Thu Aug 25, 2022 9:57 am For example, if you inherit your DECORATE weapon from this base class.
Can i do the inheritance more indirectly, for example my weapon already inherits from a decorate base class, so if i make the base class inherit from this zscript class will i still get the function to work?

Code: Select all

//Code By Jarewill
Class NewWeaponBase : DoomWeapon 
{
	Action state A_CheckMonsterHealth(int hp, statelabel state)
	{ //The custom function
		FLineTraceData h;
		LineTrace(angle,1024,pitch,0,height/2,data: h); //Fire a line trace and save the data as "h"
		If(h.HitActor != null && h.HitActor.health <= hp)
		{ //If it hit an actor and if the actor's health is less than specified amount, jump to the state
			Return ResolveState(state);
		} //Otherwise do nothing
		Else{Return null;}
	}
}

ACTOR BLoodAngelWeapon : NewWeaponBase //The base of the weapon that uses the new function
{
    //$Category Weapons
    Game Doom
    Weapon.AmmoUse1 0
    Weapon.AmmoUse2 0
    Weapon.AmmoGive1 0
    Weapon.AmmoGive2 0
	Scale 0.6
    +WEAPON.NOAUTOAIM
    +FORCEXYBILLBOARD
    +WEAPON.NOALERT
    States
    {
	LedgeClimb:
     TNT1 A 0 A_ZoomFactor(1.0)
     TNT1 A 0 A_SetPitch(+8)
	 CL1M ABC 2 A_Stop
	 CL1M D 2 A_SetPitch(+4) 
	 CL1M CBA 2 A_SetPitch(+4) 
	 TNT1 A 0 A_TakeInventory("Climbed_Ledge", 5000)
	 TNT1 A 0 A_TakeInventory("Grabbing_A_Ledge", 5000)
	 Goto Ready+1
    Ready:
    ReadyLoop:
    Deselect:
    Fire:
    Flash:
    Spawn:
        TNT1 A 0 A_Print("??? Weapon reached unimplemented state ???")
        Stop
    Select:
		TNT1 A 0 A_WeaponOffset(0.0, 32.0)
        TNT1 A 0 A_Raise(60)
        Wait
    AltFire: //Actually kick
        TNT1 A 0 A_PlaySound("weapons/melee/kick")
        TNT1 A 0 SetPlayerProperty(0, 1, PROP_FROZEN)
        //If the player has been punching, end the combo here
        TNT1 A 0 A_TakeInventory("PSeq1", 2)
        TNT1 A 0 A_TakeInventory("PSeq2", 1)
        TNT1 A 0 A_jumpifinventory("PowerStrength",1,"BerserkerKick")
        STMP ABCDEF 1
        TNT1 A 0 A_FireCustomMissile("KickAttack", 0, 0, 0, -7)
        STMP G 4
        STMP HIJK 2
        TNT1 A 0 A_Jump(256, "FinishKick")

    BerserkerKick:
        KICK ABCDEFG 1
        TNT1 A 0 A_FireCustomMissile("SuperKickAttack", 0, 0, 0, -7)
        KICK H 3
        KICK IGFEDCBA 1

    FinishKick:
        TNT1 A 0 SetPlayerProperty(0,0, PROP_FROZEN)
        TNT1 A 0 A_TakeInventory("KickHasHit", 1)
        TNT1 A 0 A_Jump(256, "ReadyLoop")

    Zoom: //Actually grenade
        TNT1 A 0 A_JumpIfInventory("GrenadeAmmo", 1, 1)
        Goto NoGrenade
        GRTH ABCD 1
        TNT1 A 0 A_PlaySound("weapons/grenade/pin")
        GRTH EEFG 1
        TNT1 A 0 A_PlaySound("weapons/grenade/toss")
        GRTH HI 1
        TNT1 A 0 A_TakeInventory("GrenadeAmmo", 1)
        TNT1 A 0 A_FireCustomMissile("BdGrenade", random(-2,2), 0, 0, 0, 0, 0)
        GRTH JKLM 1
        TNT1 A 1 
        TNT1 A 0 A_Jump(256, "Ready")

    NoGrenade:
        TNT1 A 0 A_Print("No Grenades Left")
        TNT1 A 0 A_Jump(256, "ReadyLoop")
    }
}

Actor Chainsword : BLoodAngelWeapon  //The weapon that uses the new function
{
    Game Doom
	inventory.icon CSAWA0
    Weapon.SelectionOrder 220
    Weapon.Kickback 100
    Obituary "%o was shreded by the holy chainsword %k"
    Weapon.SlotNumber 1
    Weapon.SlotPriority 1
    Inventory.PickupMessage "$GOTCHAINSWORD"
    Inventory.PickupSound "SILENT"
    +WEAPON.MELEEWEAPON
    +WEAPON.NOALERT
    +WEAPON.NOAUTOAIM
    +WEAPON.NOAUTOFIRE
	Inventory.ForbiddenTo BlackTemplar, UltraMarine, BloodHound, GreyKnight
   //Omiting the States for simplicity sake
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Checking monsters health for a weapon

Post by Player701 »

Yes you can, as long as you're not doing it the other way around, i.e. inheriting ZScript classes from DECORATE classes. That won't work because DECORATE is parsed after ZScript.
User avatar
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Checking monsters health for a weapon

Post by nekostuffing »

Player701 wrote: Thu Aug 25, 2022 11:41 pm Yes you can, as long as you're not doing it the other way around, i.e. inheriting ZScript classes from DECORATE classes. That won't work because DECORATE is parsed after ZScript.
Thanks, i tested it out and it seems to be working fine, just wanted to be sure, so i wouldn't be getting errors latter on.
Post Reply

Return to “Scripting”