Raised This Month: $ Target: $400
 0% 

[L4D2] $10 plugin job (requiring native votes)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dustinandband
Senior Member
Join Date: May 2015
Old 04-10-2017 , 15:14   [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #1

I wasn’t sure if this price seems fair or not – but the plugin is already almost finished and just needs 1 feature added to it. Perhaps $15 would be more reasonable depending on the amount of coding this could take.


Currently, if anyone types “!slots #” this plugin will automatically change the sm_cvar sv_maxplayers value to whatever was voted (as long as it’s between 1 and 32). However I want a vote to pop up asking players if they want to change slots to # amount? Simple yes / no vote with an HUD layout similar to calling a map change vote.

I’d like the NativeVotes_DisplayPass text to say something like “Changing sv_maxplayers to #”.
PrintToChatAll command at the end isn't needed of course.


Thanks



PHP Code:

#include <sourcemod>
//#include <nativevotes> - eventually when vote is functional, will include this to make vote HUD look presentable


public Plugin:myinfo = {
    
name "slots",
    
author "unknown",
    
description "Changes the slots",
    
url ""

}

public 
OnPluginStart ()
{
    
RegConsoleCmd("sm_slots"Slots_Vote"Changes the slots");
    
RegConsoleCmd("sm_slot"Slots_Vote"Changes the slots");
}

public 
Action:Slots_Vote(client,args)
{
    
decl String:arg[32];
    
GetCmdArg(1argsizeof(arg));
    
    if(
args != 1//we don't have exactly one argument passed with our command string
    
{
        
PrintToChat(client"[SM] Invalid Usage: !slots <#>");
        return 
Plugin_Handled;
    }
    
     
//Take our sm_command <argument> and put it into integer form:
    
int voteval StringToInt(arg);
    
    if(
voteval 1//vote value is less than 1
    
{
       
PrintToChat(client"[SM] Invalid Usage: value cannot be less than 1.");
       return 
Plugin_Handled;
    }
    else if(
voteval 32//vote value is greater than 32
    
{
       
PrintToChat(client"[SM] Invalid Usage: value cannot exceed 32.");
       return 
Plugin_Handled;
    }
    
    
//all good
    
SetConVarInt(FindConVar("sv_maxplayers"), voteval);
    
PrintToChatAll("[SM]: sv_maxplayers changed to %i"voteval);
    return 
Plugin_Handled;
    

dustinandband is offline
dustinandband
Senior Member
Join Date: May 2015
Old 04-10-2017 , 15:37   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #2

For some reason whenever I try to edit my main post, it comes up with a blank text box.

Anyway, $10 seems too low even for something very simple. Probably $15 would be fair but if people think that's still too low let me know.

"Currently, if anyone types “!slots #” this plugin will automatically change the sm_cvar sv_maxplayers value to whatever was voted (as long as it’s between 1 and 32)" - meant whatever was "typed". No vote function yet..
dustinandband is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 04-10-2017 , 15:39   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #3

(untested)

Code:
#include <sourcemod>

int votefor;

public Plugin:myinfo =
{
	name = "slots",
	author = "unknown",
	description = "Changes the slots",
	url = ""
}

public OnPluginStart()
{
	RegConsoleCmd("sm_slots", Slots_Vote, "Changes the slots");
	RegConsoleCmd("sm_slot", Slots_Vote, "Changes the slots");
}

public Action Slots_Vote(int client, int args)
{
	if (args != 1)
	{
		PrintToChat(client, "[SM] Invalid Usage: !slots <#>");
		return Plugin_Handled;
	}
	
	char sArgs[32];
	GetCmdArg(1, sArgs, sizeof(sArgs));
	int voteval = StringToInt(sArgs);
	
	if (voteval < 1 || voteval > 32)
	{
		PrintToChat(client, "[SM] Invalid Usage: value cannot be less than 1 or exceed 32.");
		return Plugin_Handled;
	}
	
	if (IsVoteInProgress())
	{
		PrintToChat(client, "[SM] You cannot start a vote while one is currently going.");
		return Plugin_Handled;
	}
	
	votefor = voteval;
	
	Menu menu = CreateMenu(MenuHandler_VoteMaxSlots);
	SetMenuTitle(menu, "Vote to set the maxslots to %i?", voteval);
	
	AddMenuItem(menu, "yes", "Yes");
	AddMenuItem(menu, "no", "No");
	
	VoteMenuToAll(menu, 20);
	
	return Plugin_Handled;
}

public int MenuHandler_VoteMaxSlots(Menu menu, MenuAction action, int param1, int param2)
{
	switch (action)
	{
		case MenuAction_VoteEnd:
		{
			char sInfo[6];
			GetMenuItem(menu, param1, sInfo, sizeof(sInfo));
			
			if (StrEqual(sInfo, "yes"))
			{
				SetConVarInt(FindConVar("sv_maxplayers"), votefor);
				PrintToChatAll("[SM]: sv_maxplayers changed to %i", votefor);
			}
			else
			{
				PrintToChatAll("[SM]: The vote has failed.");
			}
		}
		
		case MenuAction_VoteCancel, VoteCancel_NoVotes:
		{
			PrintToChatAll("[SM]: No votes casted.");
		}
		
		case MenuAction_End:
		{
			CloseHandle(menu);
		}
	}
}

Last edited by Drixevel; 04-10-2017 at 15:40.
Drixevel is offline
dustinandband
Senior Member
Join Date: May 2015
Old 04-10-2017 , 17:22   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #4

Hi,

Thanks for the quick reply. The vote itself is functional, but I was wanting the vote feature to be written with the native votes API for a better looking HUD:
https://forums.alliedmods.net/showthread.php?t=208008

Video demonstration - you can see the nice HUD layout when I call the !fullspawns command as well as voting to change chapters: https://youtu.be/XA_5p7zo6nM


Some example code that uses the Native Votes API (taken from the fullspawns sp file):

PHP Code:
public TurnOffFullSpawns(client)
{
    if(
StartEnableSpawnClearVote(client))
    {
        
FakeClientCommand(client"Vote Yes");
    }
    
//====================
// Voting
//====================
bool:StartDisableSpawnClearVote(client)
{
    if (!
NativeVotes_IsVoteInProgress())
    {
        new 
iNumPlayers;
        
decl iPlayers[MaxClients];
        
        for (new 
i=1i<=MaxClientsi++)
        {
            if (!
IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) == L4D_TEAM_SPECTATE))
            {
                continue;
            }
            
iPlayers[iNumPlayers++] = i;
        }
        
        new 
String:sVote[64];
        
g_hDisableShutdownVote NativeVotes_Create(VoteActionHandler,  NativeVotesType_Custom_YesNoMenuAction_Cancel MenuAction_VoteEnd MenuAction_End);
        
        
Format(sVotesizeof(sVote), "Don't Allow Spawns To Shut Down?");
        
        
NativeVotes_SetTitle(g_hDisableShutdownVotesVote);
        
NativeVotes_SetInitiator(g_hDisableShutdownVoteclient);
        
NativeVotes_SetResultCallback(g_hDisableShutdownVoteVoteResultHandler);
        
NativeVotes_Display(g_hDisableShutdownVoteiPlayersiNumPlayers20);
        return 
true;
    }
    
    return 
false;
}

bool:StartEnableSpawnClearVote(client)
{
    if (!
NativeVotes_IsVoteInProgress())
    {
        new 
iNumPlayers;
        
decl iPlayers[MaxClients];
        
        for (new 
i=1i<=MaxClientsi++)
        {
            if (!
IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) == L4D_TEAM_SPECTATE))
            {
                continue;
            }
            
iPlayers[iNumPlayers++] = i;
        }
        
        new 
String:sVote[64];
        
g_hEnableShutdownVote NativeVotes_Create(VoteActionHandler,  NativeVotesType_Custom_YesNoMenuAction_Cancel MenuAction_VoteEnd MenuAction_End);
        
        
Format(sVotesizeof(sVote), "Allow Spawns To Shut Down?");
        
        
NativeVotes_SetTitle(g_hEnableShutdownVotesVote);
        
NativeVotes_SetInitiator(g_hEnableShutdownVoteclient);
        
NativeVotes_SetResultCallback(g_hEnableShutdownVoteVoteResultHandler);
        
NativeVotes_Display(g_hEnableShutdownVoteiPlayersiNumPlayers20);
        return 
true;
    }
    
    return 
false;
}

public 
VoteActionHandler(Handle:voteMenuAction:actionparam1param2)
{
    switch (
action)
    {
        case 
MenuAction_End:
        {
            
g_hDisableShutdownVote INVALID_HANDLE;
            
g_hEnableShutdownVote INVALID_HANDLE;
            
NativeVotes_Close(vote);
        }
        case 
MenuAction_VoteCancel:
        {
            switch (
param1)
            {
                case 
VoteCancel_Generic:
                {
                    
NativeVotes_DisplayFail(voteNativeVotesFail_Generic);
                }
                
                case 
VoteCancel_NoVotes:
                {
                    
NativeVotes_DisplayFail(voteNativeVotesFail_NotEnoughVotes);
                }
            }
        }
    }
}

public 
VoteResultHandler(Handle:votenum_votesnum_clients, const client_indexes[], const client_votes[], num_items, const item_indexes[], const item_votes[])
{
    for (new 
i=0i<num_itemsi++)
    {
        if (
item_indexes[i] == NATIVEVOTES_VOTE_YES)
        {
            if (
item_votes[i] > (num_clients 2))
            {
                if (
vote == g_hDisableShutdownVote)
                {
                    
NativeVotes_DisplayPass(vote"Disabling spawn clearing...");
                    
                    
DisableSpawnClear();
                    return;
                }
                else if (
vote == g_hEnableShutdownVote)
                {
                    
NativeVotes_DisplayPass(vote"Enabling spawn clearing...");
                    
                    
EnableSpawnClear();
                    return;
                }
            }
        }
    }
    
NativeVotes_DisplayFail(voteNativeVotesFail_Loses);

dustinandband is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 04-10-2017 , 19:14   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #5

(Definitely untested)

Code:
#include <sourcemod>
#include <nativevotes>

int votefor;

public Plugin:myinfo =
{
	name = "slots",
	author = "unknown",
	description = "Changes the slots",
	url = ""
}

public OnPluginStart()
{
	RegConsoleCmd("sm_slots", Slots_Vote, "Changes the slots");
	RegConsoleCmd("sm_slot", Slots_Vote, "Changes the slots");
}

public Action Slots_Vote(int client, int args)
{
	if (args != 1)
	{
		PrintToChat(client, "[SM] Invalid Usage: !slots <#>");
		return Plugin_Handled;
	}
	
	char sArgs[32];
	GetCmdArg(1, sArgs, sizeof(sArgs));
	int voteval = StringToInt(sArgs);
	
	if (voteval < 1 || voteval > 32)
	{
		PrintToChat(client, "[SM] Invalid Usage: value cannot be less than 1 or exceed 32.");
		return Plugin_Handled;
	}
	
	if (IsVoteInProgress())
	{
		PrintToChat(client, "[SM] You cannot start a vote while one is currently going.");
		return Plugin_Handled;
	}
	
	votefor = voteval;
	
	Handle vote = NativeVotes_Create(MenuHandler_VoteMaxSlots, NativeVotesType_Custom_YesNo);
	NativeVotes_SetInitiator(vote, client);
	
	char sDetails[256];
	FormatEx(sDetails, sizeof(sDetails), "Vote to change the maxslots value to %i?", votefor);
	NativeVotes_SetDetails(vote, sDetails);
	NativeVotes_DisplayToAll(vote, 20);
	
	return Plugin_Handled;
}

public int MenuHandler_VoteMaxSlots(Menu menu, MenuAction action, int param1, int param2)
{
	switch (action)
	{
		case MenuAction_VoteEnd:
		{
			if (param1 == NATIVEVOTES_VOTE_YES)
			{
				char sDetails[256];
				FormatEx(sDetails, sizeof(sDetails), "Maxslots changed to %i", votefor);
				NativeVotes_DisplayPass(menu, sDetails);
				
				SetConVarInt(FindConVar("sv_maxplayers"), votefor);
			}
			else
			{
				NativeVotes_DisplayFail(menu, NativeVotesFail_Loses);
			}
		}
		
		case MenuAction_VoteCancel:
		{
			if (param1 == VoteCancel_NoVotes)
			{
				NativeVotes_DisplayFail(menu, NativeVotesFail_NotEnoughVotes);
			}
			else
			{
				NativeVotes_DisplayFail(menu, NativeVotesFail_Generic);
			}
		}
		
		case MenuAction_End:
		{
			NativeVotes_Close(menu);
		}
	}
}
Drixevel is offline
dustinandband
Senior Member
Join Date: May 2015
Old 04-10-2017 , 21:11   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #6

Sent $20; very fast responses and worked on first try. Thanks so much
dustinandband is offline
dustinandband
Senior Member
Join Date: May 2015
Old 04-11-2017 , 10:49   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #7

Though I don't intend to add this into the plugin - just curious really - if I wanted to check one more thing before proceeding with the vote, would this be the correct format?

PHP Code:
// Check to see if current server slots are the same value as called vote

FindConVar("sv_maxplayers"Current_Slots_In_Use).
if (
voteval Current_Slots_In_Use)
    {
    
PrintToChat(client"Slots are already set to %i"voteval)
    return 
Plugin_Handled
    

Reason I ask is that the FindConVar only has one parameter: const char[] name. So I'm wondering how you'd tell the server to find whatever sv_maxplayers happens to be set to at the moment - then comparing it to the voteval integer.
dustinandband is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 04-11-2017 , 12:44   Re: [L4D2] $10 plugin job (requiring native votes)
Reply With Quote #8

Quote:
Originally Posted by dustinandband View Post
Though I don't intend to add this into the plugin - just curious really - if I wanted to check one more thing before proceeding with the vote, would this be the correct format?
FindConVar returns a ConVar handle; you can get the integer value of that ConVar using its IntValue property.

Code:
if (voteval == FindConVar("sv_maxplayers").IntValue) {
    PrintToChat(client, "Slots are already set to %i", voteval)
    return Plugin_Handled;
}
If you were to add a check for that, it'd be ideal to add it before NativeVotes_Create is called to avoid leaking handles.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 04-11-2017 at 12:46.
nosoop is offline
Reply



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 12:41.


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