I am trying to make a menu to give an m16 or ar47 to players. I have weapons listed in file called rifles.txt and have in my sourcemod/configs folder.
This is what I did:
Code:
#include <sourcemod>
public Plugin:rifle = {
name = "rifle",
author = "Irishfire",
description = "Give rifle",
version = "1.0",
url = "http://insurgency.ipkclan.com/forum/"
};
new Handle:g_weaponmenu = INVALID_HANDLE
public OnPluginStart()
{
RegConsoleCmd("weaponmenu", Command_give_weapon)
}
public OnweaponStart()
{
g_weaponmenu = Buildweaponmenu()
}
public OnweaponEnd()
{
if (g_weaponmenu != INVALID_HANDLE)
{
CloseHandle(g_weaponmenu)
g_weaponmenu = INVALID_HANDLE
}
}
Handle:Buildweaponmenu()
{
/* Open the file */
new Handle:file = OpenFile("rifles.txt", "/addons/sourcemod/configs")
if (file == INVALID_HANDLE)
{
return INVALID_HANDLE
}
/* Create the menu Handle */
new Handle:menu = CreateMenu(weaponmenu);
new String:weaponname[255]
while (!IsEndOfFile(file) && ReadFileLine(file, weaponname, sizeof(weaponname)))
{
if (weaponname[0] == ';' || !IsCharAlpha(weaponname[0]))
{
continue
}
/* Cut off the name at any whitespace */
new len = strlen(weaponname)
for (new i=0; i<len; i++)
{
if (IsCharSpace(weaponname[i]))
{
weaponname[i] = '\0'
break
}
}
/* Check if the weapon is valid */
/*if (!IsgunValid(weaponname))*/
/*{*/
/* continue*/
/*}*/
/* Add it to the menu */
AddMenuItem(menu, weaponname, weaponname)
}
/* Make sure we close the file! */
CloseHandle(file)
/* Finally, set the title */
SetMenuTitle(menu, "Please select a Rifle:")
return menu
}
public weaponmenu(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32]
/* Get item info */
new bool:found = GetMenuItem(menu, param2, info, sizeof(info))
/* Tell the client */
PrintToConsole(param1, "You selected item: %d (found? %d info: %s)", param2, found, info)
/* Change the Rifle */
ServerCommand("give_weapon %s", info)
}
}
public Action:Command_give_weapon(client, args)
{
if (g_weaponmenu == INVALID_HANDLE)
{
PrintToConsole(client, "The rifles.txt file was not found!")
return Plugin_Handled
}
DisplayMenu(g_weaponmenu, client, MENU_TIME_FOREVER)
return Plugin_Handled
}
If some could help please
__________________