Auto-use item when the player died

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.

Auto-use item when the player died

Postby Laskow » Tue Feb 16, 2021 10:15 am

Hello.
I'm making an inventory item that will be activated automatically when the player dies then give 100 health to him. It's just like The Mystic Urn that cannot use manually.
However I'm facing a few problems.

1: Uses HealthPickup

The player can activate the item anytime :( Somehow HealthPickup.AutoUse doesn't work when added sound frags like Inventory.UseSound. And it seems that there are no way to show the messages so it's hard to notice when the item was activated.
Spoiler:



2: Make the item as Inventory and use with ACS

The player cannot activate manually as I want. But he has not been resurrected!
Spoiler:


I tried to set the state to Spawn from ACS but the game was crashed so probably I cannot change the state after he died.


It will not be too difficult if it's able to use ConsoleCommand in GZDoom though, anyway, is possible to add this item?
DECORATE and ACS are welcome, not very good at using ZScript.

Thanks!
User avatar
Laskow
 
Joined: 16 Feb 2021

Re: Auto-use item when the player died

Postby Jarewill » Tue Feb 16, 2021 11:27 am

It seems Thing_Raise does not work on players apparently, so I don't think ACS has a way of reviving players.

It's possible in ZScript though:
Spoiler:
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Auto-use item when the player died

Postby Player701 » Tue Feb 16, 2021 11:55 am

Laskow wrote:Somehow HealthPickup.AutoUse doesn't work when added sound frags like Inventory.UseSound.

The problem is, the way health auto-use is implemented is rather hacky. The items don't actually get used - instead, the game reads the amount of health they would give and decrements their amounts, possibly destroying them entirely in case an item's amount reaches zero. The resulting health value is then used to heal up the player before they'd take damage. This is why the item's use sound doesn't play.

Also note that whether health items get auto-used depends on skill settings, so it's not a good idea to employ the auto-use mechanism in this particular case. (This does not apply to auto-use mode 3, which corresponds to Strife health items, but those activate regardless of whether or not the player would die, which is also not what the OP wanted, I guess.)

Jarewill wrote:
Code: Select allExpand view
owner.A_StartSound("Misc/Item01"); //Play sound

Perhaps it'd be better to play the sound on CHAN_ITEM because that is the channel the use sound is normally played on?
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Auto-use item when the player died

Postby Laskow » Tue Feb 16, 2021 11:35 pm

Jarewill's code
Code: Select allExpand view
version "3.0" //Important
//You can't give editor numbers to classes in ZScript like in DECORATE, refer to https://zdoom.org/wiki/MAPINFO/Editor_number_definition instead.
Class Talisman : Inventory
{
    Default
    {
        +INVENTORY.UNDROPPABLE;
        +INVENTORY.INVBAR;
        Inventory.PickupMessage "Picked up Talisman";
        Tag "TAG_TALIS";
        Inventory.Icon "TLSMA0";
    }
    Override void DoEffect()
    {
        Super.DoEffect();
        If(owner&&owner.health<1) //If player is dead
        {
            owner.player.Resurrect(); //Resurrect the player
            owner.GiveBody(-100); //Heal them to full health
            owner.A_StartSound("Misc/Item01"); //Play sound
            owner.A_Print("Talisman protected you"); //Print out message
            Destroy(); //Take away the item
        }
    }
    States
    {
    Spawn:
        TLSM A -1;
        Stop;
    }
}


It works and this is what I want!

Player701 wrote:
The problem is, the way health auto-use is implemented is rather hacky. The items don't actually get used - instead, the game reads the amount of health they would give and decrements their amounts, possibly destroying them entirely in case an item's amount reaches zero. The resulting health value is then used to heal up the player before they'd take damage. This is why the item's use sound doesn't play.

I was surprised that the auto-use mechanism is complicated than I expected. And whether I make the auto-use item or not in a future, I won't use this method...


Thank you everyone!
User avatar
Laskow
 
Joined: 16 Feb 2021


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest