Lua/Freeslots and Object resources

From SRB2 Wiki
< Lua
Jump to navigation Jump to 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_), secondary sprites (SPR2_), sounds (sfx_), skin colors (SKINCOLOR_), and level types (TOL_).

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,
    caption = "New sound"
}
  • Shorthand version:
S_sfx[sfx_newsnd] = {
	false,
	255,
	0,
    "New sound"
}
  • Formatted in a single line:
S_sfx[sfx_newsnd] = {false, 255, 0, "New sound"}

singular will default to false, priority and flags will default to 0, and caption will default to the sound's name (e.g. for the sound sfx_newsnd, the default caption would be newsnd). 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.

Custom skincolors

  • Longhand version:
skincolors[SKINCOLOR_CUSTOMCOLOR] = {
	name = "Custom Color",
	ramp = {0,130,133,134,149,149,150,150,167,168,168,169,253,254,30,31},
	invcolor = SKINCOLOR_FLAME,
    invshade = 7,
    chatcolor = V_BLUEMAP,
    accessible = true
}
  • Shorthand version:
skincolors[SKINCOLOR_CUSTOMCOLOR] = {
	"Custom Color",
	{0,130,133,134,149,149,150,150,167,168,168,169,253,254,30,31},
	SKINCOLOR_FLAME,
    7,
    V_BLUEMAP,
    true
}

name will default to an empty string, ramp will default to all 0 (bright white), invcolor, invshade, and chatcolor will all default to 0, and accessible will default to false.

  Lua [view]
Language features SyntaxMetatables
SRB2 data ActionsConstantsFunctionsGlobal variablesHooksUserdata structures
SRB2Kart data Kart Userdata structuresKart FunctionsKart HooksKart Global Variables and Constants
Tutorials Freeslots and Object resourcesCustom player ability