Skip to content

Commit

Permalink
API: Added new API natives (5)
Browse files Browse the repository at this point in the history
Added `mm_get_mod_enabled`
Added `mm_get_mod_changemap_type`
Added `mm_get_mod_maps`
Added `mm_get_mod_cvars`
Added `mm_get_mod_plugins`
  • Loading branch information
FEDERICOMB96 committed Jul 31, 2023
1 parent e5bd122 commit a5a87e2
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 3 deletions.
2 changes: 1 addition & 1 deletion addons/amxmodx/scripting/include/mm_incs/defines.inc
Expand Up @@ -6,7 +6,7 @@
#define PLUGIN_NAME "MultiMod Manager"

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

#define PLUGIN_VERSION fmt("v%d.%d.%d", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_PATCH)
Expand Down
173 changes: 173 additions & 0 deletions addons/amxmodx/scripting/include/mm_incs/natives.inc
Expand Up @@ -19,6 +19,39 @@ public _mm_get_mods_count(plugin_id, argc)
return ArraySize(g_GlobalConfigs[Mods]);
}

/**
* Return if the mod is enabled or not.
*
* @param iModId Mod index.
*
* @return (bool) true if the mod is enabled, false otherwise.
*
* native bool:mm_get_mod_enabled(const iModId);
*/
public bool:_mm_get_mod_enabled(plugin_id, argc)
{
enum _:args_e { arg_modid = 1 };

if(argc != (args_e-1))
{
abort(AMX_ERR_NATIVE, "'mm_get_mod_enabled' 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 aMods[ArrayMods_e];
ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods);

return aMods[Enabled];
}

/**
* Retrieves mod name.
*
Expand Down Expand Up @@ -99,6 +132,146 @@ public _mm_get_mod_tag(plugin_id, argc)
return set_string(arg_output, aMods[ModTag], get_param(arg_len));
}

/**
* Return the mod changemap type.
*
* @note See 'ChangeMap_e' enum for more information.
*
* @param iModId Mod index.
*
* @return (int) 0 on change map timeleft.
* 1 on change map end of round.
* 2 on change map one more round.
*
* native ChangeMap_e:mm_get_mod_changemap_type(const iModId);
*/
public ChangeMap_e:_mm_get_mod_changemap_type(plugin_id, argc)
{
enum _:args_e { arg_modid = 1 };

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

new iModId = get_param(arg_modid);
new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]);

if(iModId < 0 || iModId >= iArraySizeMods)
{
abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId);
return -1;
}

new aMods[ArrayMods_e];
ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods);

return aMods[ChangeMapType];
}

/**
* Return the maps list of the mod.
*
* @param iModId Mod index.
*
* @return (Array) Maps list array handle, which must be freed via ArrayDestroy()
*
* native Array:mm_get_mod_maps(const iModId);
*/
public Array:_mm_get_mod_maps(plugin_id, argc)
{
enum _:args_e { arg_modid = 1 };

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

new iModId = get_param(arg_modid);
new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]);

if(iModId < 0 || iModId >= iArraySizeMods)
{
abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId);
return -1;
}

new aMods[ArrayMods_e];
ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods);

return ArrayClone(aMods[Maps]);
}

/**
* Return the cvars list of the mod.
*
* @param iModId Mod index.
*
* @return (Array) Cvars list array handle, which must be freed via ArrayDestroy()
*
* native Array:mm_get_mod_cvars(const iModId);
*/
public Array:_mm_get_mod_cvars(plugin_id, argc)
{
enum _:args_e { arg_modid = 1 };

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

new iModId = get_param(arg_modid);
new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]);

if(iModId < 0 || iModId >= iArraySizeMods)
{
abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId);
return -1;
}

new aMods[ArrayMods_e];
ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods);

return ArrayClone(aMods[Cvars]);
}

/**
* Return the plugin list of the mod.
*
* @param iModId Mod index.
*
* @return (Array) Plugins list array handle, which must be freed via ArrayDestroy()
*
* native Array:mm_get_mod_plugins(const iModId);
*/
public Array:_mm_get_mod_plugins(plugin_id, argc)
{
enum _:args_e { arg_modid = 1 };

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

new iModId = get_param(arg_modid);
new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]);

if(iModId < 0 || iModId >= iArraySizeMods)
{
abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId);
return -1;
}

new aMods[ArrayMods_e];
ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods);

return ArrayClone(aMods[Plugins]);
}

/**
* Return the current mod index based on JSON position.
*
Expand Down
58 changes: 57 additions & 1 deletion addons/amxmodx/scripting/include/multimod_manager_natives.inc
Expand Up @@ -8,9 +8,16 @@
* Do not modify this!
*/
#define MM_VERSION_MAJOR 2
#define MM_VERSION_MINOR 0
#define MM_VERSION_MINOR 1
#define MM_VERSION_PATCH 0

enum ChangeMap_e
{
CHANGEMAP_TIMELEFT,
CHANGEMAP_END_OF_ROUND,
CHANGEMAP_ONE_MORE_ROUND,
};

/* ===========================================================================
* [ MULTIMOD MANAGER NATIVES ]
* ============================================================================ */
Expand All @@ -22,6 +29,15 @@
*/
native mm_get_mods_count();

/**
* Return if the mod is enabled or not.
*
* @param iModId Mod index.
*
* @return (bool) true if the mod is enabled, false otherwise.
*/
native bool:mm_get_mod_enabled(const iModId);

/**
* Retrieves mod name.
*
Expand Down Expand Up @@ -52,6 +68,46 @@ native mm_get_mod_name(const iModId, szOutput[], const iLen);
*/
native mm_get_mod_tag(const iModId, szOutput[], const iLen);

/**
* Return the mod changemap type.
*
* @note See 'ChangeMap_e' enum for more information.
*
* @param iModId Mod index.
*
* @return (int) 0 on change map timeleft.
* 1 on change map end of round.
* 2 on change map one more round.
*/
native ChangeMap_e:mm_get_mod_changemap_type(const iModId);

/**
* Return the maps list of the mod.
*
* @param iModId Mod index.
*
* @return (Array) Maps list array handle, which must be freed via ArrayDestroy()
*/
native Array:mm_get_mod_maps(const iModId);

/**
* Return the cvars list of the mod.
*
* @param iModId Mod index.
*
* @return (Array) Cvars list array handle, which must be freed via ArrayDestroy()
*/
native Array:mm_get_mod_cvars(const iModId);

/**
* Return the plugin list of the mod.
*
* @param iModId Mod index.
*
* @return (Array) Plugins list array handle, which must be freed via ArrayDestroy()
*/
native Array:mm_get_mod_plugins(const iModId);

/**
* Return the current mod index based on JSON position.
*
Expand Down
7 changes: 6 additions & 1 deletion addons/amxmodx/scripting/multimod_manager.sma
Expand Up @@ -19,8 +19,13 @@
public plugin_natives()
{
register_native("mm_get_mods_count", "_mm_get_mods_count");
register_native("mm_get_mod_enabled", "_mm_get_mod_enabled");
register_native("mm_get_mod_name", "_mm_get_mod_name");
register_native("mm_get_mod_tag", "_mm_get_mod_tag");
register_native("mm_get_mod_changemap_type", "_mm_get_mod_changemap_type");
register_native("mm_get_mod_maps", "_mm_get_mod_maps");
register_native("mm_get_mod_cvars", "_mm_get_mod_cvars");
register_native("mm_get_mod_plugins", "_mm_get_mod_plugins");
register_native("mm_get_currentmod_id", "_mm_get_currentmod_id");
register_native("mm_get_nextmod_id", "_mm_get_nextmod_id");
register_native("mm_force_votemod", "_mm_force_votemod");
Expand Down Expand Up @@ -269,7 +274,7 @@ MultiMod_Init()
}
json_free(jObjectMod);

aMod[Plugins] = ArrayCreate(64);
aMod[Plugins] = ArrayCreate(PLATFORM_MAX_PATH);
jObjectMod = json_object_get_value(jArrayValue, "plugins");
for(j = 0, iObjetCount = json_array_get_count(jObjectMod); j < iObjetCount; ++j)
{
Expand Down

0 comments on commit a5a87e2

Please sign in to comment.