Classes:Key
Note: Wait! Stop! Before you copy this actor's definition into your mod, remember the following things:
|
Key | |||
---|---|---|---|
Actor type | Internal | Game | (ZDoom) |
DoomEd Number | None | Class Name | Key |
Classes: Inventory→Key
→DoomKey
→HereticKey
→HexenKey
→StrifeKey
Keys are items that are used to open locked doors. The base class Key is never used directly; it serves as the base class for predefined items (like Doom's Red Keycard) or for custom keys items defined in ZScript or DECORATE.
Contents
Use in ZScript and DECORATE
Keys use some of the basic Inventory properties but it is impossible to carry more than one of each key at any time. Therefore the amount property has no effect.
If the Species property is set to an existing key, the new key will function as a duplicate for the other key, opening the same locks work locks in the same way as the old one. For example, setting the key's species to RedCard will allow it to open locks as if it were a red keycard.
The Key class doesn't define any custom properties outside of thise defined in Inventory. If you want to define entirely new keys, you must use the LOCKDEFS lump to assign them to locks.
Methods
Non-static
The Key class uses the same non-static methods as the Inventory class.
Static
- static native clearscope bool IsLockDefined(int locknum)
- Returns true if the specified number matches an existing lock.
- static native clearscope Color GetMapColorForLock(int locknum)
- Returns the color that would be used on the automap to draw the color for the specified lock number.
- Could be used to draw some kind of a custom element, for example in a ZScript HUD.
- static native clearscope Color GetMapColorForKey(Key key)
- Returns the color that would be used on the automap for the specified key.
- Could be used to draw some kind of a custom element, for example in a ZScript HUD.
- static native clearscope int GetKeyTypeCount()
- Returns the total number of valid keys defined for the current game. For example, for vanilla Doom will return 6 (because there are 3 keycars, 3 skull keys).
- static native clearscope class<Key> GetKeyType(int index)
- Returns a pointer to a Key class in an index. The index is a position in an internal list, where the total size of the list can be obtained with
GetKeyTypeCount
Examples
This defines a new key. Note, it'll only function if a lock is defined for it in LOCKDEFS:
class SilverKey : Key
{
Default
{
Inventory.PickupMessage "Picked up the silver key.";
Inventory.Icon "SLVKA0";
}
States
{
Spawn:
SLVK A -1;
stop;
}
}
Defines a new key that functions the same was as RedCard:
class GoldKey : Key
{
Default
{
Inventory.PickupMessage "Picked up the gold key.";
Inventory.Icon "GLDKA0";
Species "RedCard";
}
States
{
Spawn:
GLDK A -1;
stop;
}
}
This is an example of how keys could be draw in a ZScript HUD in a vertial line at the top right corner of the screen:
void DrawAllKeys()
{
vector2 pos = (0,0);
double iconSize = 8;
int totalKeys = Key.GetKeyTypeCount();
for (int i = 0; i < totalKeys; i++)
{
Key k = Key(CPlayer.mo.FindInventory(Key.GetKeyType(i)));
if (k)
{
DrawInventoryIcon(k, pos, DI_SCREEN_RIGHT_TOP|DI_ITEM_RIGHT_TOP, boxsize:(iconSize, iconSize));
pos.y += iconsize;
}
}
}
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 Key : Inventory
{
Default
{
+DONTGIB; // Don't disappear due to a crusher
Inventory.InterHubAmount 0;
Inventory.PickupSound "misc/k_pkup";
}
static native clearscope bool IsLockDefined(int locknum);
static native clearscope Color GetMapColorForLock(int locknum);
static native clearscope Color GetMapColorForKey(Key key);
static native clearscope int GetKeyTypeCount();
static native clearscope class<Key> GetKeyType(int index);
override bool HandlePickup (Inventory item)
{
// In single player, you can pick up an infinite number of keys
// even though you can only hold one of each.
if (multiplayer)
{
return Super.HandlePickup (item);
}
if (GetClass() == item.GetClass())
{
item.bPickupGood = true;
return true;
}
return false;
}
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 Key : Inventory native { +DONTGIB +INVENTORY.INTERHUBSTRIP Inventory.PickupSound "misc/k_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