This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

How to save Function in dynamic array?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Dakex
Junior Member
Join Date: Mar 2019
Old 02-04-2021 , 14:41   How to save Function in dynamic array?
Reply With Quote #1

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<= sizeof(defaultGameModes); i++)
    {
        
gameModes.PushString(defaultGameModes[i]);
        
gameModes_Handler.PushString(defaultGameModes_Handler[i]);
    }
}
public 
Action GameModeMenu(int clientint args)
{
    
Menu gameModeMenu = new Menu(GameModeMenu_Handler);
    
char buffer[64];
    
char idBuffer[64];
    
    
gameModeMenu.SetTitle("Game Modes");
    
    for(
int i 0<= gameModes.Lengthi++)
    {
        
IntToString(iidBuffersizeof(idBuffer));
        
        
gameModes.GetString(ibuffersizeof(buffer) );
        
gameModeMenu.AddItem(idBufferbuffer);
    }
    
gameModeMenu.Display(client20);
    
    return 
Plugin_Handled;
}
public 
int GameModeMenu_Handler(Menu menuMenuAction actionint param1int param2)
{
    
char menuIdBuffer[64];
    
char buffer[64];
    
    
GetMenuItem(menuparam2menuIdBuffersizeof(menuIdBuffer));
    
int menuId StringToInt(menuIdBuffer);
    
    
gameModes_Handler.GetString(menuIdbuffersizeof(buffer));
    
    
PrintToServer("%s %d"buffermenuId);
    
    Function 
gameModeFunc GetFunctionByName(INVALID_HANDLEbuffer);
    
Call_StartFunction(INVALID_HANDLEgameModeFunc);
    
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!");

Dakex is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode