mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-12-22 16:30:23 +00:00
Allow other mods to add levels to arena
This commit is contained in:
parent
dc63c6588f
commit
929b10995c
14 changed files with 75 additions and 18 deletions
|
@ -74,6 +74,12 @@ function hook_chat_command(command, description, func)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param command string
|
||||
--- @param description string
|
||||
function update_chat_command_description(command, description)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param hookEventType LuaHookedEventType
|
||||
--- @param func function
|
||||
function hook_event(hookEventType, func)
|
||||
|
|
|
@ -181,6 +181,15 @@ void *DynOS_Lvl_Override(void *aCmd) {
|
|||
gLevelScriptActive = (LevelScript*)aCmd;
|
||||
}
|
||||
}
|
||||
|
||||
auto& _CustomLevelScripts = DynOS_Lvl_GetArray();
|
||||
for (auto& script : _CustomLevelScripts) {
|
||||
if (aCmd == script.second->mLevelScripts[0]->mData) {
|
||||
gLevelScriptModIndex = script.second->mModIndex;
|
||||
gLevelScriptActive = (LevelScript*)aCmd;
|
||||
}
|
||||
}
|
||||
|
||||
return aCmd;
|
||||
}
|
||||
|
||||
|
|
BIN
mods/arena/levels/level_arena_forts_entry.lvl
Normal file
BIN
mods/arena/levels/level_arena_forts_entry.lvl
Normal file
Binary file not shown.
BIN
mods/arena/levels/level_arena_origin_entry.lvl
Normal file
BIN
mods/arena/levels/level_arena_origin_entry.lvl
Normal file
Binary file not shown.
BIN
mods/arena/levels/level_arena_pillars_entry.lvl
Normal file
BIN
mods/arena/levels/level_arena_pillars_entry.lvl
Normal file
Binary file not shown.
BIN
mods/arena/levels/level_arena_platforms_entry.lvl
Normal file
BIN
mods/arena/levels/level_arena_platforms_entry.lvl
Normal file
Binary file not shown.
BIN
mods/arena/levels/level_arena_sky_beach_entry.lvl
Normal file
BIN
mods/arena/levels/level_arena_sky_beach_entry.lvl
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -23,19 +23,27 @@ gGameModes = {
|
|||
[GAME_MODE_TKOTH] = { shortName = 'TKOTH', name = 'Team King of the Hill', teams = true, teamSpawns = false, useScore = true, scoreCap = 90, minPlayers = 4, maxPlayers = 99 },
|
||||
}
|
||||
|
||||
gGameLevels = {
|
||||
{ level = LEVEL_BOB, name = 'Origin' },
|
||||
{ level = LEVEL_CCM, name = 'Sky Beach' },
|
||||
{ level = LEVEL_WF, name = 'Pillars' },
|
||||
{ level = LEVEL_JRB, name = 'Forts' },
|
||||
{ level = LEVEL_DDD, name = 'Platforms' },
|
||||
LEVEL_ARENA_ORIGIN = level_register('level_arena_origin_entry', COURSE_NONE, 'Origin', 'origin', 28000, 0x28, 0x28, 0x28)
|
||||
LEVEL_ARENA_SKY_BEACH = level_register('level_arena_sky_beach_entry', COURSE_NONE, 'Sky Beach', 'beach', 28000, 0x28, 0x28, 0x28)
|
||||
LEVEL_ARENA_PILLARS = level_register('level_arena_pillars_entry', COURSE_NONE, 'Pillars', 'pillars', 28000, 0x28, 0x28, 0x28)
|
||||
LEVEL_ARENA_FORTS = level_register('level_arena_forts_entry', COURSE_NONE, 'Forts', 'forts', 28000, 0x28, 0x28, 0x28)
|
||||
LEVEL_ARENA_PLATFORMS = level_register('level_arena_platforms_entry', COURSE_NONE, 'Platforms', 'platforms', 28000, 0x28, 0x28, 0x28)
|
||||
|
||||
local gGameLevels = {
|
||||
{ level = LEVEL_ARENA_ORIGIN, name = 'Origin' },
|
||||
{ level = LEVEL_ARENA_SKY_BEACH, name = 'Sky Beach' },
|
||||
{ level = LEVEL_ARENA_PILLARS, name = 'Pillars' },
|
||||
{ level = LEVEL_ARENA_FORTS, name = 'Forts' },
|
||||
{ level = LEVEL_ARENA_PLATFORMS, name = 'Platforms' },
|
||||
}
|
||||
|
||||
smlua_text_utils_course_acts_replace(COURSE_BOB, " 1 Origin", "?", "?", "?", "?", "?", "?")
|
||||
smlua_text_utils_course_acts_replace(COURSE_CCM, " 4 Sky Beach", "?", "?", "?", "?", "?", "?")
|
||||
smlua_text_utils_course_acts_replace(COURSE_WF, " 2 Pillars", "?", "?", "?", "?", "?", "?")
|
||||
smlua_text_utils_course_acts_replace(COURSE_JRB, " 3 Forts", "?", "?", "?", "?", "?", "?")
|
||||
smlua_text_utils_course_acts_replace(COURSE_DDD, " 4 Platforms", "?", "?", "?", "?", "?", "?")
|
||||
-- expose certain functions to other mods
|
||||
_G.Arena = {
|
||||
add_level = function (levelNum, levelName)
|
||||
table.insert(gGameLevels, { level = levelNum, name = levelName })
|
||||
update_chat_command_description('arena-level', string.format('[%s] sets level', get_level_choices()))
|
||||
end
|
||||
}
|
||||
|
||||
-- setup global sync table
|
||||
gGlobalSyncTable.gameState = GAME_STATE_ACTIVE
|
||||
|
@ -466,7 +474,6 @@ function on_gamemode_command(msg)
|
|||
end
|
||||
|
||||
function on_level_command(msg)
|
||||
|
||||
local setLevel = nil
|
||||
|
||||
for i, gl in ipairs(gGameLevels) do
|
||||
|
@ -498,15 +505,18 @@ for i, gm in ipairs(gGameModes) do
|
|||
sGameModeShortTimes = sGameModeShortTimes .. gm.shortName
|
||||
end
|
||||
|
||||
sLevelChoices = ''
|
||||
for i, gl in ipairs(gGameLevels) do
|
||||
if string.len(sLevelChoices) > 0 then
|
||||
sLevelChoices = sLevelChoices .. '|'
|
||||
function get_level_choices()
|
||||
local levelChoices = ''
|
||||
for i, gl in ipairs(gGameLevels) do
|
||||
if string.len(levelChoices) > 0 then
|
||||
levelChoices = levelChoices .. '|'
|
||||
end
|
||||
levelChoices = levelChoices .. gl.name
|
||||
end
|
||||
sLevelChoices = sLevelChoices .. gl.name
|
||||
return levelChoices
|
||||
end
|
||||
|
||||
if network_is_server() then
|
||||
hook_chat_command('arena-gamemode', string.format("[%s|random] sets gamemode", sGameModeShortTimes), on_gamemode_command)
|
||||
hook_chat_command('arena-level', string.format('[%s] sets level', sLevelChoices), on_level_command)
|
||||
hook_chat_command('arena-level', string.format('[%s] sets level', get_level_choices()), on_level_command)
|
||||
end
|
||||
|
|
|
@ -1277,6 +1277,37 @@ int smlua_hook_chat_command(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_update_chat_command_description(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
if (!smlua_functions_valid_param_count(L, 2)) { return 0; }
|
||||
|
||||
const char* command = smlua_to_string(L, 1);
|
||||
if (command == NULL || strlen(command) == 0 || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA_LINE("Update chat command: tried to update invalid command");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* description = smlua_to_string(L, 2);
|
||||
if (description == NULL || strlen(description) == 0 || !gSmLuaConvertSuccess) {
|
||||
LOG_LUA_LINE("Update chat command: tried to update invalid description");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sHookedChatCommandsCount; i++) {
|
||||
struct LuaHookedChatCommand* hook = &sHookedChatCommands[i];
|
||||
if (!strcmp(hook->command, command)) {
|
||||
if (hook->description) {
|
||||
free(hook->description);
|
||||
}
|
||||
hook->description = strdup(description);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_LUA_LINE("Update chat command: could not find command to update");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool smlua_call_chat_command_hook(char* command) {
|
||||
lua_State* L = gLuaState;
|
||||
if (L == NULL) { return false; }
|
||||
|
@ -1470,4 +1501,5 @@ void smlua_bind_hooks(void) {
|
|||
smlua_bind_function(L, "hook_chat_command", smlua_hook_chat_command);
|
||||
smlua_bind_function(L, "hook_on_sync_table_change", smlua_hook_on_sync_table_change);
|
||||
smlua_bind_function(L, "hook_behavior", smlua_hook_behavior);
|
||||
smlua_bind_function(L, "update_chat_command_description", smlua_update_chat_command_description);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue