Point of this doom port is not to stay compatible or emulate original game accurately. Lua scripts in kgdoom.wad for original games do not reflect 100% original game behavior and are provided only for basic compatibility.
To install on Switch, you currently have to use HBL. Copy kgdoom.nro and kgdoom.wad to /switch/kgdoom/ on your SD card. Also copy any IWADs you have to this directory. If you want to run PWAD mods, create directory /switch/kgdoom/pwads/ and copy these there. When you start kgdoom, you will see WAD menu where you can pick IWAD, and optionally PWAD.
This manual documents kgDoom Lua game API. I assume you already know how to make doom maps / mods and know Lua scripting. Hexen map formap is recommended. Doom map format is present only for compatibility reasons.
These are terms used in Lua API.
- mobj
- Map object. Anything sprite-based in map. Items, monsters, players ...
- Default properties and animations are defined by mobjtype.
- mobjtype
- This is a template for mobj. When spawning mobjs, you refer to this type.
- This defines all animations and default properties.
- player
- This is a special mobj section that is only present for players.
- Players have few extra properties that other mobjs do not have.
- sector
- This allows access to map sectors.
- line
- This allows access to map lines and sides.
- genericPlane
- This is a generic plane (floor / ceiling) movement handler.
- This is bound to a sector.
- genericCaller
- This is a generic caller. It calls specified Lua callback periodically.
- This is bound to a sector.
- Used for example for light effects.
- textureScroll
- This is used to add texture scroll effect to lines.
Lua scirpts are stored in WADs. There is only one recognized lump name: GAMELUA. You can have as many GAMELUA lumps in multiple wads.
Lua scripts are loaded from first wad to last and from first lump to last one. This should allow for overrides (game mods).
First line in each GAMELUA can specify internal script name. Example: ---test.lua
. Every time Lua has to report error, it will use test.lua
as a script name.
There are two stages. Loading stage and map stage. Every stage has its own set of global functions.
This is stage when all GAMELUA scripts are loaded and executed. At this point you should create all mobjtypes, register player class, weapons and keys. You can not do these later. Contents of GAMELUA ouside of any functions is executed at this stage.
This is stage when level is already loaded and everything in map is spawned. Only callbacks and action functions are called.
The is a weird bug(?) in Lua itself. If you make a syntax error, you will get attempt to call a string value
error, which is not helpful at all.
- Every mobj can have its own inventory and armor.
- Inventory item can be any mobjtype that has maxcount other than zero.
- When count reaches zero, item is removed from inventory.
- Negative maxcount is undepletable and will be kept even if count reaches zero. Used for ammo sice HUD expects ammo to exist even when depleted.
- angles
- Angles are specified in range 0 - 8191. This is a whole circle.
- fixed
- Any fixed point values can use decimal point in Lua.
- function
createMobjType(table)
- Table should contain everything required to describe mobj type.
- See Lua scripts in kgdoom.wad file.
- See mobjtype section for list of properties.
- Returns newly created mobjtype.
- function
setPlayerType(mobjtype)
- This function regiters primary player type.
- There is only one player type requred, multiple calls will only redefine default player type.
- function
addWeaponType(mobjtype [, mobjtype [, mobjtype])
- This function expects weapon type as mobjtype and optionally one or two ammo types as mobjtype.
- Every weapon that should be listed in weapon menu must be registered using this weapon.
- If you want to have secret / scriptable weapons, you do not have to register them.
- function
addKeyType(mobjtype)
- This fucntion registers key as mobjtype. This registration is only for display in HUD.
- function
doomRandom()
- This will return a prandom number from 0 to 255. It uses original doom random table.
- function
doomRandom(max)
- This will return a prandom number from 0 to max, including 0 and max. Only whole numbers are supported.
- function
doomRandom(min, max)
- This will return a prandom number from min to max, including min and max. Only whole numbers are supported.
- function
spawnMobj(mobjtype, x, y [, z [, angle [, action]]])
- Spawn new mobj at x and y and optionally z. Uses fixed point numbers.
- Spawn angle can be specified.
- If action is
true
, first frame action is executed. Enabled by default. - Returns spawned mobj.
- function
blockThingsIterator(test_mobj, func [, arg])
- Calls a callback
func
with optional argumentarg
for every mobj found inside radius oftest_mobj
. - Argument
arg
is user specified, and can be anything. It will be passed to callback function. - Callback should be function defined as
somecb(thing)
orsomecb(thing, arg)
. - If callback returns
false
, iteration will stop and any other return values will get returned byblockThingsIterator
itself. - Beware: no z height checks are computed, you have to do this yourself it you need it.
- Calls a callback
- function
blockThingsIterator(x, y, func [, arg])
- Same as above, but with single point specified by fixed point x and y.
- function
blockThingsIterator(x, y, xe, ye, func [, arg])
- Same as above, but with manualy specified range. Also uses fixed points.
- function
globalPlayersIterator(func [, arg])
- Calls a callback
func
with optional argumentarg
for every player in level. - Callback should be function defined as
somecb(player)
orsomecb(player, arg)
. - Return logic is same as in
blockThingsIterator
.
- Calls a callback
- function
globalThingsIterator(func [, arg])
- Calls a callback
func
with optional argumentarg
for every mobj in level. - Callback should be function defined as
somecb(thing)
orsomecb(thing, arg)
. - Return logic is same as in
blockThingsIterator
.
- Calls a callback
- function
thingTagIterator(func [, arg])
- same as
globalThingsIterator
but with automatic TID filter.
- same as
- function
globalSectorsIterator(func [, arg])
- Calls a callback
func
with optional argumentarg
for every sector in level. - Callback should be function defined as
somecb(sector)
orsomecb(sector, arg)
. - Return logic is same as in
blockThingsIterator
.
- Calls a callback
- function
sectorTagIterator(tag, func [, arg])
- Same as
globalSectorsIterator
but with automatic sector tag filter.
- Same as
- function
globalLinesIterator(func [, arg])
- Calls a callback
func
with optional argumentarg
for every line in level. - Callback should be function defined as
somecb(line)
orsomecb(line, arg)
. - Return logic is same as in
blockThingsIterator
.
- Calls a callback
- function
fakeContrast(enable)
- Set
false
to enable fake contrast in level. - Doom uses fake contrast on walls, so it is enabled by default.
- Set
- function
setBackground(patchlump)
- This function will set screen background to this gfx from any WAD.
- Use of this function is not recommendes as specified image will only show trough holes in map (= bad map).
- It is only used for Doom2 finale emulation.
There are few animations that every mobjtype can have. Only spawn state has meaning for all of them, as it is state it gets set to on level load.
Other animations depend on flag combinations. Unused states can be used in any way you wish.
Animations are always specified as _animName
_spawn
- Basic animation for all mobjs.
_see
- Set by internal
a.Look
when mobj has target to go after.
- Set by internal
_pain
- Used on
__shootable
mobjs. This state is set when mobj is damaged, but with chance specified bypainChance
.
- Used on
_melee
- Set by internal
a.Chase
when mobj is close enough to do melee damage to its target.
- Set by internal
_missile
- Randomly set by internal
a.Chase
. Used to attack from distance.
- Randomly set by internal
_death
- Used on
__shootable
mobjs. This state is set when mobj is damaged and resulting health is less or equal to 0.
- Used on
_xdeath
- Used on
__shootable
mobjs. This state is set when mobj is damaged and resulting health is less than negative default health (overkill).
- Used on
_raise
- Not used by engine logic.
- Used in Doom Lua scripts by Archvile to raise dead bodies.
_crush
- Used when there is not enough space in changing sector for this mobj and
__dropped
or__corpse
is set.
- Used when there is not enough space in changing sector for this mobj and
_heal
- Not used by engine logic.
- Used in Doom Lua scripts by Archvile itself to heal dead bodies.
_wRaise
- Weapon state. Used when raising selected weapon.
_wReady
- Weapon state. Used when holding weapon, waiting for fire.
_wLower
- Weapon state. Used when lowering weapon.
_wFireMain
- Weapon state. Used when firing using main attack.
_wFireAlt
- Weapon state. Used when firing using alternate attack.
_wFlashMain
- Weapon state. Added on top of normal animation if internal
a.WeaponFlash
is called.
- Weapon state. Added on top of normal animation if internal
_wFlashAlt
- Weapon state. Added on top of normal animation if internal
a.WeaponFlash
is called.
- Weapon state. Added on top of normal animation if internal
Mobj flags are boolean values that affect mobj behavior. Flags are always specified as __flagName
.
__special
- Used for item pickup. Any mobj with
__pickup
enabled colliding with this one will call callbackaction
. - Callback should be function defined as
somecb(mobj, spec)
orsomecb(mobj, spec, arg)
.- mobj is colliding thing (one with
__pickup
flag) andspec
is this thing.
- mobj is colliding thing (one with
- Used for item pickup. Any mobj with
__solid
- This mobj is considered solid and can be collided agains.
__shootable
- This mobj can be damaged and is expected to have
health
andpainChance
set.
- This mobj can be damaged and is expected to have
__noSector
- This mobj is not in sector links. This affects rendering. If enabled, this mobj will be invisible.
__noBlockmap
- This mobj is non in block links. This affects physics. Nothing can collide with this mobj. Usefull for GFX effects.
- Projectiles use this. In Doom, nothing coolides with projectiles, but projectiles collide with other mobjs.
__ambush
- Used by internal
a.Look
. - Monsters with this flag won't react to
a.NoiseAlert
but wait for direct line of sight (even from behind) to wake up.
- Used by internal
__spawnCeiling
- Used by some Doom decorations. Items with this flag will be spanwed on celing, but only at map loading.
__noGravity
- This mobj won't fall down due to gravity.
__dropOff
- This mobj can fall of tall edges.
__pickup
- This mobj can 'pickup' items. See
__special
.
- This mobj can 'pickup' items. See
__noClip
- This mobj has collision checks disabled.
__slide
- This mobj will slide along walls / other mobjs.
__float
- Used for internal
a.Chase
as a hit that this monster is flying.
- Used for internal
__missile
- Used for projectiles. This mobj has special collision check logic. Any collision would cause its death. And eventual damage to collided mobj.
__dropped
- Used as a marker for dropped items. Engine either deletes this mobj, or sets state to
_crush
when there is not enough space in changing sector for this mobj. - Doom logic (Lua scripts) also use this flag to give half ammo from items dropped by monsters.
- Used as a marker for dropped items. Engine either deletes this mobj, or sets state to
__noblood
- Bullet puffs on this mobj are spawned as is instead of having state set to
_pain
.
- Bullet puffs on this mobj are spawned as is instead of having state set to
__corpse
- This flag is automatically set on things with
__shootable
flag set when killed (health <= 0). - Engine uses this flag set
_crush
state in changing sector when there is no room for this mobj.
- This flag is automatically set on things with
__countKill
- This mobj is counted as killable for level end screen.
__countItem
- This mobj is counted as pickable for level end screen.
__notInDeathmatch
- This mobj will not get spawned in deathmatch. Only affects map loading.
__isMonster
- This mobj is marked as monster. This is purely informative, to be used for any checks you need.
__noRadiusDamage
- This mobj is immune to
RadiusDamage
.
- This mobj is immune to
__noRadiusDmgZ
- This mobj can be damaged by
RadiusDamage
at any Z distance. Only X and Y distance is checked.
- This mobj can be damaged by
__skullFly
- This mobj will damage anything it will collide with. Then it will be stopped, and its state will be set to
_spawn
. - Used on Doom lost souls.
- This mobj will damage anything it will collide with. Then it will be stopped, and its state will be set to
__noZChange
- This mobj has 3D thing collision disabled.
- Internaly set when
__missile
explodes.
__troughMobj
- This mobj can't collide with other mobjs, and other mobjs can't collide with it.
- Only level geometry collision is enabled.
__fullVolume
- This mobj has is's body sounds at full volume.
- Used on bosses in Doom.
__noDeathPull
- There is a chance that death body will fall towards you instead of getting pushed by damage. This flag will disable it.
__invulnerable
- This mobj can't be hurt.
- Used by invunlerability sphere in doom.
__wallBounce
- Used on projectiles. Projectile will bounce off walls.
__mobjBounce
- Used on projectiles. Projectile will bounce off other mobjs and do no damage to them.
__Monster
- Flag combination of
__isMonster
,__countKill
,__solid
and__shootable
- Flag combination of
__Projectile
- Flag combination of
__missile
,__noBlockmap
,__noGravity
,__dropOff
and__noZChange
- Flag combination of
Mobjtype can contain these parameters. Default 0 / none, unless specified otherwise.
ednum
- Doom editor number. This is ID for map editor.
- Integer.
health
- Default health. Used on
__shootable
items. - Integer.
- Default health. Used on
reactionTime
- Default monster reacion time. See mobj.
- Integer.
painChance
- Used on
__shootable
items. Chance to set_pain
animation, where 0 is 0% and 256 is 100% - Integer.
- Used on
speed
- Speed for projectile spawning, or internal
a.Chase
movement code. - Fixed point.
- Speed for projectile spawning, or internal
radius
- Mobj size - radius.
- Fixed point.
height
- Mobj size - height.
- Fixed point.
mass
- Mobj mass. Used on
__shootable
items when taking damage. - Can be used for any push strength calculation.
- Integer.
- Mobj mass. Used on
damage
- Used on projectiles, or when
__skullFly
is set. - Integer.
- Used on projectiles, or when
gravity
- Gravity multiplier. Default is 1.
- Fixed point.
bounce
- Bounce multiplier. If greater than 0, mobj can bounce of celings / floors.
- Eeach bounce momentnum is inverted and multiplied by this value.
- Fixed point.
viewz
- Rendering height offset when viewing trough this mobj.
- Fixed point.
shootz
- Shooting height offset. Used for
SpawnMissile
andLineAttack
- Fixed point.
- Shooting height offset. Used for
bobz
- Only usefull for player classes. Amount of screen bouncing while walking.
- Fixed point.
stepheight
- Maximal height difference this mobj can step up.
- Fixed point, default 24.
species
- If other than 0, this mobj is added into specified species cathegory.
- Same species can't hurt each other with projectiles. (Example: Imps won't hurt other imps, baron won't hurt knight.)
- Integer.
block
- Blocking flags for this mobj. Only used when
__solid
is set. - This is a bit mask of blocking flags. This allows for custom blocking configuration.
- Integer, 16 bit only. Default 0xFFFF (block everything).
- Blocking flags for this mobj. Only used when
pass
- See blocking. If specified bit is set, this mobj won't be blocked by other mobjs, lines or 3D floors with same
block
bit set as it normally would. - Integer, 16 bit only.
- See blocking. If specified bit is set, this mobj won't be blocked by other mobjs, lines or 3D floors with same
icon
- Icon to be used for this mobj. Usage depends on mobj type, or can be used for custom Lua scripts.
addWeaponType
expects this to be set to valid icon. If not found or invalid, this weapon won't be listed in selection menu.addKeyType
expects this to be set to valid icon. If not found or invalid, this key won't be listed in HUD even when picked up.- String. Patch type lump in any of loaded WADs.
maxcount
- Max count if used as inventory item.
- Integer.
translation
- Custom translation table. If specified, all colors will be tranlsated trough this table when rendering sprites of this mobj. Used on colored blood.
- Translation table is 256 bytes long. Lump itself can be bigger and offset can be specified. Example:
BLOODMAP:1
.BLOODMAP
is same asBLOODMAP:0
. - String.
render
- Render style. For now there are only few supported internal styles.
!NORMAL
no effects.!SHADOW
original doom invisibility fuzz effect.!HOLEY0
every pixel is skipped.!HOLEY1
every pixel is skipped, alternative version.- String.
action
- For now only used with
__special
flag. - Function or nil.
- For now only used with
arg
- Argument for
action
. - Anything Lua type.
- Argument for
action_crash
- Function to call when mobj hits floor (falls down). Callback should be defined as
somecb(thing)
. Used on player for fall down sound effect. - Function or nil.
- Function to call when mobj hits floor (falls down). Callback should be defined as
seeSound
- Played by internal
a.Look
when target is found. - String. Sound lump from any WAD.
- Played by internal
attackSound
- Played by internal
a.Chase
when melee attacking. - String. Sound lump from any WAD.
- Played by internal
painSound
- Not used by engine. Supposed to be used in
_pain
animation. - String. Sound lump from any WAD.
- Not used by engine. Supposed to be used in
activeSound
- Randomly player by internal
a.Chase
. - Played by player when pressing
use
key without anything to activate. - String. Sound lump from any WAD.
- Randomly player by internal
deathSound
- Not used by engine. Supposed to be used in
_death
animation. - String. Sound lump from any WAD.
- Not used by engine. Supposed to be used in
xdeathSound
- Not used by engine. Supposed to be used in
_xdeath
animation. - String. Sound lump from any WAD.
- Not used by engine. Supposed to be used in
bounceSound
- Played when thing is about to bounce. Used for
bounce
,__wallBounce
and__mobjBounce
. - String. Sound lump from any WAD.
- Played when thing is about to bounce. Used for
damageScale
- Table of damage scalers.
- Table of Fixed point numbers. Range from -2.7 to 9.0 with 0.05 steps. Or
true
for instant kill.