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

pls help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
songoku2
New Member
Join Date: Aug 2020
Old 09-19-2020 , 04:11   pls help
Reply With Quote #1

I need help to do that if you click no then it cancels that you can buy grenades but if you click yes it is possible to buy four grenades in the vote menu
---------------------------------------------------------------

Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

public Plugin myinfo = 
{
	name = "test",
	author = "me",
	description = "idk",
	version = "1.00",
	url = ""
};

ConVar ammo_grenade_limit_total;

public void OnPluginStart()
{
	ammo_grenade_limit_total = FindConVar("ammo_grenade_limit_total");
	RegConsoleCmd("sm_votegrenades", Command_Vote, "test");
}


public Action Command_Vote(int client, int args)
{
	Menu menu = new Menu(Menu_Callback);
	menu.SetTitle("Vote Grenades: ");
	menu.AddItem("yes", "Yes");
	menu.AddItem("no", "No");
	menu.DisplayVoteToAll(client, 15);
	return Plugin_Handled;
}

public int Menu_Callback(Menu menu, MenuAction action, int param1, int param2)
{
	switch (action) {
		case MenuAction_Select:
		{
			char item[32];
			menu.GetItem(param2, item, sizeof(item));
			
			if (StrEqual(item, "yes")) 
			{
				SetConVarInt(ammo_grenade_limit_total, 1, false, false);
				PrintToChatAll("\x04[VoteGrenades]\x01 The vote is over, The result is \x07Yes\x01");
			}
			else if (StrEqual(item, "no")) 
			{
				PrintToChatAll("\x04[VoteGrenades]\x01 The vote is over, The result is \x07No\x01");
			}
		}
		case MenuAction_End:
		{
			delete menu;
		}
	}
}

Last edited by songoku2; 09-19-2020 at 04:12.
songoku2 is offline
Cruze
Veteran Member
Join Date: May 2017
Old 09-20-2020 , 13:02   Re: pls help
Reply With Quote #2

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma newdecls required
#pragma semicolon 1

public Plugin myinfo 
{
    
name "Vote Grenades",
    
author "Cruze",
    
description "Vote for toggling grenades",
    
version "1.0",
    
url "http://steamcommunity.com/profiles/76561198132924835 | Cruze#4947"
};

ConVar ammo_grenade_limit_total;
Handle g_hEndVoteGrenadesVote;
bool g_Vote;
int g_iVoted;
bool g_bGrenade[MAXPLAYERS+1];

public 
void OnPluginStart()
{
    
ammo_grenade_limit_total FindConVar("ammo_grenade_limit_total");
    
RegConsoleCmd("sm_votegrenades"Command_Vote"Start a vote grenades vote.");
}

public 
void OnMapStart()
{
    
g_Vote false;
    
g_hEndVoteGrenadesVote null;
}

public 
void OnClientPutInServer(int client)
{
    
g_bGrenade[client] = false;
}

public 
Action Command_Vote(int clientint args)
{
    if(
g_Vote || IsVoteInProgress())
    {
        
ReplyToCommand(client"[SM] There is already a vote going on.");
        return 
Plugin_Handled;
    }
    
StartVoteGrenadesMenu();
    
PrintToChatAll("[SM] Vote grenades vote started by %N"client);
    return 
Plugin_Handled;
}

stock void StartVoteGrenadesMenu()
{
    if(
g_hEndVoteGrenadesVote != null)
    {
        
KillTimer(g_hEndVoteGrenadesVote);
        
g_hEndVoteGrenadesVote null;
    }
    
g_Vote true;
    
g_iVoted 0;
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && !IsClientSourceTV(i))
        {
            if(!
IsFakeClient(i))
            {
                
g_bGrenade[i] = false;
                
VoteGrenades(i);
            }
            else
            {
                
g_bGrenade[i] = true;
                
g_iVoted++;
            }
        }
    }
    
g_hEndVoteGrenadesVote CreateTimer(20.1Timer_EndVoteGrenadesVote_TIMER_FLAG_NO_MAPCHANGE);
}

stock void VoteGrenades(int client)
{
    
Menu menu = new Menu(Handler_VoteGrenades);
    
menu.SetTitle("Vote Grenades:");
    
menu.AddItem("yes""Yes");
    
menu.AddItem("no""No");
    
menu.Display(client20);
}

public 
int Handler_VoteGrenades(Menu menuMenuAction actionint clientint item)
{
    if (
action == MenuAction_End)
    {
        
delete menu;
    }
    else if (
action == MenuAction_Select)
    {
        if(
item == 0)
        {
            
g_bGrenade[client] = true;
        }
        else
        {
            
g_bGrenade[client] = false;
        }
        
g_iVoted++;
        if(
g_iVoted >= GetPlayerCount() && g_hEndVoteGrenadesVote != null)
        {
            
TriggerTimer(g_hEndVoteGrenadesVote);
        }
    }
}

public 
Action Timer_EndVoteGrenadesVote(Handle timer)
{
    
int totalcount;
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && !IsClientSourceTV(i))
        {
            if(
g_bGrenade[i])
            {
                
count++;
            }
            
total++;
        }
    }
    
int percentage = (count/total)*100;
    if(
percentage >= 80)
    {
        
Toggle();
        
g_hEndVoteGrenadesVote null;
        
g_Vote false;
        return;
    }
    
PrintToChatAll("[SM] The vote failed. Required percentage = 80%%, got %d%%"percentage);
    
g_hEndVoteGrenadesVote null;
    
g_Vote false;
}

void Toggle()
{
    if(
ammo_grenade_limit_total.IntValue)
    {
        
ammo_grenade_limit_total.IntValue 0;
    }
    else
    {
        
ammo_grenade_limit_total.IntValue 1;
    }
}

stock int GetPlayerCount()
{
    
int count;
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && !IsClientSourceTV(i))
        {
            
count++;
        }
    }
    return 
count;

Took this from another plugin of mine which was working but this is untested. This may not be the best way to do it, but this is how I do it ._.
Attached Files
File Type: sp Get Plugin or Get Source (VoteGrenades.sp - 50 views - 3.1 KB)
__________________
Taking paid private requests! Contact me

Last edited by Cruze; 09-20-2020 at 13:04. Reason: Attached source in attachment so that you can just click "Get Plugin"
Cruze 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 04:53.


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