Hi guys, I am trying to create game mode system for my jailbreak plugin.
The problem is, I want to implement natives which will allow to create custom game modes from different plugins.
I am using two ArrayLists, one for the menu (name of gamemode), second one is used to save the handler.
But the code is not working at all. When I try to open the menu, nothing happens, it just says invalid index 8 at line 57 which makes no sense to me.
Here is the code:
PHP Code:
#define PLUGIN_NAME "GameModes"
#define PLUGIN_AUTHOR "Dakex"
#define PLUGIN_DESCRIPTION ""
#define PLUGIN_VERSION "1.1 Epom"
#define PLUGIN_URL ""
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1
ArrayList gameModes;
ArrayList gameModes_Handler;
char defaultGameModes_Handler[] = {"Shooter_Handle", "HNS_Handle", "Matrix_Handle", "CODMW_Handle"};
char defaultGameModes[] = {"Shooter", "HNS", "Matrix", "COD:MW"};
public Plugin:myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_URL
};
public OnPluginStart()
{
gameModes = CreateArray(64);
gameModes_Handler = CreateArray(64);
LoadDefaultGameModes();
RegConsoleCmd("gamemod", GameModeMenu, "turns the gamemode on");
}
public void LoadDefaultGameModes()
{
for(int i = 0; i <= sizeof(defaultGameModes); i++)
{
gameModes.PushString(defaultGameModes[i]);
gameModes_Handler.PushString(defaultGameModes_Handler[i]);
}
}
public Action GameModeMenu(int client, int args)
{
Menu gameModeMenu = new Menu(GameModeMenu_Handler);
char buffer[64];
char idBuffer[64];
gameModeMenu.SetTitle("Game Modes");
for(int i = 0; i <= gameModes.Length; i++)
{
IntToString(i, idBuffer, sizeof(idBuffer));
gameModes.GetString(i, buffer, sizeof(buffer) );
gameModeMenu.AddItem(idBuffer, buffer);
}
gameModeMenu.Display(client, 20);
return Plugin_Handled;
}
public int GameModeMenu_Handler(Menu menu, MenuAction action, int param1, int param2)
{
char menuIdBuffer[64];
char buffer[64];
GetMenuItem(menu, param2, menuIdBuffer, sizeof(menuIdBuffer));
int menuId = StringToInt(menuIdBuffer);
gameModes_Handler.GetString(menuId, buffer, sizeof(buffer));
PrintToServer("%s %d", buffer, menuId);
Function gameModeFunc = GetFunctionByName(INVALID_HANDLE, buffer);
Call_StartFunction(INVALID_HANDLE, gameModeFunc);
Call_Finish();
}
public void Shooter_Handle()
{
PrintToChatAll("TURNING ON SHOOTER!");
}
public void HNS_Handle()
{
PrintToChatAll("TURNING ON HNS!");
}
public void Matrix_Handle()
{
PrintToChatAll("TURNING ON MATRIX!");
}
public void CODMW_Handle()
{
PrintToChatAll("Turning the COD:MW MODE ON!");
}