sm64coopdx/docs/lua/functions.md
PeachyPeach 6726a6280a
Changes in level_info; play_transition; dev-only warp command; bug fix for moving sounds played via lua (#69)
Improved level_info.c and added functions to LUA:
        const char *get_level_name_ascii(s16 courseNum, s16 levelNum, s16 areaIndex, s16 charCase):
            Return a level name as an ascii string. If charCase is 1, capitalize all letters.
            If charCase is -1, decapitalize all letters except the first one of each word.
        const u8 *get_level_name_sm64(s16 courseNum, s16 levelNum, s16 areaIndex, s16 charCase):
            Return a level name as an sm64 u8 string.
            If charCase is 1, capitalize all letters.
            If charCase is -1, decapitalize all letters except the first one of each word.
        const char *get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex):
            Shortcut for get_level_name_ascii(courseNum, levelNum, areaIndex, -1).
        const char *get_star_name_ascii(s16 courseNum, s16 starNum, s16 charCase):
            Return a star name as an ascii string.
            If charCase is 1, capitalize all letters.
            If charCase is -1, decapitalize all letters except the first one of each word.
        const u8 *get_star_name_sm64(s16 courseNum, s16 starNum, s16 charCase):
            Return a star name as an sm64 u8 string.
            If charCase is 1, capitalize all letters.
            If charCase is -1, decapitalize all letters except the first one of each word.
        const char *get_star_name(s16 courseNum, s16 starNum):
            Shortcut for get_star_name_ascii(courseNum, starNum, -1).

    Added play_transition function to LUA.
        I chose to copy the function declaration to smlua_misc_utils.h instead of adding area.h
        to the autogen tool, as most structures, variables and functions in area.h aren't meant
        to be used by LUA scripts.

    Added a dev-only warp chat command.
        This command signature is /warp [LEVEL] [AREA] [ACT]. Level can be either a number
            or a shorthand name (bob, wf, ccm...). Area and Act are numbers.
        This command is available only when building the game with DEBUG and DEVELOPMENT.
        This command cannot be used if hosting through Discord.

    Fixed a bug with moving sounds when they are played via a lua script.
        Bug: Moving sounds (including terrain sounds, flying sound, quicksand sound)
            are not played correctly when a lua script play them via a call of
            play_sound or play_sound_with_freq_scale. This is due to how the moving
            sounds are handled internally. They use the f32 pointer provided to the
            play_sound functions to decide if the sound must be kept playing,
            stopped or restarted. Most of the time, the pointer provided is the
            cameraToObject field of Mario's object graph node. Since smlua uses a
            circular buffer for Vec3f conversion, this pointer is lost, and the
            sound engine can't decide what to do with the sound, resulting in a
            weird and incorrect sound effect.
        Fix: play_sound and play_sound_with_freq_scale now calls
            smlua_get_vec3f_for_play_sound before filling the sound request queue,
            to retrieve the correct pointer from the Vec3f provided by smlua.
2022-04-26 13:48:50 -07:00

95 KiB

Lua Reference


1 | 2 | 3 | 4 | next >]


Supported Functions









































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

🔼



1 | 2 | 3 | 4 | next >]