Raised This Month: $32 Target: $400
 8% 

Preventing voting by time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 11-03-2019 , 07:23   Preventing voting by time
Reply With Quote #1

I want to prevent it from being restarted within 30 minutes of voting.

Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"

#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");
		}
	}
}
 
public Action Menu_Test1(int client, int args)
{
	if (IsVoteInProgress())
	{
		return;
	}
 
	Menu menu = new Menu(Handle_VoteMenu);
	menu.SetTitle("FJ Vote?");
	menu.AddItem("yes", "Yes");
	menu.AddItem("no", "No");
	menu.ExitButton = false;
	menu.DisplayVoteToAll(20);
}
__________________
alphaearth is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-05-2019 , 18:08   Re: Preventing voting by time
Reply With Quote #2

You could do it by a couple of methods.
Code:
CreateTimer(1800.0,ResetCountdown);

public Action ResetCountdown(Handle timer)
{
	AllowVote = true;
}
Or by a global float set when the vote passes to g_VoteTime = GetTickedTime()+1800.0;
Then have a check in Menu_Test1 for:
Code:
if (g_VoteTime <= GetTickedTime())
Balimbanana is offline
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 11-07-2019 , 06:30   Re: Preventing voting by time
Reply With Quote #3

Can you edit my article above via plugin?
__________________
alphaearth is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-07-2019 , 10:44   Re: Preventing voting by time
Reply With Quote #4

Would be something like this (NOT TESTED)

Spoiler
__________________

Last edited by Marttt; 11-07-2019 at 18:27.
Marttt is offline
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
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 11-08-2019 , 21:41   Re: Preventing voting by time
Reply With Quote #6

thank you.
__________________
alphaearth is offline
Reply


Thread Tools
Display Modes

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 16:42.


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