AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
|
02-26-2015
, 17:24
Re: [cs:go] menu pop-up on roundstart and chat cmd.
|
#3
|
Quote:
Originally Posted by AleCz14
I started working on a Menu using a menu generator, i dont know how to make the Menu to auto show-up on round_start and on chatcmd "!shop", maybe u can help me.
|
If the menu is always the same, you may want to move the Menu variable to a global variable and just display the menu in your function.
I really should add an option for that to the menu generator at some point.
As for displaying the menu on Round Start and Player Spawn, event hooks for those aren't difficult to do.
Having said that, lets make those changes
Spoiler
PHP Code:
#include <sourcemod>
#include <sdkhooks>
new Handle:weaponsMenu;
public Plugin:myinfo =
{
name = "FMU BUY MENU",
author = "AleCs14;o",
description = "BUY MENU DESIGNED FOR FMU",
version = "1.0",
url = "<- URL ->"
}
public OnPluginStart()
{
// This is a separate function to make the code easier to read
CreateWeaponsMenu();
RegConsoleCmd("shop", Cmd_Shop, "Shop command");
HookEvent("round_start", Event_RoundStart);
HookEvent("player_spawn", Event_PlayerSpawn); // May need to be "player_spawned"
}
CreateWeaponsMenu()
{
weaponsMenu = CreateMenu(Menu_WeaponStore, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
SetMenuTitle(weaponsMenu, "| FURIEN MOD ULTIMATE |");
AddMenuItem(weaponsMenu, "Ammo", "Ammo Refill - 1,000$");
AddMenuItem(weaponsMenu, "Zeus", "Zeus - 1,500$");
AddMenuItem(weaponsMenu, "Armor", "Armor - 2,000$");
AddMenuItem(weaponsMenu, "Hp", "+25 HP - 3,000$");
AddMenuItem(weaponsMenu, "Shotgun", "Shotgun - 3,000$");
AddMenuItem(weaponsMenu, "M4", "M4A4 / M4A1 - 3,500$");
AddMenuItem(weaponsMenu, "Scout", "Scout - 4,000$");
AddMenuItem(weaponsMenu, "Grenades", "Grenades Pack - 5,000$");
AddMenuItem(weaponsMenu, "Bhop", "AutoBhop - 6, 000$");
AddMenuItem(weaponsMenu, "Wall", "WallHang - 10,000$");
}
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
for (new client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client) && !IsClientObserver(client) && !IsFakeClient(client) &&
GetClientMenu(client) != MenuSource_Normal)
{
ShowWeaponsMenu(client);
}
}
}
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (client > 0 && !IsFakeClient(client) && GetClientMenu(client) != MenuSource_Normal)
{
ShowWeaponsMenu(client);
}
}
public Action:Cmd_Shop(client, args)
{
ShowWeaponsMenu(client);
return Plugin_Handled;
}
ShowWeaponsMenu(client)
{
DisplayMenu(weaponsMenu, client, MENU_TIME_FOREVER);
}
public Menu_WeaponStore(Handle:menu, MenuAction:action, param1, param2)
{
switch (action)
{
case MenuAction_Select:
{
//param1 is client, param2 is item
new String:item[64];
GetMenuItem(menu, param2, item, sizeof(item));
if (StrEqual(item, "Ammo"))
{
}
else if (StrEqual(item, "Zeus"))
{
}
else if (StrEqual(item, "Armor"))
{
}
else if (StrEqual(item, "Hp"))
{
}
else if (StrEqual(item, "Shotgun"))
{
}
else if (StrEqual(item, "M4"))
{
}
else if (StrEqual(item, "Scout"))
{
}
else if (StrEqual(item, "Grenades"))
{
}
else if (StrEqual(item, "Bhop"))
{
}
else if (StrEqual(item, "Wall"))
{
}
}
case MenuAction_End:
{
//param1 is MenuEnd reason, if canceled param2 is MenuCancel reason
CloseHandle(menu);
}
case MenuAction_DisplayItem:
{
//param1 is client, param2 is item
new String:item[64];
GetMenuItem(menu, param2, item, sizeof(item));
if (StrEqual(item, "Ammo"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Ammo", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Zeus"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Zeus", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Armor"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Armor", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Hp"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Hp", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Shotgun"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Shotgun", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "M4"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "M4", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Scout"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Scout", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Grenades"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Grenades", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Bhop"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Bhop", param1);
return RedrawMenuItem(translation);
}
else if (StrEqual(item, "Wall"))
{
new String:translation[128];
Format(translation, sizeof(translation), "%T", "Wall", param1);
return RedrawMenuItem(translation);
}
}
}
return 0;
}
Note that I made a few other adjustments... notably, I changed the menu type as I've heard Valve menus don't work in CS:GO (it's missing the UI for it).
Quote:
Originally Posted by Exolent[jNr]
Hooking chat commands like this:
Code:
public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[]) {
if (StrEqual(sArgs, "!shop")) {
// Show menu to client
}
}
And you can hook events as seen here:
https://wiki.alliedmods.net/Events_(...Mod_Scripting)
You might want to hook player spawn to show it whenever they spawn.
|
If you're registering commands starting with / or !, you really should use RegConsoleCmd.
__________________
Not currently working on SourceMod plugin development.
|
|