diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index b60b668c..1dcefd88 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -8594,6 +8594,13 @@ function obj_count_objects_with_behavior_id(behaviorId) -- ... end +--- @param o Object +--- @param index integer +--- @return Object +function obj_get_collided_object(o, index) + -- ... +end + --- @param objList ObjectList --- @return Object function obj_get_first(objList) diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md index 30a9790b..787b3de6 100644 --- a/docs/lua/functions-5.md +++ b/docs/lua/functions-5.md @@ -116,6 +116,27 @@
+## [obj_get_collided_object](#obj_get_collided_object) + +### Lua Example +`local ObjectValue = obj_get_collided_object(o, index)` + +### Parameters +| Field | Type | +| ----- | ---- | +| o | [Object](structs.md#Object) | +| index | `integer` | + +### Returns +[Object](structs.md#Object) + +### C Prototype +`struct Object *obj_get_collided_object(struct Object *o, s16 index);` + +[:arrow_up_small:](#) + +
+ ## [obj_get_first](#obj_get_first) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 67bad391..61f57a46 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1601,6 +1601,7 @@ - [obj_check_hitbox_overlap](functions-5.md#obj_check_hitbox_overlap) - [obj_check_overlap_with_hitbox_params](functions-5.md#obj_check_overlap_with_hitbox_params) - [obj_count_objects_with_behavior_id](functions-5.md#obj_count_objects_with_behavior_id) + - [obj_get_collided_object](functions-5.md#obj_get_collided_object) - [obj_get_first](functions-5.md#obj_get_first) - [obj_get_first_with_behavior_id](functions-5.md#obj_get_first_with_behavior_id) - [obj_get_first_with_behavior_id_and_field_f32](functions-5.md#obj_get_first_with_behavior_id_and_field_f32) diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 998949af..a77695cc 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -27912,6 +27912,25 @@ int smlua_func_obj_count_objects_with_behavior_id(lua_State* L) { return 1; } +int smlua_func_obj_get_collided_object(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 2) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "obj_get_collided_object", 2, top); + return 0; + } + + struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "obj_get_collided_object"); return 0; } + s16 index = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "obj_get_collided_object"); return 0; } + + smlua_push_object(L, LOT_OBJECT, obj_get_collided_object(o, index)); + + return 1; +} + int smlua_func_obj_get_first(lua_State* L) { if (L == NULL) { return 0; } @@ -30798,6 +30817,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "obj_check_hitbox_overlap", smlua_func_obj_check_hitbox_overlap); smlua_bind_function(L, "obj_check_overlap_with_hitbox_params", smlua_func_obj_check_overlap_with_hitbox_params); smlua_bind_function(L, "obj_count_objects_with_behavior_id", smlua_func_obj_count_objects_with_behavior_id); + smlua_bind_function(L, "obj_get_collided_object", smlua_func_obj_get_collided_object); smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first); smlua_bind_function(L, "obj_get_first_with_behavior_id", smlua_func_obj_get_first_with_behavior_id); smlua_bind_function(L, "obj_get_first_with_behavior_id_and_field_f32", smlua_func_obj_get_first_with_behavior_id_and_field_f32); diff --git a/src/pc/lua/utils/smlua_obj_utils.c b/src/pc/lua/utils/smlua_obj_utils.c index 1ac6956e..175681fe 100644 --- a/src/pc/lua/utils/smlua_obj_utils.c +++ b/src/pc/lua/utils/smlua_obj_utils.c @@ -244,6 +244,13 @@ struct Object *obj_get_next_with_same_behavior_id_and_field_f32(struct Object *o return NULL; } +struct Object *obj_get_collided_object(struct Object *o, s16 index) { + if (o && o->numCollidedObjs != 0 && o->numCollidedObjs > index) { + return o->collidedObjs[index]; + } + return NULL; +} + struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId) { static struct SpawnParticlesInfo sTmpSpi = { 0 }; memset(&sTmpSpi, 0, sizeof(struct SpawnParticlesInfo)); diff --git a/src/pc/lua/utils/smlua_obj_utils.h b/src/pc/lua/utils/smlua_obj_utils.h index 6fc395cd..48b0963f 100644 --- a/src/pc/lua/utils/smlua_obj_utils.h +++ b/src/pc/lua/utils/smlua_obj_utils.h @@ -32,6 +32,8 @@ struct Object *obj_get_nearest_object_with_behavior_id(struct Object *o, enum Be s32 obj_count_objects_with_behavior_id(enum BehaviorId behaviorId); +struct Object *obj_get_collided_object(struct Object *o, s16 index); + // misc obj helpers struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId);