View Single Post
Balimbanana
Member
Join Date: Jan 2017
Old 11-08-2019 , 12:42   Re: Preventing voting by time
Reply With Quote #5

It would be something like this:

Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"
static float g_VoteTime = 0.0;

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

public Plugin myinfo = 
{
	name = "",
	author = PLUGIN_AUTHOR,
	description = "",
	version = PLUGIN_VERSION,
	url = ""
};

public void OnPluginStart()
{
	RegConsoleCmd("menu_test1", Menu_Test1);
}

public int Handle_VoteMenu(Menu menu, MenuAction action, int param1, int param2)
{
	if (action == MenuAction_End)
	{
		/* This is called after VoteEnd */
		delete menu;
	}
	else if (action == MenuAction_VoteEnd)
	{
		/* 0=yes, 1=no */
		if (param1 == 0)
		{
			ServerCommand("sm plugins load xantis_fj; sm_fj");
		}
		g_VoteTime = GetTickedTime()+1800.0;
	}
}
 
public Action Menu_Test1(int client, int args)
{
	if (IsVoteInProgress())
	{
		return Plugin_Handled;
	}
	else if (g_VoteTime <= GetTickedTime())
	{
		Menu menu = new Menu(Handle_VoteMenu);
		menu.SetTitle("FJ Vote?");
		menu.AddItem("yes", "Yes");
		menu.AddItem("no", "No");
		menu.ExitButton = false;
		menu.DisplayVoteToAll(20);
	}
	else
	{
		float timeleft = -1.0*(GetTickedTime()-g_VoteTime);
		if (timeleft > 60.0)
		{
			timeleft = timeleft/60.0;
			char context[32];
			Format(context,sizeof(context),"minutes");
			if (timeleft < 2.0) Format(context,sizeof(context),"minute");
			if (client) PrintToChat(client,"You cannot vote for another %1.f %s...",timeleft,context);
			else PrintToServer("You cannot vote for another %1.f %s...",timeleft,context);
		}
		else
		{
			char context[32];
			Format(context,sizeof(context),"seconds");
			if (timeleft < 2.0) Format(context,sizeof(context),"second");
			if (client) PrintToChat(client,"You cannot vote for another %1.f %s...",timeleft,context);
			else PrintToServer("You cannot vote for another %1.f %s...",timeleft,context);
		}
	}
	return Plugin_Handled;
}

Last edited by Balimbanana; 11-08-2019 at 13:09. Reason: There should be Plugin_Handled for the returns so it doesn't show Unknown Command in console.
Balimbanana is offline