Replace Key (item) class while handling explicit inventory checks.

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!)
Vigil

Replace Key (item) class while handling explicit inventory checks.

Post by Vigil »

:!: Problem:

A map-pack contains a switch linedef that, when activated, explicitly checks the player's inventory for a Key item, say the RedCard, RedSkull, etc., via a script e.g. using:

if (CheckInventory("RedCard") == 1 )

A gameplay mod contains a class definition that is written to replace the key actor. e.g. using:

Actor NewRedCard : redcard replaces redcard
{
// definition and states
}

The explicit inventory check for a RedCard item fails, because RedCard is now replaced by NewRedCard.

:?: Solvable:

To enforce compatibility, **without editing the scripting in the map-pack and only editing that of the gameplay mod**, how can the replaced actor be granted the class or inventory "type" RedCard such that it is compatible with the explicit inventory check while also replacing the item encountered in game so that its new sprites are visible during play, only if this is possible? If it is not possible, why, and what can be done instead?

:idea: Motivation:

I have a real pretty keycard replacement here, but it ain't working with some map packs and I kind of want to fix that. The true reason, though, is that it's easier to fix this incompatibility in the offending mod than it is to trawl through every map I want to use it in and tweak it in Slade - which I'm not fully opposed to, but it would be a pain.
Explicitly, I am trying to fix a mod that I enjoy playing the game with so that it is more broadly compatible with the mappacks I enjoy playing - I would like to make it clear that I have no intention of reuploading the content of other users, this is for personal use.

:arrow: Present efforts:

I understand that a class can't be defined with an equal name to the class it means to replace (though I may be wrong about that, guidance on the wiki is not completely clear to me so far) and presently the only idea I have is to perhaps set some kind of flag or figure out how to implement some sort of "newclass : inheritanceClass replace inheritanceClass as inheritanceClass" or, on pickup, ALSO somehow give the player the "old" key, if it does indeed still exist (presuming that "replace" does not destroy the class definition during initialisation and simply replaces *spawned instances* of itself in-game. I have also encountered ( viewtopic.php?p=114504 ) and the links from that thread, but I can't see a direct confirmation that I can simply use "Actor Redcard : Redcard replaces Redcard" with the confidence that it will correctly inherit properties that are unchanged.
User avatar
Virathas
Posts: 223
Joined: Thu Aug 10, 2017 9:38 am

Re: Replace Key (item) class while handling explicit inventory checks.

Post by Virathas »

If ZScript is an option, there are several ways i can think of. One, that i believe is a little hacky, but also i think easiest, is to give player an inventory item, that "keeps watch" if the "NewRedCard" is in players inventory, and if it is, gives the RedCard.
This is pseudo code that could help you to go the right way.

Class KeyChecker : Inventory
{
override void Tick()
{
Super.Tick();
If (Owner.CheckInventory("NewRedCard",1) && !Owner.CheckInventory("RedCard",1))
{
Owner.GiveInventory("RedCard",1);
}
}
}

You can try to add this item, either with a cheat, if its for personal purpose, or you can grant it via start item of a custom player class or use an EventHandler for spawning.
Vigil

Re: Replace Key (item) class while handling explicit inventory checks.

Post by Vigil »

I'll give it a go, I've almost no experience with the ZScript language itself but I know a bit of general programming, how hard could it be? I would asssume that I would only need one KeyChecker class for all six keys (three cards, three skulls) if the handling is done every game tick. Results later.

Return to “Scripting”