sm64coopdx/docs/lua/functions.md
PeachyPeach 69e129805e
More math improvements (#820)
* More math improvements

* more math functions

* stack check

* added error message when trying to modify read-only table; fix gSmluaConstants printed to console
2025-05-29 02:52:31 +02:00

147 KiB

Lua Reference


1 | 2 | 3 | 4 | 5 | 6 | next >]


Supported Functions























































  • smlua_deprecated.h













manually written functions

define_custom_obj_fields

Defines a custom set of overlapping object fields.

The fieldTable table's keys must start with the letter o and the values must be either u32, s32, or f32.

Lua Example

define_custom_obj_fields({ oCustomField1 = 'u32', oCustomField2 = 's32', oCustomField3 = 'f32' })

Parameters

Field Type
fieldTable Lua Table

C Prototype

N/A

🔼

network_init_object

Enables synchronization on an object.

  • Setting standardSync to true will automatically synchronize the object at a rate that is determined based on player distance. The commonly used object fields will be automatically synchronized.
  • Setting standardSync to false will not automatically synchronize the object, or add commonly used object fields. The mod must manually call network_send_object() when fields have changed.

The fieldTable parameter can be nil, or a list of object fields.

Lua Example

network_init_object(obj, true, { 'oCustomField1', 'oCustomField2', 'oCustomField3' })

Parameters

Field Type
object Object
standardSync bool
fieldTable Lua Table

C Prototype

N/A

🔼


network_send_object

Sends a packet that synchronizes an object. This does not need to be called when standardSync is enabled.

The reliable field will ensure that the packet arrives, but should be used sparingly and only when missing a packet would cause a desync.

Lua Example

network_send_object(obj, false)

Parameters

Field Type
object Object
reliable bool

C Prototype

N/A

🔼


network_send_to

Sends a packet to a particular player (using their local index) containing whatever data you want.

dataTable can only contain strings, integers, numbers, booleans, and nil

The reliable field will ensure that the packet arrives, but should be used sparingly and only when missing a packet would cause a desync.

Lua Example

network_send_to(localPlayerIndex, reliable, { data1 = 'hello', data2 = 10})

Parameters

Field Type
localPlayerIndex integer
reliable bool
dataTable table

C Prototype

N/A

🔼


network_send

Sends a packet to all players containing whatever data you want.

dataTable can only contain strings, integers, numbers, booleans, and nil

The reliable field will ensure that the packet arrives, but should be used sparingly and only when missing a packet would cause a desync.

Lua Example

network_send(reliable, { data1 = 'hello', data2 = 10})

Parameters

Field Type
reliable bool
dataTable table

C Prototype

N/A

🔼


get_texture_info

Retrieves a texture by name.

Lua Example

get_texture_info(textureName)

Parameters

Field Type
textureName string

Returns

C Prototype

N/A

🔼


djui_hud_render_texture

Renders a texture to the screen.

Lua Example

djui_hud_render_texture(texInfo, 0, 0, 1, 1)

Parameters

Field Type
texInfo TextureInfo
x number
y number
scaleW number
scaleH number

Returns

  • None

C Prototype

void djui_hud_render_texture(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH);

🔼


djui_hud_render_texture_tile

Renders a tile of a texture to the screen.

Lua Example

djui_hud_render_texture_tile(texInfo, 0, 0, 1, 1, 0, 0, 16, 16)

Parameters

Field Type
texInfo TextureInfo
x number
y number
scaleW number
scaleH number
tileX number
tileY number
tileW number
tileH number

Returns

  • None

C Prototype

void djui_hud_render_texture_tile(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);

🔼


djui_hud_render_texture_tile_interpolated

Renders an interpolated tile of a texture to the screen.

Lua Example

djui_hud_render_texture_tile_interpolated(texInfo, prevX, prevY, prevScaleW, prevScaleH, 0, 0, 1, 1, 0, 0, 16, 16)

Parameters

Field Type
texInfo TextureInfo
prevX number
prevY number
prevScaleW number
prevScaleH number
x number
y number
scaleW number
scaleH number
tileX number
tileY number
tileW number
tileH number

Returns

  • None

C Prototype

void djui_hud_render_texture_tile_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);

🔼


texture_override_reset

Resets an overridden texture.

Lua Example

texture_override_reset("outside_09004000")

Parameters

Field Type
textureName string

Returns

  • None

C Prototype

void dynos_texture_override_reset(const char* textureName);

🔼


texture_override_set

Overrides a texture with a custom TextureInfo.

Lua Example

