Raised This Month: $ Target: $400
 0% 

weaponmenu for insurgency


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
IrishFire
Junior Member
Join Date: Apr 2006
Location: Syracuse NY
Old 07-29-2007 , 11:37   weaponmenu for insurgency
Reply With Quote #1

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
__________________
The IRISH rule as long as they dont stop making BEER

-|IPK|-IRISH PUB KILLERS

Last edited by IrishFire; 07-29-2007 at 11:40.
IrishFire is offline
Send a message via Yahoo to IrishFire
 



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 10:17.


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