diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 45459311..0875975c 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -4135,6 +4135,12 @@ function allocate_mario_action(actFlags) -- ... end +--- @param index integer +--- @return number +function get_environment_region(index) + -- ... +end + --- @param m MarioState --- @param index integer --- @return number @@ -4171,6 +4177,13 @@ function hud_show() -- ... end +--- @param index integer +--- @param value integer +--- @return nil +function set_environment_region(index, value) + -- ... +end + --- @param aDelay integer --- @return boolean function warp_exit_level(aDelay) diff --git a/docs/lua/examples/Instant_Clip.lua b/docs/lua/examples/instant-clip.lua similarity index 85% rename from docs/lua/examples/Instant_Clip.lua rename to docs/lua/examples/instant-clip.lua index 1a735362..d578fcad 100644 --- a/docs/lua/examples/Instant_Clip.lua +++ b/docs/lua/examples/instant-clip.lua @@ -1,12 +1,12 @@ --- name: Instant Clip --- description: Press L trigger, profit! - -function mario_update(m) - if (m.controller.buttonDown & L_TRIG) ~= 0 then -- If L pressed - set_mario_action(m, ACT_WALKING, 0) --set mario to walking so his vel is used - m.forwardVel = 400 --set Velocity to clip speed - end -end - --- hooks -- +-- name: Instant Clip +-- description: Press L trigger, profit! + +function mario_update(m) + if (m.controller.buttonDown & L_TRIG) ~= 0 then -- If L pressed + set_mario_action(m, ACT_WALKING, 0) --set mario to walking so his vel is used + m.forwardVel = 400 --set Velocity to clip speed + end +end + +-- hooks -- hook_event(HOOK_MARIO_UPDATE, mario_update) \ No newline at end of file diff --git a/docs/lua/examples/water-level.lua b/docs/lua/examples/water-level.lua new file mode 100644 index 00000000..6a221bb9 --- /dev/null +++ b/docs/lua/examples/water-level.lua @@ -0,0 +1,28 @@ +-- name: Water Height Changer +-- description: Use /waterset and /waterget to manipulate water height. + +function on_get_command(msg) + if not network_is_server() then + djui_chat_message_create("You need to be the host!") + return true + end + + djui_chat_message_create(tostring(get_environment_region(1))) + djui_chat_message_create(tostring(get_environment_region(2))) + return false +end + +function on_set_command(msg) + if not network_is_server() then + djui_chat_message_create("You need to be the host!") + return true + end + + local num = tonumber(msg) + set_environment_region(1, num) + set_environment_region(2, num) + return false +end + +hook_chat_command("waterset", "to set the first two water levels", on_set_command) +hook_chat_command("waterget", "to get the first two water levels", on_get_command) \ No newline at end of file diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 2e827466..36ae0ca7 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -727,12 +727,14 @@ - smlua_misc_utils.h - [allocate_mario_action](#allocate_mario_action) + - [get_environment_region](#get_environment_region) - [get_hand_foot_pos_x](#get_hand_foot_pos_x) - [get_hand_foot_pos_y](#get_hand_foot_pos_y) - [get_hand_foot_pos_z](#get_hand_foot_pos_z) - [get_network_area_timer](#get_network_area_timer) - [hud_hide](#hud_hide) - [hud_show](#hud_show) + - [set_environment_region](#set_environment_region) - [warp_exit_level](#warp_exit_level) - [warp_restart_level](#warp_restart_level) - [warp_to_castle](#warp_to_castle) @@ -13658,6 +13660,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [get_environment_region](#get_environment_region) + +### Lua Example +`local numberValue = get_environment_region(index)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | + +### Returns +- `number` + +### C Prototype +`f32 get_environment_region(u8 index);` + +[:arrow_up_small:](#) + +
+ ## [get_hand_foot_pos_x](#get_hand_foot_pos_x) ### Lua Example @@ -13775,6 +13797,27 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [set_environment_region](#set_environment_region) + +### Lua Example +`set_environment_region(index, value)` + +### Parameters +| Field | Type | +| ----- | ---- | +| index | `integer` | +| value | `integer` | + +### Returns +- None + +### C Prototype +`void set_environment_region(u8 index, s32 value);` + +[:arrow_up_small:](#) + +
+ ## [warp_exit_level](#warp_exit_level) ### Lua Example diff --git a/docs/lua/lua.md b/docs/lua/lua.md index ebd30980..aad3a0e3 100644 --- a/docs/lua/lua.md +++ b/docs/lua/lua.md @@ -54,8 +54,9 @@ All of this is a holdover from when there were only two players. It was a reason - [Custom Surface Collisions](examples/big-paddle) - [Custom Box Model](examples/custom-box-model) - [Custom Player Model](examples/koopa-player-model) -- [Moonjump](examples/Moonjump.lua) -- [Instant Clip](examples/Instant_Clip.lua) +- [Moonjump](examples/moonjump.lua) +- [Instant Clip](examples/instant-clip.lua) +- [Water Height Changer](examples/water-level.lua) ## Example Lua mods (large) - [Extended Moveset](../../mods/extended-moveset.lua) diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5d1e6702..e0f73c66 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -9200,6 +9200,17 @@ int smlua_func_allocate_mario_action(lua_State* L) { return 1; } +int smlua_func_get_environment_region(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + u8 index = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { return 0; } + + lua_pushnumber(L, get_environment_region(index)); + + return 1; +} + int smlua_func_get_hand_foot_pos_x(lua_State* L) { if(!smlua_functions_valid_param_count(L, 2)) { return 0; } @@ -9266,6 +9277,19 @@ int smlua_func_hud_show(UNUSED lua_State* L) { return 1; } +int smlua_func_set_environment_region(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 2)) { return 0; } + + u8 index = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { return 0; } + s32 value = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { return 0; } + + set_environment_region(index, value); + + return 1; +} + int smlua_func_warp_exit_level(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } @@ -10703,12 +10727,14 @@ void smlua_bind_functions_autogen(void) { // smlua_misc_utils.h smlua_bind_function(L, "allocate_mario_action", smlua_func_allocate_mario_action); + smlua_bind_function(L, "get_environment_region", smlua_func_get_environment_region); smlua_bind_function(L, "get_hand_foot_pos_x", smlua_func_get_hand_foot_pos_x); smlua_bind_function(L, "get_hand_foot_pos_y", smlua_func_get_hand_foot_pos_y); smlua_bind_function(L, "get_hand_foot_pos_z", smlua_func_get_hand_foot_pos_z); smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer); smlua_bind_function(L, "hud_hide", smlua_func_hud_hide); smlua_bind_function(L, "hud_show", smlua_func_hud_show); + smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region); smlua_bind_function(L, "warp_exit_level", smlua_func_warp_exit_level); smlua_bind_function(L, "warp_restart_level", smlua_func_warp_restart_level); smlua_bind_function(L, "warp_to_castle", smlua_func_warp_to_castle); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index 462fb922..12dd8941 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -7,6 +7,8 @@ #include "smlua_misc_utils.h" #include "pc/debuglog.h" +#include "game/object_list_processor.h" + u32 get_network_area_timer(void) { return gNetworkAreaTimer; } @@ -54,3 +56,16 @@ f32 get_hand_foot_pos_z(struct MarioState* m, u8 index) { if (index >= 4) { index = 0; } return m->marioBodyState->handFootPos[index][2]; } + +f32 get_environment_region(u8 index) { + if (gEnvironmentRegions != NULL && index <= gEnvironmentRegions[0]) { + return gEnvironmentRegions[6 * (int)index]; + } + return -11000; +} + +void set_environment_region(u8 index, s32 value) { + if (gEnvironmentRegions != NULL && index <= gEnvironmentRegions[0]) { + gEnvironmentRegions[6 * (int)index] = value; + } +} \ No newline at end of file diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index a44064f1..2698eee0 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -17,4 +17,7 @@ f32 get_hand_foot_pos_x(struct MarioState* m, u8 index); f32 get_hand_foot_pos_y(struct MarioState* m, u8 index); f32 get_hand_foot_pos_z(struct MarioState* m, u8 index); +f32 get_environment_region(u8 index); +void set_environment_region(u8 index, s32 value); + #endif