Raised This Month: $51 Target: $400
 12% 

Solved [CS:GO] Maxrounds vote


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
STiNG645
Junior Member
Join Date: Oct 2016
Location: Tashkent
Old 01-21-2023 , 03:36   [CS:GO] Maxrounds vote
Reply With Quote #1

I am sorry if there is such a request, I couldn't find one for sourcemod.
I'm looking for a plugin which initiates a vote for extend the mp_maxrounds (not mp_timelimit) in the last round for example by 10,15,20 or not to extend.
Please help.

Last edited by STiNG645; 01-26-2023 at 07:21.
STiNG645 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-22-2023 , 17:02   Re: Maxrounds vote
Reply With Quote #2

People should mention in first post, what game we talk about.

I assumed, cs:go

here one example.
- Plugin look events "round_announce_match_point" & "round_announce_final", and start vote after 2 seconds.
- Match point happen earlier, when losing team have no chance to win if winning team score one more time. (mp_match_can_clinch 1)
- Vote start once per match.
- If there is already another vote in progress, this plugin try create vote again after vote cooldown (sm_vote_delay),
plugin attempt this two times.
Of course if round end already, no vote.

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

enum
{
    
GAMEPHASE_WARMUP_ROUND,
    
GAMEPHASE_PLAYING_STANDARD,    
    
GAMEPHASE_PLAYING_FIRST_HALF,
    
GAMEPHASE_PLAYING_SECOND_HALF,
    
GAMEPHASE_HALFTIME,
    
GAMEPHASE_MATCH_ENDED,    
    
GAMEPHASE_MAX
};


ConVar mp_maxrounds;

public 
void OnPluginStart()
{
    
//RegConsoleCmd("sm_test", test);

    
HookEventEx("round_announce_match_point"events);
    
HookEventEx("round_announce_final"events);
    
HookEventEx("begin_new_match"events);

    
mp_maxrounds FindConVar("mp_maxrounds");

    if(
mp_maxrounds == null)
        
SetFailState("This game mod do not have ConVar mp_maxrounds");
}

public 
void events(Event event, const char[] namebool dontBroadcast)
{
    
//static bool round_announce_match_point = false;    // mp_match_can_clinch 1
    
static bool round_announce_final false;

    if(
StrEqual(name"begin_new_match"false))
    {
        
//round_announce_match_point = false;
        
round_announce_final false;
        return;
    }


    
//if(StrEqual(name, "round_announce_match_point", false))
    //{
    //    // Has been announced once.
    //    if(round_announce_match_point)
    //        return;
    //
    //    round_announce_match_point = true;
    //}

    //if(StrEqual(name, "round_announce_final", false))
    //{
    //    // Has been announced once.
    //    if(round_announce_final)
    //        return;
    //
    //    round_announce_final = true;
    //}


    
if(round_announce_final)
        return;

    
round_announce_final true;
    
StartVote();
}

public 
Action test(int clientint args)
{
    
//StartVote();
    
return Plugin_Handled;
}

void StartVote()
{
    
CreateTimer(2.0VoteStart0TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action VoteStart(Handle timerany data)
{
    static 
int x;

    if(
data == 0)
        
0;

    
// Do not create vote when mp_maxrounds is disabled, for some reason
    
if(mp_maxrounds.IntValue == 0)
        return 
Plugin_Continue;


    
// skip these phases
    
if(GameRules_GetProp("m_bWarmupPeriod"))
        return 
Plugin_Continue;

    if(!
GameRules_GetProp("m_bHasMatchStarted"))
        return 
Plugin_Continue;

    if(
GameRules_GetProp("m_bGameRestart"))
        return 
Plugin_Continue;

    
int gamephase GameRules_GetProp("m_gamePhase");
    
    if(
gamephase GAMEPHASE_PLAYING_STANDARD || gamephase GAMEPHASE_HALFTIME)
        return 
Plugin_Continue;



    if(
IsVoteInProgress())
    {
        
// When fail to create vote, try few times again.
        
if(data <= 2)
        {
            
float delay float(CheckVoteDelay());
            
CreateTimer(delayVoteStart, ++xTIMER_FLAG_NO_MAPCHANGE);
        }

        return 
Plugin_Continue;
    }


    
int targets[MAXPLAYERS+1];
    
int numtargets;

    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsFakeClient(i))
            continue;
        
        
targets[numtargets] = i;
        
numtargets++;
    }


    
Menu menu = new Menu(menu_handlerMenuAction_End)
    
    
menu.VoteResultCallback vote_handler;

    
menu.AddItem("10""+10");
    
menu.AddItem("15""+15");
    
menu.AddItem("20""+20");
    
menu.AddItem("0""No more rounds");
    
menu.ExitButton false;
    
menu.SetTitle("Vote Extend -> Max +Rounds");

    
menu.ShufflePerClient(0, -1);

    
menu.DisplayVote(targetsnumtargets10);

    return 
Plugin_Continue
}


