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

CSGO in game map vote | EndMatchMapGroupVoteOptions


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-06-2016 , 09:12   CSGO in game map vote | EndMatchMapGroupVoteOptions
Reply With Quote #1

My little incomplete plugin.

This plugin disturb CSGO in game map vote at end of match.
It will now excluded previous maps from vote.

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

ArrayList EndMatchMapGroupVoteList// store and refresh mapgroup map list every map change and match end
StringMap EndMatchMapGroupVoteExcluded// store previous maps at end of match

int excluded_amount 5;

public 
void OnPluginStart()
{
    
EndMatchMapGroupVoteExcluded = new StringMap();    
    
HookEventEx("cs_win_panel_match"cs_win_panel_match); // Match totally ends
}

public 
OnConfigsExecuted()
{
    
RequestFrame(frame);
}

public 
void frame(any data)
{
    
// Need maplist for "nominate"
    
CreateMapList();
}

public 
void cs_win_panel_match(Event event, const char[] namebool dontBroadcast)
{
    
// Collect map list end of match, if mapgroup have changed to another
    //Note: If server change mapgroup in the middle of the game, players still have previous mapgroup maps in vote.
    //        Players need reconnect to server to update they list of maps.
    
CreateMapList();



    
// Keep count previous maps and how many times have excluded from vote
    
char buffer[PLATFORM_MAX_PATH];
    
int value;
    
StringMapSnapshot snapshot EndMatchMapGroupVoteExcluded.Snapshot();

    for(
int x 0snapshot.Lengthx++)
    {
        
snapshot.GetKey(xbuffersizeof(buffer));
        
EndMatchMapGroupVoteExcluded.GetValue(buffervalue);
        
EndMatchMapGroupVoteExcluded.SetValue(buffervalue+1true);
        
//PrintToServer("Excluded %i %s %i", x, buffer, value);

        
if(value >= excluded_amount)
        {
            
//PrintToServer("Remove %i %s %i", x, buffer, value);
            
EndMatchMapGroupVoteExcluded.Remove(buffer);
        }
    }

    
delete snapshot;

    
// Exclude current map from vote
    
GetCurrentMap(buffersizeof(buffer));
    
EndMatchMapGroupVoteExcluded.SetValue(buffer1true);
    
//PrintToServer("exclude new map %s", buffer);



    
int ent FindEntityByClassname(-1"cs_gamerules");

    if(
ent != -1)
    {
        
int VoteOptionArraySize GetEntPropArraySize(entProp_Send"m_nEndMatchMapGroupVoteOptions");
        
int[] VoteOptions = new int[VoteOptionArraySize];

        
// save given map indexs
        
for(int x 0VoteOptionArraySizex++)
        {
            
VoteOptions[x] = GameRules_GetProp("m_nEndMatchMapGroupVoteOptions"_x);
        }

        
bool VoteOptionAlready;

        for(
int x 0VoteOptionArraySizex++)
        {

            if(
VoteOptions[x] == -|| VoteOptions[x] >= EndMatchMapGroupVoteList.Length) return;

            
EndMatchMapGroupVoteList.GetString(VoteOptions[x], buffersizeof(buffer));
            
//PrintToServer("-option %i %s", x, buffer);

            // map have played newly
            
if(EndMatchMapGroupVoteExcluded.GetValue(buffervalue))
            {
                
//PrintToServer("-%i %s", VoteOptions[x], buffer);
                
for(int i 0EndMatchMapGroupVoteList.Lengthi++)
                {
                    
EndMatchMapGroupVoteList.GetString(ibuffersizeof(buffer));
                    
//PrintToServer("--%i %s", i, buffer);

                    
if(!EndMatchMapGroupVoteExcluded.GetValue(buffervalue))
                    {
                        for(
int l 0VoteOptionArraySizel++)
                        {
                            if(
VoteOptions[l] == i)
                            {
                                
//PrintToServer("SAME!!");
                                
VoteOptionAlready true;
                            }
                        }

                        if(
VoteOptionAlready)
                        {
                            
GameRules_SetProp("m_nEndMatchMapGroupVoteOptions", -1_xtrue);
                            
VoteOptionAlready false;
                            
i++;
                            continue;
                        }


                        
//PrintToServer("Change %i to %i", VoteOptions[x], i)
                        
VoteOptions[x] = i;
                        
GameRules_SetProp("m_nEndMatchMapGroupVoteOptions"i_xtrue);
                        break;
                    }                    
                }
            }
        }

    }
}


CreateMapList()
{
    if(
EndMatchMapGroupVoteList != nulldelete EndMatchMapGroupVoteList;
    
EndMatchMapGroupVoteList = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));

    
// I really hate to do this way, grab map list:(
    
char consoleoutput[5000];
    
ServerCommandEx(consoleoutputsizeof(consoleoutput), "print_mapgroup_sv");

    
int skip;
    
int sub;

    
char buffer[PLATFORM_MAX_PATH];
    
Regex regex = new Regex("^[[:blank:]]+(\\w.*)$"PCRE_MULTILINE);
    
    while( (
sub regex.Match(consoleoutput[skip])) > )
    {
        if(!
regex.GetSubString(0buffersizeof(buffer)))
        {
            break;
        }

        
skip += StrContains(consoleoutput[skip], buffer);
        
skip += strlen(buffer);

        for(
int x 1subx++)
        {
            if(!
regex.GetSubString(xbuffersizeof(buffer)))
            {
                break;
            }
            
EndMatchMapGroupVoteList.PushString(buffer); // Add also false maps to match vote indexs
        
}
    
    }
    
    
delete regex;
    

This grab current mapgroup map list from server command, print_mapgroup_sv
I couldn't find better way to get those and in right order.

There could be some flaw, example, if other plugin block server command print_mapgroup_sv, this plugin can't get maps from server console output text.

Another is, if some reason server command mapgroup change maplist to another in the middle of the game,
players still have previous mapgroup maplist in vote,
so in the end, server and player maps not match together in votes.
Can be check client side print_mapgroup and server side print_mapgroup_sv


But, here snip for anyone who interest.

*edit
I use workshop collection witch have lot of maps. It was annoying when same maps where bring in vote.
__________________
Do not Private Message @me

Last edited by Bacardi; 10-06-2016 at 09:14.
Bacardi is offline
 



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:19.


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