Lua/Freeslots and Object resources
This tutorial explains how to declare names for freeslots and define whole infotable entries for resources using Lua.
Contents
Declaring freeslot names
Names for new resources are declared in Lua using the freeslot()
function:
freeslot("MT_CUSTOMTYPE", "S_CUSTOMSTATE", "SPR_CUST", "sfx_newsnd")
This is limited to new Object types (MT_
), states (S_
), sprites (SPR_
) or sounds (sfx_
).
Line breaks can be used after commas to separate out the names of new resources, if many are being declared at once:
freeslot(
"MT_CUSTOMTYPE",
"S_CUSTOMSTATE",
"SPR_CUST",
"sfx_newsnd"
)
Defining infotables
This section covers creating whole infotable entries from scratch (as opposed to changing a single property, which doesn't affect the rest of the table). This can be done with mobjinfo[]
, states[]
and S_sfx[]
(or sfxinfo[]
).
Custom Object types
- Longhand version:
mobjinfo[MT_CUSTOMTYPE] = {
doomednum = 42,
spawnstate = S_CUSTOMSPAWN,
spawnhealth = 1,
seestate = S_CUSTOMSEE,
seesound = sfx_seesnd,
reactiontime = TICRATE,
attacksound = sfx_attack,
painstate = S_CUSTOMPAIN,
painchance = 0,
painsound = sfx_painnn,
meleestate = S_KARATE,
missilestate = S_SHMUP,
deathstate = S_DEFEATED,
xdeathstate = S_XDEATH,
deathsound = sfx_death,
speed = 10,
radius = 16*FRACUNIT,
height = 32*FRACUNIT,
dispoffset = 0,
mass = 100,
damage = 0,
activesound = sfx_None,
flags = MF_SPECIAL|MF_SHOOTABLE|MF_ENEMY|MF_RUNSPAWNFUNC,
raisestate = S_NULL
}
- Shorthand version:
mobjinfo[MT_CUSTOMTYPE] = {
42,
S_CUSTOMSPAWN,
1,
S_CUSTOMSEE,
sfx_seesnd,
TICRATE
sfx_attack
S_CUSTOMPAIN,
0,
sfx_painnn,
S_KARATE,
S_SHMUP,
S_DEFEATED,
S_XDEATH,
sfx_death,
10,
16*FRACUNIT,
32*FRACUNIT,
0,
100,
0,
sfx_None,
MF_SPECIAL|MF_SHOOTABLE|MF_ENEMY|MF_RUNSPAWNFUNC,
S_NULL
}
In the longhand version, parameters that are omitted will use a default value (doomednum
defaults to -1, spawnhealth
defaults to 1, everything else defaults to 0). In the shorthand version, no parameters may be omitted. In general, the longhand version is favored.
Custom states
- Longhand version:
states[S_CUSTOMSTATE] = {
sprite = SPR_CUST,
frame = 0,
tics = 35,
action = A_Look,
var1 = 0,
var2 = 0,
nextstate = S_NEXTSTATE
}
- Shorthand version:
states[S_CUSTOMSTATE] = {
SPR_CUST,
0,
35,
A_Look,
0,
0,
S_NEXTSTATE
}
- Formatted in a single line:
states[S_CUSTOMSTATE] = {SPR_CUST, 0, 35, A_Look, 0, 0, S_NEXTSTATE}
As with Object types, parameters that are omitted in the longhand version will use a default value (tics
defaults to -1, everything else defaults to 0). In the shorthand version, no parameters may be omitted. The shorthand version is generally favored. For no action to be used in the state, use nil
in place of an action name.
Custom sounds
- Longhand version:
S_sfx[sfx_newsnd] = {
singular = false,
priority = 255,
flags = 0
}
- Shorthand version:
S_sfx[sfx_newsnd] = {
false,
255,
0
}
- Formatted in a single line:
S_sfx[sfx_newsnd] = {false, 255, 0}
singular
will default to false, and priority
and flags
will default to 0. sfxinfo
works as an alternative name for S_sfx
. Note that the name
and skinsound
attributes of sfxinfo_t
are read-only and so cannot be set by this.
Lua | [view] | |
Language features | Syntax • Metatables | |
SRB2 data | Actions • Constants • Functions • Global variables • Hooks • Userdata structures | |
SRB2Kart data | Kart Userdata structures | |
Tutorials | Freeslots and Object resources • Custom player ability |