/////////////////////////////////////////////////////////
/////////////// INCLUDES / DEFINES
/////////////////////////////////////////////////////////
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#define VERSION "1.0Beta"
new Handle:g_CvarDescMode = INVALID_HANDLE;
new Handle:g_CvarShowOnConnect = INVALID_HANDLE;
new Item = 0;
/////////////////////////////////////////////////////////
/////////////// PLUGIN INFO
/////////////////////////////////////////////////////////
public Plugin:myinfo =
{
name = "Rules Plugin",
author = "TOMI[HUN]",
description = "Szabályzat plugin",
version = VERSION,
url = "www.pgaming.hu"
};
/////////////////////////////////////////////////////////
/////////////// ESSENTIAL FUNCTIONS
/////////////////////////////////////////////////////////
public OnPluginStart()
{
// Register Client / Admins Commands
RegConsoleCmd("sm_rules", RulesMenu_Func);
RegAdminCmd("sm_showrules", ShowRules, ADMFLAG_GENERIC);
g_CvarDescMode = CreateConVar("sm_rules_descmode", "0", "Set to 0 if you want description to be show on a menu ,and 1 if you want it to show on chat .");
g_CvarShowOnConnect = CreateConVar("sm_rules_noconnect", "0", "Set to 1 If you dont want menu to show on players connection .");
}
/////////////////////////////////////////////////////////
/////////////// ON CLIENT CONNECTING TO SERVER SEND RULES
/////////////////////////////////////////////////////////
public OnClientPostAdminCheck(client)
{
if (!GetConVarInt(g_CvarShowOnConnect))
{
CreateRulesMenu(client, 0);
}
return Plugin_Handled;
}
/////////////////////////////////////////////////////////
/////////////// CMD HANDLERs
/////////////////////////////////////////////////////////
public Action:RulesMenu_Func(client, args)
{
// Function To Create the menu and send it to client
CreateRulesMenu(client, 0);
return Plugin_Handled;
}
public Action:ShowRules(client, args)
{
// Send admins a list of players to send the Rules menu
new Handle:PlayersMenu = CreateMenu(ShowRulesHandler);
SetMenuTitle(PlayersMenu, "Send rules for player");
SetMenuExitButton(PlayersMenu, true);
AddTargetsToMenu2(PlayersMenu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
DisplayMenu(PlayersMenu, client, 15);
return Plugin_Handled;
}
/////////////////////////////////////////////////////////
/////////////// MENUs / MENUs HANDLERs
/////////////////////////////////////////////////////////
public Action:CreateRulesMenu(client, item)
{
new Handle:RulesMenu = CreateMenu(RulesMenuHandler);
SetMenuTitle(RulesMenu, "Server Rules");
new Handle:kv = CreateKeyValues("Rules");
FileToKeyValues(kv, "addons/sourcemod/configs/rules.cfg");
if (!KvGotoFirstSubKey(kv))
{
return Plugin_Continue;
}
decl String:RuleNumber[64];
decl String:RuleName[255];
do
{
KvGetSectionName(kv, RuleNumber, sizeof(RuleNumber));
KvGetString(kv, "name", RuleName, sizeof(RuleName));
// Add Each Rule to the menu
AddMenuItem(RulesMenu, RuleNumber, RuleName);
} while (KvGotoNextKey(kv));
CloseHandle(kv);
// Send Menu to client
DisplayMenuAtItem(RulesMenu, client, item, 15);
return Plugin_Handled;
}
public HandlerBackToMenu(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
CreateRulesMenu(param1, Item);
}
else if (action == MenuAction_Cancel)
{
PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2);
}
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public RulesMenuHandler(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new Handle:kv = CreateKeyValues("Rules");
FileToKeyValues(kv, "addons/sourcemod/configs/rules.cfg");
if (!KvGotoFirstSubKey(kv))
{
return Plugin_Handled;
}
decl String:buffer[255];
decl String:choice[255];
GetMenuItem(menu, param2, choice, sizeof(choice));
do
{
KvGetSectionName(kv, buffer, sizeof(buffer));
if (StrEqual(buffer, choice))
{
decl String:ruleName[255];
decl String:ruleDescription[255];
decl String:ruleDescription2[255];
decl String:ruleDescription3[255];
decl String:ruleDescription4[255];
decl String:ruleDescription5[255];
decl String:ruleDescription6[255];
decl String:ruleDescription7[255];
decl String:ruleDescription8[255];
decl String:ruleDescription9[255];
KvGetString(kv, "name", ruleName, sizeof(ruleName));
KvGetString(kv, "description", ruleDescription, sizeof(ruleDescription));
KvGetString(kv, "description2", ruleDescription2, sizeof(ruleDescription2));
KvGetString(kv, "description3", ruleDescription3, sizeof(ruleDescription3));
KvGetString(kv, "description4", ruleDescription4, sizeof(ruleDescription4));
KvGetString(kv, "description5", ruleDescription5, sizeof(ruleDescription5));
KvGetString(kv, "description6", ruleDescription6, sizeof(ruleDescription6));
KvGetString(kv, "description7", ruleDescription7, sizeof(ruleDescription7));
KvGetString(kv, "description8", ruleDescription8, sizeof(ruleDescription8));
KvGetString(kv, "description9", ruleDescription9, sizeof(ruleDescription9));
if (GetConVarInt(g_CvarDescMode))
{
PrintToChat(param1, "\x04[nRules] \x03%s : \x01%s", ruleName, ruleDescription);
Item = GetMenuSelectionPosition();
CreateRulesMenu(param1, Item);
}
else
{
decl String:Rule[255];
decl String:Desc[255];
decl String:Desc2[255];
decl String:Desc3[255];
decl String:Desc4[255];
decl String:Desc5[255];
decl String:Desc6[255];
decl String:Desc7[255];
decl String:Desc8[255];
decl String:Desc9[255];
Format(Rule, sizeof(Rule), "%s", ruleName);
Format(Desc, sizeof(Desc), "%s", ruleDescription);
Format(Desc2, sizeof(Desc2), "%s", ruleDescription2);
Format(Desc3, sizeof(Desc3), "%s", ruleDescription3);
Format(Desc4, sizeof(Desc4), "%s", ruleDescription4);
Format(Desc5, sizeof(Desc5), "%s", ruleDescription5);
Format(Desc5, sizeof(Desc6), "%s", ruleDescription6);
Format(Desc5, sizeof(Desc7), "%s", ruleDescription7);
Format(Desc5, sizeof(Desc8), "%s", ruleDescription8);
Format(Desc5, sizeof(Desc9), "%s", ruleDescription9);
Item = GetMenuSelectionPosition();
new Handle:DescriptionPanel = CreatePanel();
SetPanelTitle(DescriptionPanel, Rule);
DrawPanelText(DescriptionPanel, " ");
DrawPanelText(DescriptionPanel, Desc);
DrawPanelText(DescriptionPanel, Desc2);
DrawPanelText(DescriptionPanel, Desc3);
DrawPanelText(DescriptionPanel, Desc4);
DrawPanelText(DescriptionPanel, Desc5);
DrawPanelText(DescriptionPanel, Desc6);
DrawPanelText(DescriptionPanel, Desc7);
DrawPanelText(DescriptionPanel, Desc8);
DrawPanelText(DescriptionPanel, Desc9);
DrawPanelText(DescriptionPanel, " ");
DrawPanelItem(DescriptionPanel, "Back");
SendPanelToClient(DescriptionPanel, param1, HandlerBackToMenu, 15);
}
}
} while (KvGotoNextKey(kv));
CloseHandle(kv);
}
else if (action == MenuAction_Cancel)
{
PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2);
}
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
return Plugin_Handled;
}
public ShowRulesHandler(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
decl String:UserId[64];
GetMenuItem(menu, param2, UserId, sizeof(UserId));
new i_UserId = StringToInt(UserId);
new client = GetClientOfUserId(i_UserId);
CreateRulesMenu(client, 1);
}
else if (action == MenuAction_Cancel)
{
PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2);
}
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
return Plugin_Handled;
}