Raised This Month: $ Target: $400
 0% 

[NMRiH] Weapon Menu (v1.1.0, 01/13/14)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
tdlab
Junior Member
Join Date: Nov 2013
Old 11-09-2013 , 11:42   Re: [NMRiH] Weapon Menu (v1.0.6, 11/08/13)
Reply With Quote #10

Quote:
Originally Posted by Frischling View Post
Yes, that did the trick.Thank you very much for pointing this out.

I am still completly new to this.
Now i have to wait for an update on the Unlimited Ammo Plugin
Well, I tried to edit it a little to add a ammo menu, however I never tested it, and am very new to coding.


Code:
#include <sourcemod>
#include <sdktools>

#define MESS "\x01[\x04Notice\x01]"
#define ERROR "\x01\x04Error\x01"
#define MAX_CONFIG_WEAPONS 24

new Handle:g_iToolCount = INVALID_HANDLE;

new String:g_sWepNumbers[MAX_CONFIG_WEAPONS][64];
new String:g_sWepNames[MAX_CONFIG_WEAPONS][64];
new String:g_sWepDNames[MAX_CONFIG_WEAPONS][64];
new String:g_sWepCategory[MAX_CONFIG_WEAPONS][64];

new g_iWeps = 0, g_iMaxTools = 0, g_iTools[MAXPLAYERS+1];
new bool:bAlive[MAXPLAYERS+1], bool:bPrimary[MAXPLAYERS+1], bool:bSecondary[MAXPLAYERS+1];

public Plugin:myinfo = 
{
	name = "[NMRiH] Weapon Menu",
	author = "Marcus",
	description = "A simple and customizable weapon menu for NMRiH.",
	version = "1.0.1",
	url = "http://www.redspeedservers.com"
};

public OnPluginStart()
{
	CreateConVar("sv_weapon_menu_version", "1.0.1", "This is the version of the Weapon Menu the server is running.", FCVAR_DONTRECORD|FCVAR_NOTIFY|FCVAR_CHEAT);

	g_iToolCount = CreateConVar("sv_tool_count", "10", "Sets the number of tools a player can select.", FCVAR_NONE, true, 0.0, true, 7.0);
	HookConVarChange(g_iToolCount, OnSettingsChange);

	RegAdminCmd("sm_guns", Weapon_Menu, 0);
	RegAdminCmd("sm_primary", Primary_Menu, 0);
	RegAdminCmd("sm_secondary", Secondary_Menu, 0);
	RegAdminCmd("sm_tools", Tool_Menu, 0);
	RegAdminCmd("sm_ammo", Ammo_Menu, 0);
	
	HookEvent("player_spawn", Player_Spawn);
	HookEvent("player_death", Player_Death);
	
	Load_Weapons();
}

public OnSettingsChange(Handle:cvar, const String:oldvalue[], const String:newvalue[])
{
	if (cvar == g_iToolCount)
	{
		g_iMaxTools = StringToInt(newvalue);
	}
}

public OnClientPutInServer(client)
{
	if (IsValidClient(client))
	{
		g_iTools[client] = 0;
		
		bPrimary[client] = false;
		bSecondary[client] = false;
	}
}

public Player_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	
	if (client > 0)
	{
		if (IsClientConnected(client) && IsPlayerAlive(client))
		{
			bAlive[client] = true;
			g_iTools[client] = 0;
			
			bPrimary[client] = false;
			bSecondary[client] = false;
		}
	}

}

public Player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	
	if (client > 0)
	{
		if (IsClientConnected(client) && IsPlayerAlive(client))
		{
			bAlive[client] = false;
		}
	}

}

Load_Weapons() // Originally, this was from TwistedPanda's BuildWars : It helped alot!!
{
	decl String:sPath[PLATFORM_MAX_PATH];
	BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/weapon_menu.ini");

	new Handle:_hKV = CreateKeyValues("Weapons");
	if(FileToKeyValues(_hKV, sPath))
	{
		KvGotoFirstSubKey(_hKV);
		do
		{
			KvGetSectionName(_hKV, g_sWepNumbers[g_iWeps], 64);
			
			KvGetString(_hKV, "display_name", g_sWepDNames[g_iWeps], sizeof(g_sWepDNames[]));
			KvGetString(_hKV, "weapon_name", g_sWepNames[g_iWeps], sizeof(g_sWepNames[]));
			KvGetString(_hKV, "category", g_sWepCategory[g_iWeps], sizeof(g_sWepCategory[]));

			g_iWeps++;
		}
		while (KvGotoNextKey(_hKV));
		CloseHandle(_hKV);
		
		PrintToServer("Weapon-Menu: Loaded %d weapons", g_iWeps);
	} else
	{
		CloseHandle(_hKV);
		SetFailState("Weapon-Menu: Could not locate \"configs/weapon_menu.ini\"");
	}
}

public Action:Weapon_Menu(client, args)
{
	if(bAlive[client])
	{
		new Handle:hMenu = CreateMenu(Menu_Weapon);
		SetMenuTitle(hMenu, "Weapon Menu");
		
		AddMenuItem(hMenu, "1", "Primary Weapons");
		AddMenuItem(hMenu, "2", "Secondary Weapons");
		AddMenuItem(hMenu, "3", "Tools");
		AddMenuItem(hMenu, "4", "Ammo");

		SetMenuExitButton(hMenu, true);
		DisplayMenu(hMenu, client, 120);
		
		PrintToChat2(client, "%s Press [\x04Esc\x01] to view the weapon menu!", MESS);
	} else
	PrintToChat2(client, "%s %s: You must be alive to use this command!", MESS, ERROR)

	return Plugin_Handled;
}

public Menu_Weapon(Handle:weapon, MenuAction:action, param1, param2)
{
	if (action == MenuAction_End)
	{
        CloseHandle(weapon);
	}
	
	if (action == MenuAction_Select)
	{
		new String:info[32];
		GetMenuItem(weapon, param2, info, sizeof(info));
		
		if (StrEqual(info, "1"))
		{
			FakeClientCommand(param1, "sm_primary");
		} else if (StrEqual(info, "2"))
		{
			FakeClientCommand(param1, "sm_secondary");
		} else if (StrEqual(info, "3"))
		{
			FakeClientCommand(param1, "sm_tools");
		}
		{
			FakeClientCommand(param1, "sm_ammo");
		}
	}
}

public Action:Primary_Menu(client, args)
{
	if(bAlive[client])
	{
		new Handle:hMenu = CreateMenu(Menu_Primary);
		SetMenuTitle(hMenu, "Primary Weapon Menu");
		
		for(new i = 0; i < g_iWeps; i++)
		{
			if (StrEqual(g_sWepCategory[i], "primary", false))
				AddMenuItem(hMenu, g_sWepNumbers[i], g_sWepDNames[i]);
		}
		
		SetMenuExitButton(hMenu, true);
		DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
		
		PrintToChat2(client, "%s Press [\x04Esc\x01] to view the primary weapons menu!", MESS);
	} else
	PrintToChat2(client, "%s %s: You must be alive to use this command!", MESS, ERROR);
	
	return Plugin_Handled;
}

public Menu_Primary(Handle:primary, MenuAction:action, param1, param2)
{
	if (action == MenuAction_End)
	{
        CloseHandle(primary);
	}
	if (action == MenuAction_Select)
	{
		new String:info[32];
		GetMenuItem(primary, param2, info, sizeof(info));
		
		for (new i = 0; i < g_iWeps; i++)
		{
			if (StrEqual(info, g_sWepNumbers[i]))
			{
				new weapon = GivePlayerItem(param1, g_sWepNames[i], 0);
				
				bPrimary[param1] = true;
				AcceptEntityInput(weapon, "use", param1, param1);
				
				PrintToChat2(param1, "%s You have selected the \x04%s\x01.", MESS, g_sWepDNames[i]);
			}
		}
	}
}

public Action:Secondary_Menu(client, args)
{
	if(bAlive[client])
	{
		new Handle:hMenu = CreateMenu(Menu_Secondary);
		SetMenuTitle(hMenu, "Secondary Weapon Menu");
	
		for(new i = 0; i < g_iWeps; i++)
		{
			if (StrEqual(g_sWepCategory[i], "secondary", false))
				AddMenuItem(hMenu, g_sWepNumbers[i], g_sWepDNames[i]);
		}
		
		SetMenuExitButton(hMenu, true);
		DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
		
		PrintToChat2(client, "%s Press [\x04Esc\x01] to view the secondary weapons menu!", MESS);
	} else
	PrintToChat2(client, "%s %s: You must be alive to use this command!", MESS, ERROR);
	
	return Plugin_Handled;
}