public 
int menu_handler(Menu menuMenuAction actionint param1int param2)
{
    if(
action == MenuAction_End)
        
delete menu;

    return 
0;
}


public 
void vote_handler(Menu menuint num_votesint num_clients, const int[][] client_infoint num_items, const int[][] item_info)
{
    
int winner 0;

    if(
num_items &&
        
item_info[0][VOTEINFO_ITEM_VOTES] == item_info[1][VOTEINFO_ITEM_VOTES])
    {
        
winner GetRandomInt(01);
    }

    
char info[3], display[50];
    
menu.GetItem(item_info[winner][VOTEINFO_ITEM_INDEX], infosizeof(info), _displaysizeof(display), -1);

    
int extend StringToInt(info);

    if(
extend == 0)
    {
        
PrintToChatAll("[SM] Vote end: Vote result %s"display);
        return;
    }


    
int maxrounds mp_maxrounds.IntValue;

    if(
maxrounds == 0)
    {
        
LogError("Vote Extend Max Rounds: Cancel change mp_maxrounds cvar, mp_maxrounds value is 0 (disabled)");
        return;
    }

    
mp_maxrounds.IntValue maxrounds extend;

    
PrintToChatAll("[SM] Vote end: Vote result, extend rounds by %s"display);

__________________
Do not Private Message @me

Last edited by Bacardi; 01-22-2023 at 17:03.
Bacardi is offline
STiNG645
Junior Member
Join Date: Oct 2016
Location: Tashkent
Old 01-25-2023 , 12:24   Re: Maxrounds vote
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
People should mention in first post, what game we talk about.

I assumed, cs:go

here one example.
- Plugin look events "round_announce_match_point" & "round_announce_final", and start vote after 2 seconds.
- Match point happen earlier, when losing team have no chance to win if winning team score one more time. (mp_match_can_clinch 1)
- Vote start once per match.
- If there is already another vote in progress, this plugin try create vote again after vote cooldown (sm_vote_delay),
plugin attempt this two times.
Of course if round end already, no vote.

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

enum
{
    
GAMEPHASE_WARMUP_ROUND,
    
GAMEPHASE_PLAYING_STANDARD,    
    
GAMEPHASE_PLAYING_FIRST_HALF,
    
GAMEPHASE_PLAYING_SECOND_HALF,
    
GAMEPHASE_HALFTIME,
    
GAMEPHASE_MATCH_ENDED,    
    
GAMEPHASE_MAX
};


ConVar mp_maxrounds;

public 
void OnPluginStart()
{
    
//RegConsoleCmd("sm_test", test);

    
HookEventEx("round_announce_match_point"events);
    
HookEventEx("round_announce_final"events);
    
HookEventEx("begin_new_match"events);

    
mp_maxrounds FindConVar("mp_maxrounds");

    if(
mp_maxrounds == null)
        
SetFailState("This game mod do not have ConVar mp_maxrounds");
}

public 
void events(Event event, const char[] namebool dontBroadcast)
{
    
//static bool round_announce_match_point = false;    // mp_match_can_clinch 1
    
static bool round_announce_final false;

    if(
StrEqual(name"begin_new_match"false))
    {
        
//round_announce_match_point = false;
        
round_announce_final false;
        return;
    }


    
//if(StrEqual(name, "round_announce_match_point", false))
    //{
    //    // Has been announced once.
    //    if(round_announce_match_point)
    //        return;
    //
    //    round_announce_match_point = true;
    //}

    //if(StrEqual(name, "round_announce_final", false))
    //{
    //    // Has been announced once.
    //    if(round_announce_final)
    //        return;
    //
    //    round_announce_final = true;
    //}


    
if(round_announce_final)
        return;

    
round_announce_final true;
    
StartVote();
}

public 
Action test(int clientint args)
{
    
//StartVote();
    
return Plugin_Handled;
}

void StartVote()
{
    
CreateTimer(2.0VoteStart0TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action VoteStart(Handle timerany data)
{
    static 
int x;

    if(
data == 0)
        
0;

    
// Do not create vote when mp_maxrounds is disabled, for some reason
    
if(mp_maxrounds.IntValue == 0)
        return 
Plugin_Continue;


    
// skip these phases
    
if(GameRules_GetProp("m_bWarmupPeriod"))
        return 
Plugin_Continue;

    if(!
GameRules_GetProp("m_bHasMatchStarted"))
        return 
Plugin_Continue;

    if(
GameRules_GetProp("m_bGameRestart"))
        return 
Plugin_Continue;

    
int gamephase GameRules_GetProp("m_gamePhase");
    
    if(
gamephase GAMEPHASE_PLAYING_STANDARD || gamephase GAMEPHASE_HALFTIME)
        return 
Plugin_Continue;



    if(
IsVoteInProgress())
    {
        
// When fail to create vote, try few times again.
        
if(data <= 2)
        {
            
float delay float(CheckVoteDelay());
            
CreateTimer(delayVoteStart, ++xTIMER_FLAG_NO_MAPCHANGE);
        }

        return 
Plugin_Continue;
    }


    
int targets[MAXPLAYERS+1];
    
int numtargets;

    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsFakeClient(i))
            continue;
        
        
targets[numtargets] = i;
        
numtargets++;
    }


    
Menu menu = new Menu(menu_handlerMenuAction_End)
    
    
menu.VoteResultCallback vote_handler;

    
menu.AddItem("10""+10");
    
menu.AddItem("15""+15");
    
menu.AddItem("20""+20");
    
menu.AddItem("0""No more rounds");
    
menu.ExitButton false;
    
menu.SetTitle("Vote Extend -> Max +Rounds");

    
menu.ShufflePerClient(0, -1);

    
menu.DisplayVote(targetsnumtargets10);

    return 
Plugin_Continue
}


public 
int menu_handler(Menu menuMenuAction actionint param1int param2)
{
    if(
action == MenuAction_End)
        
delete menu;

    return 
0;
}


public 
void vote_handler(Menu menuint num_votesint num_clients, const int[][] client_infoint num_items, const int[][] item_info)
{
    
int winner 0;

    if(
num_items &&
        
item_info[0][VOTEINFO_ITEM_VOTES] == item_info[1][VOTEINFO_ITEM_VOTES])
    {
        
winner GetRandomInt(01);
    }

    
char info[3], display[50];
    
menu.GetItem(item_info[winner][VOTEINFO_ITEM_INDEX], infosizeof(info), _displaysizeof(display), -1);

    
int extend StringToInt(info);

    if(
extend == 0)
    {
        
PrintToChatAll("[SM] Vote end: Vote result %s"display);
        return;
    }


    
int maxrounds mp_maxrounds.IntValue;

    if(
maxrounds == 0)
    {
        
LogError("Vote Extend Max Rounds: Cancel change mp_maxrounds cvar, mp_maxrounds value is 0 (disabled)");
        return;
    }

    
mp_maxrounds.IntValue maxrounds extend;

    
PrintToChatAll("[SM] Vote end: Vote result, extend rounds by %s"display);

Yes, it was needed for CS:GO. Sorry, I forgot to mention.
The plugin works as expected. Thank you very much.
Is there a way to change the vote menu numbers? Not 1,2,3,4, but 6,7,8,9?

Last edited by STiNG645; 01-25-2023 at 12:44.
STiNG645 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-25-2023 , 14:43   Re: Maxrounds vote
Reply With Quote #4

PHP Code:
//training.train_idtestwaiting_02
//training.train_idtestwaiting_01
//training.train_failure_03b
//training.train_failure_02
//training.train_bombplantbfail_03
//Survival.BeaconGlobal
//UIPanorama.round_report_round_won

char gamesound[] = "UIPanorama.round_report_round_won";

#include <cstrike>
#include <sdktools>

enum
{
    
GAMEPHASE_WARMUP_ROUND,
    
GAMEPHASE_PLAYING_STANDARD,    
    
GAMEPHASE_PLAYING_FIRST_HALF,
    
GAMEPHASE_PLAYING_SECOND_HALF,
    
GAMEPHASE_HALFTIME,
    
GAMEPHASE_MATCH_ENDED,    
    
GAMEPHASE_MAX
};




ConVar mp_maxrounds;

public 
void OnPluginStart()
{
    
//RegConsoleCmd("sm_test", test);

    
HookEventEx("round_announce_match_point"events);
    
HookEventEx("round_announce_final"events);
    
HookEventEx("begin_new_match"events);

    
mp_maxrounds FindConVar("mp_maxrounds");

    if(
mp_maxrounds == null)
        
SetFailState("This game mod do not have ConVar mp_maxrounds");
}

public 
void events(Event event, const char[] namebool dontBroadcast)
{
    
//static bool round_announce_match_point = false;    // mp_match_can_clinch 1
    
static bool round_announce_final false;

    if(
StrEqual(name"begin_new_match"false))
    {
        
//round_announce_match_point = false;
        
round_announce_final false;
        return;
    }


    
//if(StrEqual(name, "round_announce_match_point", false))
    //{
    //    // Has been announced once.
    //    if(round_announce_match_point)
    //        return;
    //
    //    round_announce_match_point = true;
    //}

    //if(StrEqual(name, "round_announce_final", false))
    //{
    //    // Has been announced once.
    //    if(round_announce_final)
    //        return;
    //
    //    round_announce_final = true;
    //}


    
if(round_announce_final)
        return;

    
round_announce_final true;
    
StartVote();
}

public 
Action test(int clientint args)
{
    
//StartVote();
    
return Plugin_Handled;
}

void StartVote()
{
    
CreateTimer(2.0VoteStart0TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action VoteStart(Handle timerany data)
{
    static 
int x;

    if(
data == 0)
        
0;

    
// Do not create vote when mp_maxrounds is disabled, for some reason
    
if(mp_maxrounds.IntValue == 0)
        return 
Plugin_Continue;


    
// skip these phases
    
if(GameRules_GetProp("m_bWarmupPeriod"))
        return 
Plugin_Continue;

    if(!
GameRules_GetProp("m_bHasMatchStarted"))
        return 
Plugin_Continue;

    if(
GameRules_GetProp("m_bGameRestart"))
        return 
Plugin_Continue;

    
int gamephase GameRules_GetProp("m_gamePhase");
    
    if(
gamephase GAMEPHASE_PLAYING_STANDARD || gamephase GAMEPHASE_HALFTIME)
        return 
Plugin_Continue;



    if(
IsVoteInProgress())
    {
        
// When fail to create vote, try few times again.
        
if(data <= 2)
        {
            
float delay float(CheckVoteDelay());
            
CreateTimer(delayVoteStart, ++xTIMER_FLAG_NO_MAPCHANGE);
        }

        return 
Plugin_Continue;
    }


    
int targets[MAXPLAYERS+1];
    
int numtargets;

    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsFakeClient(i))
            continue;
        
        
targets[numtargets] = i;
        
numtargets++;
    }

    if(
numtargets == 0)
        return 
Plugin_Handled;

    
Menu menu = new Menu(menu_handlerMenuAction_End|MenuAction_VoteCancel)
    
menu.Pagination MENU_NO_PAGINATION;
    
    
menu.VoteResultCallback vote_handler;

    
menu.AddItem("0""-Disabled-"ITEMDRAW_SPACER);
    
menu.AddItem("0""-Disabled-"ITEMDRAW_SPACER);
    
menu.AddItem("0""-Disabled-"ITEMDRAW_SPACER);
    
menu.AddItem("0""-Disabled-"ITEMDRAW_SPACER);
    
menu.AddItem("10""+10");
    
menu.AddItem("15""+15");
    
menu.AddItem("20""+20");
    
menu.AddItem("0""No more rounds");
    
menu.ExitButton false;
    
menu.SetTitle("Vote Extend -> Max +Rounds");

    
menu.ShufflePerClient(4, -1);

    
menu.DisplayVote(targetsnumtargets10);


    
EmitGameSound(targets,
                    
numtargets,
                    
gamesound);


    return 
Plugin_Continue
}


public 
int menu_handler(Menu menuMenuAction actionint param1int param2)
{
    if(
action == MenuAction_VoteCancel && param1 == VoteCancel_NoVotes)
    {
        
PrintToChatAll("[SM] Vote End: No votes");
    }
    else if(
action == MenuAction_End)
    {
        
delete menu;
    }

    return 
0;
}


public 
void vote_handler(Menu menuint num_votesint num_clients, const int[][] client_infoint num_items, const int[][] item_info)
{
    
int winner 0;

    if(
num_items &&
        
item_info[0][VOTEINFO_ITEM_VOTES] == item_info[1][VOTEINFO_ITEM_VOTES])
    {
        
winner GetRandomInt(01);
    }

    
char info[3], display[50];
    
menu.GetItem(item_info[winner][VOTEINFO_ITEM_INDEX], infosizeof(info), _displaysizeof(display), -1);

    
int extend StringToInt(info);

    if(
extend == 0)
    {
        
PrintToChatAll("[SM] Vote end: Vote result %s"display);
        return;
    }


    
int maxrounds mp_maxrounds.IntValue;

    if(
maxrounds == 0)
    {
        
LogError("Vote Extend Max Rounds: Cancel change mp_maxrounds cvar, mp_maxrounds value is 0 (disabled)");
        return;
    }

    
mp_maxrounds.IntValue maxrounds extend;

    
PrintToChatAll("[SM] Vote end: Vote result, extend rounds by %s"display);

__________________
Do not Private Message @me
Bacardi is offline
STiNG645
Junior Member
Join Date: Oct 2016
Location: Tashkent
Old 01-26-2023 , 07:15   Re: Maxrounds vote
Reply With Quote #5

Didn't expect such a quality plugin! Thanks a lot
STiNG645 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 19:56.


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