Classes:PuzzleItem
Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
|
Puzzle item | |||
---|---|---|---|
Actor type | Internal | Game | (ZDoom) |
DoomEd Number | None | Class Name | PuzzleItem |
Classes: Inventory→PuzzleItem
→PuzzBook1
→PuzzBook2
→PuzzCWeapon
→PuzzFlameMask
→PuzzFWeapon
→PuzzGear1
→PuzzGear2
→PuzzGear3
→PuzzGear4
→PuzzGemBig
→PuzzGemBlue1
→PuzzGemBlue2
→PuzzGemGreen1
→PuzzGemGreen2
→PuzzGemRed
→PuzzMWeapon
→PuzzSkull
PuzzleItem is a subclass of Inventory. Puzzle items don't have any functions themselves, but they can be combined with UsePuzzleItem map special to create "puzzle" locks that require multiple puzzle items to open. In principle, they act very similar to Key class items, but they are visible in the player's inventory bar rather than a dedicated key section, and and they have to be used from it manually, by pressing the "use item" keybind. Also, in contrast to keys, puzzle items are removed after use.
Using in ZScript and DECORATE
PuzzleItems uses the basic Inventory properties, plus a few properties unique to this class:
- PuzzleItem.Number value
- Defines the number that has to be used with UsePuzzleItem to identify the item.
- PuzzleItem.FailMessage string
- Message to be displayed when this item is used and not the one requested by UsePuzzleItem.
- PuzzleItem.FailSound sound
- Sound to be played when the item is used, but is not the one requested by UsePuzzleItem. Default is the player class specific *puzzfail sound.
Examples
This is an example of a custom PuzzleItem:
class PigHead : PuzzleItem { Default { PuzzleItem.Number 17; Inventory.PickupMessage "A Pig's head"; // This is an example. It's recommended to use LANGUAGE for player-facing strings. Inventory.DefMaxAmount; Inventory.Icon "PIGHEAD"; } States { Spawn: PHED A -1; stop; } }
ZScript definition
Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub. |
class PuzzleItem : Inventory
{
meta int PuzzleItemNumber;
meta String PuzzFailMessage;
meta Sound PuzzFailSound;
property Number: PuzzleItemNumber;
property FailMessage: PuzzFailMessage;
property FailSound: PuzzFailSound;
Default
{
+NOGRAVITY
+INVENTORY.INVBAR
+INVENTORY.ISKEYITEM
Inventory.DefMaxAmount;
Inventory.UseSound "PuzzleSuccess";
Inventory.PickupSound "misc/i_pkup";
PuzzleItem.FailMessage("$TXT_USEPUZZLEFAILED");
PuzzleItem.FailSound "*puzzfail";
}
override bool HandlePickup (Inventory item)
{
// Can't carry more than 1 of each puzzle item in coop netplay
if (multiplayer && !deathmatch && item.GetClass() == GetClass())
{
return true;
}
return Super.HandlePickup (item);
}
override bool Use (bool pickup)
{
if (Owner == NULL) return false;
if (Owner.UsePuzzleItem (PuzzleItemNumber))
{
return true;
}
// [RH] Always play the sound if the use fails.
Owner.A_StartSound (PuzzFailSound, CHAN_VOICE);
if (Owner.CheckLocalView())
{
Console.MidPrint (null, PuzzFailMessage, true);
}
return false;
}
override void UseAll(Actor user)
{
}
override bool ShouldStay ()
{
return !!multiplayer;
}
}
DECORATE definition
Note: This is legacy code, kept for archival purposes only. DECORATE is deprecated in GZDoom and is completely superseded by ZScript. GZDoom internally uses the ZScript definition above. |
ACTOR PuzzleItem : Inventory native { +NOGRAVITY +INVENTORY.INVBAR Inventory.DefMaxAmount Inventory.UseSound "PuzzleSuccess" Inventory.PickupSound "misc/i_pkup" }
- Chex Quest actors
- Chex Quest internal actors
- Chex Quest 3 actors
- Chex Quest 3 internal actors
- Doom actors
- Doom internal actors
- Doom II actors
- Doom II internal actors
- Heretic actors
- Heretic internal actors
- Hexen actors
- Hexen internal actors
- Strife actors
- Strife internal actors
- ZDoom actors
- ZDoom internal actors
- Internal