adding Top12Nomination
This commit is contained in:
parent
092d3c1aa8
commit
d9c128201b
189
Top12Nomination/scripting/Top12Nomination.sp
Normal file
189
Top12Nomination/scripting/Top12Nomination.sp
Normal file
@ -0,0 +1,189 @@
|
||||
#include <sourcemod>
|
||||
#include <mapchooser>
|
||||
#include <basecomm>
|
||||
#include <mapchooser_extended>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
char g_configPath[PLATFORM_MAX_PATH];
|
||||
Menu g_mapMenu;
|
||||
int g_Player_NominationDelay[MAXPLAYERS + 1];
|
||||
ConVar g_Cvar_NominateDelay = null;
|
||||
|
||||
public Plugin myinfo = {
|
||||
name = "Top 12 Nomination",
|
||||
author = "Nicklas Vedsted",
|
||||
description = "Allows very special people to nominate particular maps.",
|
||||
version = "1.0.0",
|
||||
url = "https://gflclan.com/"
|
||||
};
|
||||
|
||||
public void OnPluginStart() {
|
||||
BuildPath(Path_SM, g_configPath, PLATFORM_MAX_PATH, "configs/specialfriday.cfg");
|
||||
buildMenu();
|
||||
|
||||
RegAdminCmd("sm_top12_nominate", Cmd_Nominate, ADMFLAG_RESERVATION | ADMFLAG_CUSTOM1 | ADMFLAG_CUSTOM3 | ADMFLAG_CUSTOM4 | ADMFLAG_CUSTOM5 | ADMFLAG_CUSTOM6, "Opens Top 12 Nominations.");
|
||||
}
|
||||
|
||||
public void OnAllPluginsLoaded() {
|
||||
g_Cvar_NominateDelay = FindConVar("sm_nominate_delay");
|
||||
}
|
||||
|
||||
public Action Cmd_Nominate(int client, int args) {
|
||||
if (!IsNominateAllowed(client)) return Plugin_Handled;
|
||||
|
||||
if (g_mapMenu.ItemCount == 0) {
|
||||
ReplyToCommand(client, "[Top12] There are no maps that can be special nominated.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
g_mapMenu.Display(client, MENU_TIME_FOREVER);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public int Handler_MapSelectMenu(Menu menu, MenuAction action, int client, int position) {
|
||||
switch (action) {
|
||||
case MenuAction_Select: {
|
||||
if(g_Player_NominationDelay[client] > GetTime()) {
|
||||
PrintToChat(client, "[Top12] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[client] - GetTime());
|
||||
menu.DisplayAt(client, menu.Selection, MENU_TIME_FOREVER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
menu.GetItem(position, map, PLATFORM_MAX_PATH);
|
||||
|
||||
NominateResult result = NominateMap(map, false, client);
|
||||
|
||||
switch(result) {
|
||||
case Nominate_AlreadyInVote: {
|
||||
PrintToChat(client, "[Top12] Map is already nominated.");
|
||||
return 0;
|
||||
}
|
||||
case Nominate_VoteFull: {
|
||||
PrintToChat(client, "[Top12] There is not room for more nominations.");
|
||||
return 0;
|
||||
}
|
||||
case Nominate_InvalidMap: {
|
||||
PrintToChat(client, "[Top12] %s is not a valid map. Please contact the server manager in order to fix this.", map);
|
||||
return 0;
|
||||
}
|
||||
case Nominate_Added: {
|
||||
PrintToChatAll("[Top12] %N (special) nominated %s!", client, map);
|
||||
}
|
||||
case Nominate_Replaced: {
|
||||
PrintToChatAll("[Top12] %N changed their nomination to %s.", client, map);
|
||||
}
|
||||
}
|
||||
g_Player_NominationDelay[client] = GetTime() + getNominationDelay();
|
||||
LogMessage("%N (special) nominated %s", client, map);
|
||||
}
|
||||
case MenuAction_DrawItem: {
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
menu.GetItem(position, map, PLATFORM_MAX_PATH);
|
||||
|
||||
if(GetMapCooldown(map) || GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, client) >= 0) {
|
||||
return ITEMDRAW_DISABLED;
|
||||
}
|
||||
return ITEMDRAW_DEFAULT;
|
||||
}
|
||||
case MenuAction_DisplayItem: {
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
menu.GetItem(position, map, sizeof(map));
|
||||
char display[150];
|
||||
|
||||
int Cooldown = GetMapCooldown(map);
|
||||
if (Cooldown) {
|
||||
Format(display, sizeof(display), "%s (Recently Played %d)", map, Cooldown);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
int TimeRestriction = GetMapTimeRestriction(map);
|
||||
if(TimeRestriction) {
|
||||
Format(display, sizeof(display), "%s (Time+%dH%dM)", map, RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
int PlayerRestriction = GetMapPlayerRestriction(map);
|
||||
if(PlayerRestriction != 0) {
|
||||
if(PlayerRestriction < 0) {
|
||||
Format(display, sizeof(display), "%s (Players+%d)", map, PlayerRestriction * -1);
|
||||
} else {
|
||||
Format(display, sizeof(display), "%s (Players-%d)", map, PlayerRestriction);
|
||||
}
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
int GroupRestriction = GetMapGroupRestriction(map, client);
|
||||
if(GroupRestriction >= 0) {
|
||||
Format(display, sizeof(display), "%s (Group max: %d)", map, GroupRestriction);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
stock void buildMenu() {
|
||||
g_mapMenu = new Menu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT | MenuAction_DrawItem | MenuAction_DisplayItem);
|
||||
g_mapMenu.SetTitle("Special Nominate A Map!");
|
||||
SetMenuExitButton(g_mapMenu, true);
|
||||
|
||||
ArrayList maps = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
|
||||
|
||||
if (!FileExists(g_configPath)) {
|
||||
PrintToServer("[Top12] specialfriday.cfg does not exists. No nominations has been added.");
|
||||
return;
|
||||
}
|
||||
|
||||
File configFile = OpenFile(g_configPath, "r");
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
while (configFile.ReadLine(map, PLATFORM_MAX_PATH)) {
|
||||
TrimString(map);
|
||||
if (strlen(map) == 0 || map[0] == '#' || map[0] == '/')continue;
|
||||
maps.PushString(map);
|
||||
}
|
||||
|
||||
configFile.Close();
|
||||
SortADTArray(maps, Sort_Ascending, Sort_String);
|
||||
|
||||
for (int i = 0; i < maps.Length; ++i) {
|
||||
maps.GetString(i, map, PLATFORM_MAX_PATH);
|
||||
g_mapMenu.AddItem(map, map);
|
||||
}
|
||||
}
|
||||
|
||||
stock bool IsNominateAllowed(int client) {
|
||||
if(BaseComm_IsClientGagged(client))
|
||||
return false;
|
||||
|
||||
CanNominateResult result = CanNominate();
|
||||
|
||||
switch(result)
|
||||
{
|
||||
case CanNominate_No_VoteInProgress:
|
||||
{
|
||||
ReplyToCommand(client, "[Top12] Vote is already in progress.");
|
||||
return false;
|
||||
}
|
||||
|
||||
case CanNominate_No_VoteComplete:
|
||||
{
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
GetNextMap(map, sizeof(map));
|
||||
ReplyToCommand(client, "[Top12] The next map is %s.", map);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
stock int getNominationDelay() {
|
||||
if (g_Cvar_NominateDelay == null) {
|
||||
return 3;
|
||||
}
|
||||
return g_Cvar_NominateDelay.IntValue;
|
||||
}
|
Loading…
Reference in New Issue
Block a user