Lua/Freeslots and Object resources

From SRB2 Wiki
< Lua
Jump to: navigation, search

This tutorial explains how to declare names for freeslots and define whole infotable entries for resources using Lua.

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 only be done with mobjinfo[], states[] and S_sfx[] (or sfxinfo[]).

Custom Object types

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
}

Not all of the parameters for the longhand version are necessarily needed (doomednum defaults to -1, spawnhealth defaults to 1, everything else defaults to 0). However, for the shorthand version none should be missed out. In general the longhand version is favoured of the two.

Custom states

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, not all of the parameters for the longhand version of states are necessarily needed (tics defaults to -1, everything else defaults to 0). Shorthand version is generally favoured despite this (for no action to be used in the state, use "nil" in place of an action name).

Custom sounds

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 "name" and "skinsound" of sfxinfo_t are read-only, so cannot be set by this.

  Lua [view]
General BasicsFunctionsGlobal variablesHooksUserdata structures
Tutorials Freeslots and Object resourcesCustom player ability