diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 3ba796772..6923bedc1 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -10125,6 +10125,12 @@ function smlua_audio_utils_replace_sequence(sequenceId, bankId, defaultVolume, m
-- ...
end
+--- @return integer
+--- Allocates a new sequence ID
+function smlua_audio_utils_allocate_sequence()
+ -- ...
+end
+
--- @param filename string
--- @return ModAudio
--- Loads an `audio` stream by `filename` (with extension)
diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md
index de205a965..91856c2a2 100644
--- a/docs/lua/functions-6.md
+++ b/docs/lua/functions-6.md
@@ -5612,6 +5612,27 @@ Replaces the sequence corresponding to `sequenceId` with one called `m64Name`.m6
+## [smlua_audio_utils_allocate_sequence](#smlua_audio_utils_allocate_sequence)
+
+### Description
+Allocates a new sequence ID
+
+### Lua Example
+`local integerValue = smlua_audio_utils_allocate_sequence()`
+
+### Parameters
+- None
+
+### Returns
+- `integer`
+
+### C Prototype
+`u8 smlua_audio_utils_allocate_sequence(void);`
+
+[:arrow_up_small:](#)
+
+
+
## [audio_stream_load](#audio_stream_load)
### Description
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 9fe4cc414..4db8abe77 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1815,6 +1815,7 @@
- smlua_audio_utils.h
- [smlua_audio_utils_reset_all](functions-6.md#smlua_audio_utils_reset_all)
- [smlua_audio_utils_replace_sequence](functions-6.md#smlua_audio_utils_replace_sequence)
+ - [smlua_audio_utils_allocate_sequence](functions-6.md#smlua_audio_utils_allocate_sequence)
- [audio_stream_load](functions-6.md#audio_stream_load)
- [audio_stream_destroy](functions-6.md#audio_stream_destroy)
- [audio_stream_play](functions-6.md#audio_stream_play)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index a76b089fb..dfc274daa 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -30609,6 +30609,21 @@ int smlua_func_smlua_audio_utils_replace_sequence(lua_State* L) {
return 1;
}
+int smlua_func_smlua_audio_utils_allocate_sequence(UNUSED lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 0) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "smlua_audio_utils_allocate_sequence", 0, top);
+ return 0;
+ }
+
+
+ lua_pushinteger(L, smlua_audio_utils_allocate_sequence());
+
+ return 1;
+}
+
int smlua_func_audio_stream_load(lua_State* L) {
if (L == NULL) { return 0; }
@@ -38409,6 +38424,7 @@ void smlua_bind_functions_autogen(void) {
// smlua_audio_utils.h
smlua_bind_function(L, "smlua_audio_utils_reset_all", smlua_func_smlua_audio_utils_reset_all);
smlua_bind_function(L, "smlua_audio_utils_replace_sequence", smlua_func_smlua_audio_utils_replace_sequence);
+ smlua_bind_function(L, "smlua_audio_utils_allocate_sequence", smlua_func_smlua_audio_utils_allocate_sequence);
smlua_bind_function(L, "audio_stream_load", smlua_func_audio_stream_load);
smlua_bind_function(L, "audio_stream_destroy", smlua_func_audio_stream_destroy);
smlua_bind_function(L, "audio_stream_play", smlua_func_audio_stream_play);
diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c
index 03d0fa60c..1c39df56d 100644
--- a/src/pc/lua/utils/smlua_audio_utils.c
+++ b/src/pc/lua/utils/smlua_audio_utils.c
@@ -170,6 +170,16 @@ void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolu
LOG_LUA_LINE("Could not find m64 at path: %s", m64path);
}
+u8 smlua_audio_utils_allocate_sequence(void) {
+ for (u8 seqId = SEQ_COUNT + 1; seqId < MAX_AUDIO_OVERRIDE; seqId++) {
+ if (!sAudioOverrides[seqId].enabled) {
+ return seqId;
+ }
+ }
+ LOG_ERROR("Cannot allocate more custom sequences.");
+ return 0;
+}
+
///////////////
// mod audio //
///////////////
diff --git a/src/pc/lua/utils/smlua_audio_utils.h b/src/pc/lua/utils/smlua_audio_utils.h
index deca8b0d0..93696c80d 100644
--- a/src/pc/lua/utils/smlua_audio_utils.h
+++ b/src/pc/lua/utils/smlua_audio_utils.h
@@ -8,6 +8,8 @@ void smlua_audio_utils_reset_all(void);
bool smlua_audio_utils_override(u8 sequenceId, s32* bankId, void** seqData);
/* |description|Replaces the sequence corresponding to `sequenceId` with one called `m64Name`.m64 with `bankId` and `defaultVolume`|descriptionEnd| */
void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolume, const char* m64Name);
+/* |description|Allocates a new sequence ID|descriptionEnd| */
+u8 smlua_audio_utils_allocate_sequence(void);
////////////////
// mod sounds //