texture_override_set("outside_09004000", overrideTexInfo)

Parameters

Field Type
textureName string
overrideTexInfo TextureInfo

Returns

  • None

C Prototype

void dynos_texture_override_set(const char* textureName, struct TextureInfo* overrideTexInfo);

🔼


smlua_anim_util_register_animation

Register a new Lua animation.

Lua Example

smlua_anim_util_register_animation("apparition_idle", 0, 189, 0, 0, 0x5A, values, index)

Parameters

Field Type
name string
flags integer
animYTransDivisor integer
startFrame integer
loopStart integer
loopEnd integer
values table
index table

Returns

  • None

C Prototype

void smlua_anim_util_register_animation(const char *name, s16 flags, s16 animYTransDivisor, s16 startFrame, s16 loopStart, s16 loopEnd, s16 *values, u32 valuesLength, u16 *index, u32 indexLength);

🔼


level_script_parse

Lua Example

level_script_parse(LEVEL_BOB, func)

Parses a level script and passes area index, behavior data, macro behavior IDs and macro behavior arguments to a function.

Parameters

Field Type
levelNum LevelNum
func function

Returns

  • None

C Prototype

void smlua_func_level_script_parse(lua_State* L);

🔼


log_to_console

Logs a message to the in-game console.

Lua Example

log_to_console("sm64coopdx FTW", CONSOLE_MESSAGE_INFO)

Parameters

Field Type
message string
level (optional) ConsoleMessageLevel

Returns

  • None

C Prototype

void log_to_console(const char* message, enum ConsoleMessageLevel level);

🔼


add_scroll_target

Registers a vertex buffer to be used for a scrolling texture. Should be used with RM_Scroll_Texture or editor_Scroll_Texture

Lua Example

add_scroll_target(0, "arena_rainbow_dl_StarRoad_mesh_layer_5_vtx_0")

Parameters

Field Type
index integer
name string

Returns

  • None

C Prototype

void dynos_add_scroll_target(u32 index, const char *name, u32 offset, u32 size);

🔼


collision_find_surface_on_ray

Shoots a raycast from startX, startY, and startZ in the direction of dirX, dirY, and dirZ.

Lua Example

collision_find_surface_on_ray(0, 0, 0, 50, 100, 50)

Parameters

Field Type
startX number
startY number
startZ number
dirX number
dirY number
dirZ number
precision (optional) number

Returns

C Prototype

struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 precision);

🔼


set_exclamation_box_contents

Sets the contents that the exclamation box spawns. A single content has 5 keys: id, unused, firstByte, model, and behavior.

  • id: Required; what value the box's oBehParams2ndByte needs to be to spawn this object.
  • unused: Optional; unused by vanilla.
  • firstByte: Optional; Overrides the 1st byte given to the spawned object.
  • model: Required; The model that the object will spawn with. Uses ModelExtendedId.
  • behavior: Required; The behavior ID that the object will spawn with. Uses BehaviorId.

Lua Example

set_exclamation_box_contents({
   {id = 0, unused = 0, firstByte = 0, model = E_MODEL_GOOMBA, behavior = id_bhvGoomba}, -- Uses both optional fields
   {id = 1, unused = 0, model = E_MODEL_KOOPA_WITH_SHELL, behavior = id_bhvKoopa}, -- Only uses `unused` optional field
   {id = 2, firsteByte = model = E_MODEL_BLACK_BOBOMB, behavior = id_bhvBobomb}, -- Only uses `firstByte` optional field
   {id = 3, model = E_MODEL_BOO, behavior = id_bhvBoo}, -- Uses no optional fields
})

Parameters

There exists only 1 parameter to this function which is the main table. However, each subtable has 5 different keys that could be accessed.

Field Type
id integer
unused (Optional) integer
firstByte (Optional) integer
model ModelExtendedId
behavior BehaviorId

Returns

  • None

C Prototype

N/A

🔼


get_exclamation_box_contents

Gets the contents that the exclamation box spawns. A single content has 5 keys: id, unused, firstByte, model, and behavior.

  • id: Required; what value the box's oBehParams2ndByte needs to be to spawn this object.
  • unused: Optional; unused by vanilla.
  • firstByte: Optional; Overrides the 1st byte given to the spawned object.
  • model: Required; The model that the object will spawn with. Uses ModelExtendedId.
  • behavior: Required; The behavior ID that the object will spawn with. Uses BehaviorId.

Lua Example

local contents = get_exclamation_box_contents()
for index, content in pairs(contents) do -- Enter the main table
   djui_chat_message_create("Table index " .. index) -- Print the current table index
      for key, value in pairs(content) do
         djui_chat_message_create(key .. ": " .. value) -- Print a key-value pair within this subtable
      end
   djui_chat_message_create("---------------------------------") -- Separator
end

Parameters

  • N/A

Returns

The function itself does not return every key/value pair. Instead it returns the main table which holds all the subtables that hold each key/value pair.

Field Type
id integer
unused (Optional) integer
firstByte (Optional) integer
model ModelExtendedId
behavior BehaviorId

C Prototype

N/A

🔼


cast_graph_node

Returns the specific GraphNode(...) the node is part of. Basically the reverse of .node or .fnNode.

Lua Example

local marioGfx = gMarioStates[0].marioObj.header.gfx -- GraphNodeObject
local node = marioGfx.node -- GraphNode

print(marioGfx == cast_graph_node(node)) -- true

Parameters

Field Type
node GraphNode

Returns

  • GraphNode(...)

C Prototype

N/A

🔼


get_uncolored_string

Removes color codes from a string.

Lua Example

print(get_uncolored_string("\#210059\Colored \#FF086F\String")) -- "Colored String"

Parameters

Field Type
str 'string'

Returns

  • string

C Prototype

N/A

🔼


gfx_set_command

Sets a display list command on the display list given.

If command includes parameter specifiers (subsequences beginning with %), the additional arguments following command are converted and inserted in command replacing their respective specifiers.

The number of provided parameters must be equal to the number of specifiers in command, and the order of parameters must be the same as the specifiers.

The following specifiers are allowed:

  • %i for an integer parameter
  • %s for a string parameter
  • %v for a Vtx parameter
  • %t for a Texture parameter
  • %g for a Gfx parameter

Lua Examples

Plain string:

gfx_set_command(gfx, "gsDPSetEnvColor(0x00, 0xFF, 0x00, 0xFF)")

With parameter specifiers:

r, g, b, a = 0x00, 0xFF, 0x00, 0xFF
gfx_set_command(gfx, "gsDPSetEnvColor(%i, %i, %i, %i)", r, g, b, a)

Parameters

Field Type
gfx Gfx
command string
parameters... any of integer, string, Gfx, Texture, Vtx

Returns

  • None

C Prototype

N/A

🔼



functions from area.h


get_mario_spawn_type

Description

Derives a MARIO_SPAWN_* constant from o

Lua Example

local integerValue = get_mario_spawn_type(o)

Parameters

Field Type
o Object

Returns

  • integer

C Prototype

u32 get_mario_spawn_type(struct Object *o);

🔼


area_get_warp_node

Description

Finds a warp node in the current area by its ID. The warp node must exist in the list of warp nodes for the current area. Useful for locating a specific warp point in the level, such as teleportation zones or connections to other areas

Lua Example

local ObjectWarpNodeValue = area_get_warp_node(id)

Parameters

Field Type
id integer

Returns

ObjectWarpNode

C Prototype

struct ObjectWarpNode *area_get_warp_node(u8 id);

🔼


area_get_any_warp_node

Description

Gets the first warp node found in the area, otherwise returns nil

Lua Example

local ObjectWarpNodeValue = area_get_any_warp_node()

Parameters

  • None

Returns

ObjectWarpNode

C Prototype

struct ObjectWarpNode *area_get_any_warp_node(void);

🔼


area_get_warp_node_from_params

Description

Finds a warp node in the current area using parameters from the provided object. The object's behavior parameters are used to determine the warp node ID. Useful for associating an object (like a door or warp pipe) with its corresponding warp node in the area

Lua Example

local ObjectWarpNodeValue = area_get_warp_node_from_params(o)

Parameters

Field Type
o Object

Returns

ObjectWarpNode

C Prototype

struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o);

🔼


play_transition

Description

Plays a screen transition

Lua Example

play_transition(transType, time, red, green, blue)

Parameters

Field Type
transType integer
time integer
red integer
green integer
blue integer

Returns

  • None

C Prototype

void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue);

🔼


play_transition_after_delay

Description

Plays a screen transition after a delay in frames

Lua Example

play_transition_after_delay(transType, time, red, green, blue, delay)

Parameters

Field Type
transType integer
time integer
red integer
green integer
blue integer
delay integer

Returns

  • None

C Prototype

void play_transition_after_delay(s16 transType, s16 time, u8 red, u8 green, u8 blue, s16 delay);

🔼


---

1 | 2 | 3 | 4 | 5 | 6 | next >]