Skip to content

Commit

Permalink
New native added mm_force_change_map
Browse files Browse the repository at this point in the history
  • Loading branch information
FEDERICOMB96 committed Jul 28, 2023
1 parent c4d798b commit 275f9f4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
7 changes: 4 additions & 3 deletions addons/amxmodx/scripting/include/mm_incs/defines.inc
Expand Up @@ -6,8 +6,8 @@
#define PLUGIN_NAME "MultiMod Manager"

#define MM_VERSION_MAJOR 1
#define MM_VERSION_MINOR 1
#define MM_VERSION_PATCH 1
#define MM_VERSION_MINOR 2
#define MM_VERSION_PATCH 0

#define PLUGIN_VERSION fmt("v%d.%d.%d", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_PATCH)

Expand Down Expand Up @@ -65,7 +65,8 @@ enum
TASK_RTV,
TASK_SHOWTIME,
TASK_ENDMAP,
TASK_VOTE_ADMIN
TASK_VOTE_ADMIN,
TASK_FORCE_CHANGE_MAP,
};

const KEYSMENU = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<9);
Expand Down
53 changes: 53 additions & 0 deletions addons/amxmodx/scripting/include/mm_incs/natives.inc
Expand Up @@ -164,4 +164,57 @@ public bool:_mm_force_votemod(plugin_id, argc)
}

return false;
}

/**
* Force a map change.
*
* @param iModId Mod index.
* @param szMap Map to change to.
* @param flChangeTime Time to wait before changing map.
* 0.0 to change map immediately.
*
* @return (bool) true on success, false otherwise.
*
* native bool:mm_force_change_map(const iModId, const sMap[], const Float:flChangeTime = 0.0);
*/
public _mm_force_change_map(plugin_id, argc)
{
enum _:args_e { arg_modid = 1, arg_map, arg_changetime };

if(argc != (args_e-1))
{
abort(AMX_ERR_NATIVE, "'mm_force_change_map' needs %d param(s) (count: %d)", (args_e-1), argc);
return false;
}

new iModId = get_param(arg_modid);

if(iModId < 0 || iModId >= ArraySize(g_GlobalConfigs[Mods]))
{
abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId);
return false;
}

new szMap[MAX_MAPNAME_LENGTH];
get_string(arg_map, szMap, charsmax(szMap));

if(!IsValidMap(szMap) || !IsValidMapForMod(iModId, szMap))
{
abort(AMX_ERR_NATIVE, "Invalid map name (%s)", szMap);
return false;
}

new Float:flChangeTime = floatmax(0.0, get_param_f(arg_changetime));

if(flChangeTime)
{
remove_task(TASK_FORCE_CHANGE_MAP);
set_task(flChangeTime, "OnTask_ForceChangeMap", TASK_FORCE_CHANGE_MAP);

return true;
}

OnCSGameRules_GoToIntermission();
return true;
}
16 changes: 14 additions & 2 deletions addons/amxmodx/scripting/include/multimod_manager_natives.inc
Expand Up @@ -8,8 +8,8 @@
* Do not modify this!
*/
#define MM_VERSION_MAJOR 1
#define MM_VERSION_MINOR 1
#define MM_VERSION_PATCH 1
#define MM_VERSION_MINOR 2
#define MM_VERSION_PATCH 0

/* ===========================================================================
* [ MULTIMOD MANAGER NATIVES ]
Expand Down Expand Up @@ -81,6 +81,18 @@ native mm_get_nextmod_name(szOutput[], const iLen);
*/
native bool:mm_force_votemod();

/**
* Force a map change.
*
* @param iModId Mod index.
* @param szMap Map to change to.
* @param flChangeTime Time to wait before changing map.
* 0.0 to change map immediately.
*
* @return (bool) true on success, false otherwise.
*/
native bool:mm_force_change_map(const iModId, const sMap[], const Float:flChangeTime = 0.0);

/* ===========================================================================
* [ MULTIMOD MANAGER FORWARDS ]
* ============================================================================ */
Expand Down
12 changes: 9 additions & 3 deletions addons/amxmodx/scripting/multimod_manager.sma
Expand Up @@ -24,6 +24,7 @@ public plugin_natives()
register_native("mm_get_nextmod_id", "_mm_get_nextmod_id");
register_native("mm_get_nextmod_name", "_mm_get_nextmod_name");
register_native("mm_force_votemod", "_mm_force_votemod");
register_native("mm_force_change_map", "_mm_force_change_map");
}

public plugin_precache()
Expand Down Expand Up @@ -310,7 +311,7 @@ MultiMod_Init()
return;
}

if(bReloadMod || !IsValidMapForMod(g_iCurrentMod))
if(bReloadMod || !IsValidMapForMod(g_iCurrentMod, g_szCurrentMap))
{
g_iNextSelectMod = bReloadMod ? 0 : g_iCurrentMod; // 0 = First mod as default
MultiMod_SetNextMod(g_iNextSelectMod);
Expand Down Expand Up @@ -850,7 +851,7 @@ MultiMod_SetGameDescription(const iMod)
return 0;
}

bool:IsValidMapForMod(const iModId)
bool:IsValidMapForMod(const iModId, const szMapName[MAX_MAPNAME_LENGTH])
{
if(iModId < 0 || iModId > ArraySize(g_GlobalConfigs[Mods]))
return false;
Expand All @@ -863,7 +864,7 @@ bool:IsValidMapForMod(const iModId)
{
ArrayGetString(aMod[Maps], i, szMap, charsmax(szMap));

if(equali(g_szCurrentMap, szMap))
if(equali(szMapName, szMap))
return true;
}

Expand Down Expand Up @@ -914,4 +915,9 @@ GetRandomMapForMod(const iModId, szMap[], const iLen)
}

return 0;
}

public OnTask_ForceChangeMap()
{
OnCSGameRules_GoToIntermission();
}

0 comments on commit 275f9f4

Please sign in to comment.