public Menu_Secondary(Handle:secondary, MenuAction:action, param1, param2)
{
	if (action == MenuAction_End)
	{
        CloseHandle(secondary);
	}
	if (action == MenuAction_Select)
	{
		new String:info[32];
		GetMenuItem(secondary, param2, info, sizeof(info));
		
		for (new i = 0; i < g_iWeps; i++)
		{
			if (StrEqual(info, g_sWepNumbers[i]))
			{
				new weapon = GivePlayerItem(param1, g_sWepNames[i], 0);
				
				bSecondary[param1] = true;
				AcceptEntityInput(weapon, "use", param1, param1);
				
				PrintToChat2(param1, "%s You have selected the \x04%s\x01.", MESS, g_sWepDNames[i]);
			}
		}
	}
}

public Action:Tool_Menu(client, args)
{
	if(bAlive[client])
	{
		new Handle:hMenu = CreateMenu(Menu_Tool);
		SetMenuTitle(hMenu, "Tool Menu");
	
		for(new i = 0; i < g_iWeps; i++)
		{
			if (StrEqual(g_sWepCategory[i], "tool", false))
				AddMenuItem(hMenu, g_sWepNumbers[i], g_sWepDNames[i]);
		}
			
		SetMenuExitButton(hMenu, true);
		DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
		
		PrintToChat2(client, "%s Press [\x04Esc\x01] to view the tool menu!", MESS);
	} else
	PrintToChat2(client, "%s %s: You must be alive to use this command!", MESS, ERROR);
	
	return Plugin_Handled;
}

public Menu_Tool(Handle:tool, MenuAction:action, param1, param2)
{
	if (action == MenuAction_End)
	{
        CloseHandle(tool);
	}
	if (action == MenuAction_Select)
	{
		new String:info[32];
		GetMenuItem(tool, param2, info, sizeof(info));
		
		if (g_iTools[param1] < g_iMaxTools)
		{
			for (new i = 0; i < g_iWeps; i++)
			{
				if (StrEqual(info, g_sWepNumbers[i]))
				{
					new weapon = GivePlayerItem(param1, g_sWepNames[i], 0);
					
					g_iTools[param1]++;
					AcceptEntityInput(weapon, "use", param1, param1);
					
					PrintToChat2(param1, "%s You have selected the \x04%s\x01.", MESS, g_sWepDNames[i]);
				}
			}
		} else
		PrintToChat2(param1, "%s %s: You are only allowed 3 tools!", MESS, ERROR);
	}
}
public Action:Ammo_Menu(client, args)
{
	if(bAlive[client])
	{
		new Handle:hMenu = CreateMenu(Menu_Tool);
		SetMenuTitle(hMenu, "Ammo Menu");
	
		for(new i = 0; i < g_iWeps; i++)
		{
			if (StrEqual(g_sWepCategory[i], "ammo", false))
				AddMenuItem(hMenu, g_sWepNumbers[i], g_sWepDNames[i]);
		}
			
		SetMenuExitButton(hMenu, true);
		DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
		
		PrintToChat2(client, "%s Press [\x04Esc\x01] to view the tool menu!", MESS);
	} else
	PrintToChat2(client, "%s %s: You must be alive to use this command!", MESS, ERROR);
	
	return Plugin_Handled;
}

public Menu_Ammo(Handle:tool, MenuAction:action, param1, param2)
{
	if (action == MenuAction_End)
	{
        CloseHandle(tool);
	}
	if (action == MenuAction_Select)
	{
		new String:info[32];
		GetMenuItem(tool, param2, info, sizeof(info));
		
		if (g_iTools[param1] < g_iMaxTools)
		{
			for (new i = 0; i < g_iWeps; i++)
			{
				if (StrEqual(info, g_sWepNumbers[i]))
				{
					new weapon = GivePlayerItem(param1, g_sWepNames[i], 0);
					
					g_iTools[param1]++;
					AcceptEntityInput(weapon, "use", param1, param1);
					
					PrintToChat2(param1, "%s You have selected the \x04%s\x01.", MESS, g_sWepDNames[i]);
				}
			}
		} else
		PrintToChat2(param1, "%s %s: You are only allowed 3 tools!", MESS, ERROR);
	}
}


stock bool:IsValidClient(client) 
{
    if ((1 <= client <= MaxClients) && IsClientInGame(client)) 
        return true; 
     
    return false; 
}

public PrintToChat2(client, const String:format[], any:...)
{
	decl String:buffer[256];
	SetGlobalTransTarget(client);
	VFormat(buffer, sizeof(buffer), format, 3);
	
	new Handle:bf = StartMessageOne("SayText2", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
	BfWriteByte(bf, -1);
	BfWriteByte(bf, true);
	BfWriteString(bf, buffer);
	EndMessage();
}

I haven't tested this, and if anyone could try it out, please give me feedback. If anyone noticed code errors i'm open to suggestions.
tdlab 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 00:20.


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