June 28, 2022, 01:16:52 pm

The Gang Garrison 2 Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

NOTICE: Due to a rise in bot activity, new posters need to be approved before posting.

Join the community Discord server!

Pages: 1 2 3 [4]

Author Topic: Map Voting: Redux 2020 Edition! [serverplugin]  (Read 7294 times)

ajf

  • (Ex-?)Developer and forum/web admin
  • *****
  • Karma: 7
  • Offline Offline
  • Posts: 3492
  • she's never quite as dead as you think
Re: [Best Plugin] Map Voting! [serverplugin][UPDATED]
« Reply #45 on: July 08, 2013, 04:15:47 pm »

Nah, it did that prior to the update.

It might be that the forced restart from plugin installation fucks it over, but I'm not sure.
Hmm. In some setups, where the working directory and folder where GG2 is actually stored differ, it would break.
Logged
aka Andrea.

did you know that spinning stars work like this???

I've seen things you people wouldn't believe. execute_strings on fire off the shoulder of Overmars. I watched object-beams glitter in the dark near the room_goto_fix. All those moments will be lost in time, like tears...in...rain. Time to die.

Machidro

  • 2013 Haxxy Award Winner
  • *
  • Karma: 5
  • Offline Offline
  • Posts: 1675
  • Gardicolo time is over.
Re: Map Voting: Redux 2020 Edition! [serverplugin]
« Reply #46 on: August 13, 2020, 12:52:49 am »

The plugin has been updated for 2.9.2!

Updated code because it's literally too big for the OP to handle.

Part one of multiple that need to be stitched together into one file:

Code: [Select]
//////////////////////////////////////////////////////////////////////////

// Machidro's Map Voting plugin
// Plugin Config

// META SETTINGS:

// ParamName: PluginEnabled
// Turns all features of the Map Voting Plugin on on off
// Options: true or false
// Default: true

PluginEnabled = true;

// ParamName: DefaultSettings
// If true, overwrites the rest of the config below with known good voting settings that will work out of box.
// Options: true or false
// Default: true

DefaultSettings = true;

////////////////////////////////////////////////////////////////////////////////////

// MANUAL CONFIG OPTIONS:
// (DefaultSettings above overwrites these, make sure you have it set to false if you want to change things.)

global.mapVotingSettings = ds_map_create();

// ParamName: StartServerWithVote
// If true, the first map when booting up a server will be a vote.
// Default: true
ds_map_add(global.mapVotingSettings, "StartServerWithVote", true);

// ParamName: LogResults
// If true, logs the results of map votes to a csv file which you can analyze later to see more information about your votes
// Default: True
ds_map_add(global.mapVotingSettings, "LogResults", true);

// ParamName: ResultsLogFileName
// if logging is enabled, the file to store logs into.
// Will be created if it does not already exist.
// Default: mapVotingResults.csv
ds_map_add(global.mapVotingSettings, "ResultsLogFileName", "mapVotingResults.csv");

// ParamName: VoteCapPlayerSeconds
// Each player generates 30 points of votes per second,
// This value is how many player seconds are needed to conclude a vote when a single player is voting alone for a single map (more people, faster vote)
// Default: 25 seconds
ds_map_add(global.mapVotingSettings, "VoteCapPlayerSeconds", 25 * 30);

// ParamName: LockedPointSeconds
// When map voting, how long to keep the points locked before revealing the maps to allow people to connect and choose characters.
// Default: 5 seconds.
ds_map_add(global.mapVotingSettings, "LockedPointSeconds", 5 * 30);

// ParamName TooSmallForVotes
// If true, don't hold votes on servers with too few players (count set below)
// Default: false
ds_map_add(global.mapVotingSettings, "TooSmallForVotes", false);

// ParamName: TooSmallForVotesCap
// If the TooSmallForVotes setting is enabled, sets the max player cap for the plugin - if you have more players than the below, votes will be held.
// Default: 2 players
ds_map_add(global.mapVotingSettings, "TooSmallForVotesCap", 2);

// ParamName: useRandomMapCategories
// Sets if the plugin will give a category hint about what the third random map is.
// Three possible options:
// 0: Do not show a category/hint for the third random map.
// 1: From all maps, use the maps name to intelligently extract a mode which will be used as the hint
// 2: In addition to the above category parsing, parse a csv category file that contains map names, followed by a comma, then the category hint, to write your own hints for maps
// Default: 1
ds_map_add(global.mapVotingSettings, "useRandomMapCategories", 1);

// ParamName: customCategoryMapFileName
// If "useRandomMapCategories" is 2, Allows the user to define the category hint text
// to display for their maps to display for the map when random rolls it
// Format is a csv file without a header filled with UNIQUE pairs in format:
// mapname,category text
// eg:
// cp_dirtbowl,long AD/C
// rj_toohardforsecretman,hard RJ
// dkoth_atalia,strange dkoth
// You don't need a pair for every map, and maps without a uniquely defined pair will default to mode.
// Default: mapCategories.csv
ds_map_add(global.mapVotingSettings, "customCategoryMapFileName", "mapCategories.csv");


/////////////////////////////////////////////////////////////////////////////
// INTERNAL GLOBALS AND CONSTANTS

// mapRotationParsed - list of valid maps to roll within
ds_map_add(global.mapVotingSettings, "mapRotationParsed", ds_list_create());

// mapRotationCategoryMappings - map of map names to associated hints
ds_map_add(global.mapVotingSettings, "mapRotationCategoryMappings", ds_map_create());

// randomMaps - a subset of the map rotation that players are voting on, default of size three
ds_map_add(global.mapVotingSettings, "randomMaps", ds_list_create());
ds_map_add(global.mapVotingSettings, "voteMapCount", 3);

// timeTillPrompt - countdown used to syncc notifications between hud, server and other elements
ds_map_add(global.mapVotingSettings, "timeTillPrompt", 30);
ds_map_add(global.mapVotingSettings, "prompted", false);

// generateNewMaps - if the server finds we're not voting and this is true, it will regenerate new maps
ds_map_add(global.mapVotingSettings, "generateNewMaps", false);

// mapVotingMaps - as long as it has map_voting in the name, we treat it as a map_voting map
ds_map_add(global.mapVotingSettings, "mapVotingMaps", ds_list_create());

/////////////////////////////////////////////////////////////////////////////


// Run the plugin setup if enabled
if (PluginEnabled) {
    if (DefaultSettings) {
        ds_map_replace(global.mapVotingSettings, "StartServerWithVote", true);
ds_map_replace(global.mapVotingSettings, "LogResults", true );
ds_map_replace(global.mapVotingSettings, "ResultsLogFileName", "mapVotingResults.csv" );
ds_map_replace(global.mapVotingSettings, "VoteCapPlayerSeconds", 25 * 30 );
        ds_map_replace(global.mapVotingSettings, "LockedPointSeconds", 5 * 30);       
ds_map_replace(global.mapVotingSettings, "TooSmallForVotes", false);
        ds_map_replace(global.mapVotingSettings, "TooSmallForVotesCap", 2);
ds_map_replace(global.mapVotingSettings, "useRandomMapCategories", 1);
ds_map_replace(global.mapVotingSettings, "customCategoryMapFileName", "mapCategories.csv" );
}

    // Validate the rotation is plugin valid, and if not, disable t he plugin
    validationPassing = true;
    mapCount = 0;

    // Unpack the parsed map list for easy reference
    mapParsedList = ds_map_find_value(global.mapVotingSettings, "mapRotationParsed");
    mapVotingMaps =  ds_map_find_value(global.mapVotingSettings, "mapVotingMaps");
    mapCategoryMapping = ds_map_find_value(global.mapVotingSettings, "mapRotationCategoryMappings");
    useRandomMapCategories = ds_map_find_value(global.mapVotingSettings, "useRandomMapCategories");
    logFileName = ds_map_find_value(global.mapVotingSettings, "ResultsLogFileName");
    isLoggingOn = ds_map_find_value(global.mapVotingSettings, "LogResults");

    //Initialize the log writing file and its header if it doesn't exist and is on
    if (isLoggingOn) {
        if (!file_exists(logFileName))
        {
            var fileHandle;
            fileHandle = file_text_open_write(logFileName);
            file_text_write_string(fileHandle, "voteTime,playerCount,serverMaxPlayerCount,map1name,map2name,randomSecretMapName,map1vote%,map2vote%,randomMapVote%");
            file_text_writeln(fileHandle);
            file_text_close(fileHandle);
        }
    }

    // Go in reverse - we delete map voting maps from the rotation so when we roll random maps we don't roll into map votings.
    for (i = ds_list_size(global.map_rotation) - 1; i >= 0; i -= 1) {
        currMap = ds_list_find_value(global.map_rotation, i);
       
        // We need to validate any map we'd random to exists to avoid breaking things.
        if ((findInternalMapName(currMap) != "" or file_exists("Maps/" + currMap + ".png"))) {
            if (string_pos("map_voting", string_lower(currMap)) == 0) {
                // not map voting.
                mapCount += 1;
                ds_list_insert(mapParsedList, 0, currMap);
            }  else {
                // map is a map voting map and we don't include those in the rotation
                ds_list_add(mapVotingMaps, currMap);
                ds_list_delete(global.map_rotation, i);
            }
        }
    }

    // We need at least three non-map_voting maps to hold votes.
    if (mapCount < 3 || ds_list_size(mapVotingMaps) == 0 ) {
        validationPassing = false;
        show_error("Error in Map Voting settings: you need at least one map_voting map in your rotation to be used for votes and you need at least 3 other types of maps in your rotation to use map voting.", false);
    }

    // Parse the category file or generate categories mappings before continuing
    if (validationPassing) {
        if (useRandomMapCategories > 0) {
            //User is requesting prefix categories to be generated on their behalf.
            for (i = 0; i < ds_list_size(mapParsedList); i += 1) {
                currMap = ds_list_find_value(mapParsedList, i);
                prefixStr = "";
                indexOfUnderscore = string_pos("_", currMap);

                // Collect all characters up to the prefix
                if (indexOfUnderscore != 0) {
                    prefixStr = string_copy(currMap, 1, indexOfUnderscore - 1);
                } else {
                    mapNameNormalized = string_lower(currMap);

                    // The user has requested a map without an underscore mode prefix. Try intelligent parsing as best as we can.
                    if (string_pos("koth", mapNameNormalized) == 1) {
                        prefixStr = "koth";
                    } else if (string_pos("dkoth", mapNameNormalized) == 1) {
                        prefixStr = "dkoth";
                    } else if (string_pos("ctf", mapNameNormalized) == 1) {
                        prefixStr = "ctf";
                    } else if (string_pos("rj", mapNameNormalized) == 1) {
                        prefixStr = "rj";
                    } else if (string_pos("dj", mapNameNormalized) == 1) {
                        prefixStr = "dj";
                    } else if (string_pos("bball", mapNameNormalized) == 1) {
                        prefixStr = "bball";
                    } else if (string_pos("gen", mapNameNormalized) == 1) {
                        prefixStr = "gen";
                    } else if (string_pos("arena", mapNameNormalized) == 1) {
                        prefixStr = "arena";
                    } else if (string_pos("2cp", mapNameNormalized) == 1) {
                        prefixStr = "2cp";
                    } else if (string_pos("3cp", mapNameNormalized) == 1) {
                        prefixStr = "3cp";
                    } else if (string_pos("4cp", mapNameNormalized) == 1) {
                        prefixStr = "4cp";
                    } else if (string_pos("5cp", mapNameNormalized) == 1) {
                        prefixStr = "5cp";
                    } else if (string_pos("cp", mapNameNormalized) == 1) {
                        prefixStr = "cp";
                    } else if (string_pos("dm", mapNameNormalized) == 1) {
                        prefixStr = "dm";
                    } else if (string_pos("tdm", mapNameNormalized) == 1) {
                        prefixStr = "tdm";
                    } else {
                        prefixStr = string_copy(currMap, 1, 5); // We've got no clue how to parse this - take 5 characters and call it a day.
                    }
                }

                ds_map_add(mapCategoryMapping, currMap, prefixStr);
            }   
        }
        if (useRandomMapCategories == 2) {
            // The user has requested additional custom categories
            fileName = ds_map_find_value(global.mapVotingSettings, "customCategoryMapFileName");
            //User wants hand-generated categories
            if (!file_exists(fileName))
            {
                // User is missing the needed category mapping file for their settings
                show_error("Error in Customized Map Voting settings: your filename for the random maps category mapping is invalid. To fix this, check the top of your map_voting plugin for the category file path, and make sure it exists, that it has no header, and all rows are in the correct format of MAPNAME,CATEGORY.", false);
                validationPassing = false;
            } else {
                // Parse the category map file
                var fileHandle;
                fileHandle = file_text_open_read(fileName);
                while (!file_text_eof(fileHandle))
                {
                    mapCatPair = file_text_read_string(fileHandle);
                    file_text_readln(fileHandle);
                    indexOfCommaDelim = string_pos(",", mapCatPair);
                    if (indexOfCommaDelim != 0) {
                        mapName = string_copy(mapCatPair, 1, indexOfCommaDelim - 1);
                        lenStrEnd = string_length(mapCatPair) - string_length(mapName) - 1;
                        mapCategory = string_copy(mapCatPair, indexOfCommaDelim + 1, lenStrEnd);

                        ds_map_replace(mapCategoryMapping, mapName, mapCategory);
                    }
                }
                file_text_close(fileHandle);
            }
        }
    }

    // Set up the parsed rotation for play
    if (validationPassing) {
        randomMaps = ds_map_find_value(global.mapVotingSettings, "randomMaps");
        mapCount = ds_map_find_value(global.mapVotingSettings, "voteMapCount");
        mapsFound = 0;

        // No sets in GML is suffering. We'll make do with a map.
        mapSet = ds_map_create();
        ds_list_shuffle(mapParsedList);
        ds_list_clear(randomMaps);

        // Find three unique candidate maps not in the set
        for (i = 0; i < ds_list_size(mapParsedList); i += 1) {
            mapName = ds_list_find_value(mapParsedList, i);
            if (!(ds_map_find_value(mapSet, mapName)))
            {
                ds_map_add(mapSet, mapName, true);
                ds_list_add(randomMaps, mapName);
                mapsFound += 1;
            }

            if (mapsFound >= mapCount) {
                break;
            }
        }

        ds_list_destroy(mapSet);
    }

    // If the user wants to start their servers with a vote, let them.
    if (ds_map_find_value(global.mapVotingSettings, "StartServerWithVote")) {
        mapVotingMaps = ds_map_find_value(global.mapVotingSettings, "mapVotingMaps");
        ds_list_shuffle(mapVotingMaps);
        ds_list_insert(global.map_rotation, 0, ds_list_find_value(mapVotingMaps, 0));
    }

    //Useful logging code to test randomization stuff:
    // show_message("FINAL: map one: "
    //                 + ds_list_find_value(randomMaps, 0) + ", cat: " + ds_map_find_value(mapCategoryMapping, ds_list_find_value(randomMaps, 0))
    //                 + ", map two: "
    //                 + ds_list_find_value(randomMaps, 1) + ", cat: " + ds_map_find_value(mapCategoryMapping, ds_list_find_value(randomMaps, 1))
    //                 + ", map three: "
    //                 + ds_list_find_value(randomMaps, 2) + ", cat: " + ds_map_find_value(mapCategoryMapping, ds_list_find_value(randomMaps, 2))
    //                 );

}

// Alter code in other objects to handle map voting content if enabled
if (PluginEnabled) {
    // Make control points on maps with "map_voting" in the name work special.
    object_event_add(ControlPoint, ev_create, 0, '
        map_voting_lock_time = ds_map_find_value(global.mapVotingSettings, "LockedPointSeconds");
        onMapVoting = false;
        if (string_pos("map_voting", string_lower(global.currentMap)) != 0) {
            onMapVoting = true;
        }
        mapVotingCapTime = ds_map_find_value(global.mapVotingSettings, "VoteCapPlayerSeconds");
    ');

    object_event_clear(ControlPoint,ev_step, 0)
    object_event_add(ControlPoint, ev_step, 0, '
        //if on map voting, raise the captime limit to make sure
        if (onMapVoting && capTime != mapVotingCapTime) {
            capTime = mapVotingCapTime;
        }

        alpha += fade;
        if(alpha >= 1) {
            fade = -0.05 * global.delta_factor;
        } else if(alpha <= 0) {
            fade = 0.05 * global.delta_factor;
        }

        var arenaRoundEnd;
        arenaRoundEnd = false;
        if(mode == 2) {
            if(ArenaHUD.state == ArenaHUD.ARENA_STATE_ROUND_END) arenaRoundEnd=true;
        } else if (mode == 4) { 
            if (DKothHUD.cpUnlock>0)
                locked = true;
            else //bruteforce because the below code wont lock the two edge cases without causing errors in other modes.
            {
                if (cp == 1) { if (global.cp[2].team == TEAM_RED) locked = true else locked = false; }
                if (cp == 2) { if (global.cp[1].team == TEAM_BLUE) locked = true else locked = false; }
            }
        } else if (mode != 3){
            // Locking is done externally in Arena mode and KotH
            //If we are voting on maps, then all points are to be unlocked.
            if (onMapVoting) {
                if (map_voting_lock_time >= 0) {
                    map_voting_lock_time -= 1 * global.delta_factor;
                    locked = true;
                } else {
                    locked = false;
                }
            }
            //Default non-map-voting behavior instead:
            else {
                if(team == TEAM_BLUE) {
                    if(cp > 1) {
                        if(global.cp[cp-1].team != TEAM_RED) locked = true;
                        else locked = false;
                    }
                } else if(team == TEAM_RED) {
                    if(cp < global.totalControlPoints) {
                        if(global.cp[cp+1].team != TEAM_BLUE) locked = true;
                        else locked = false;
                    }
                }
               
                if(mode==1 && team == TEAM_RED) locked = true;
            }
           
        }

        //autolock if the round is over, regardless of game mode
        if (arenaRoundEnd || global.mapchanging) locked = true;

        if(locked)
        {
            capping = 0;
            exit;
        }

        var randomRedCapper, randomBlueCapper, redCappers, blueCappers, myselfOnPoint, soundx, soundy;
        var oldRedPresence, oldBluePresence;

        oldRedPresence = redPresence;
        oldBluePresence = bluePresence;
        redPresence = 0;
        bluePresence = 0;
        redCappers = 0;
        blueCappers = 0;
        myselfOnPoint = false;
        cappers = 0;

        if(not arenaRoundEnd) {
            // At the end of an arena round players on the CP are no longer counted
            with(Character) {
                if(cappingPoint==other.id) {
                    if(player == global.myself) {
                        myselfOnPoint = true;
                    }

                    if (!other.onMapVoting)
                    {
                        if(player.team == TEAM_RED) {
                            if(ubered) {
                                other.redPresence = max(1, other.redPresence);
                            } else {
                                other.redPresence = max(2, other.redPresence);
                                redCappers += capStrength;
                            }
                            randomRedCapper = id;
                        } else {
                            if(ubered) {
                                other.bluePresence = max(1, other.bluePresence);
                            } else {
                                other.bluePresence = max(2, other.bluePresence);
                                blueCappers += capStrength;
                            }
                            randomBlueCapper = id;
                        }
                    }
                    else {
                        //If we are playing map voting, you can cap your own teams point - this is what makes the mode work
                        //Uber related info removed so you can capture with a constant uber status, preventing stabs while people cap.
                        //Cap strength removed because we dont want to make scouts cap faster than anyone else.
                            if other.id = global.cp[1]
                            {
                                            other.bluePresence = max(2, other.bluePresence);
                                            blueCappers += 1;
                               
                                        randomBlueCapper = id;
                            }
                            if other.id = global.cp[2]
                            {
                                            other.redPresence = max(2, other.redPresence);
                                            redCappers += 1;
                                       
                                        randomRedCapper = id;
                            }
                            if other.id = global.cp[3]
                            {
                                            other.redPresence = max(2, other.redPresence);
                                            redCappers += 1;
                                       
                                        randomRedCapper = id;
                        }
                    }
                }
            }
        }

        var cappingPower, cappingTeamPower;
        if(object_index == ArenaControlPoint)
        {
            reds = 0;
            blues = 0;
            livereds = 0;
            liveblues = 0;
           
            for(i=0; i<ds_list_size(global.players); i+=1)
            {
                player = ds_list_find_value(global.players, i);
               
                if(player.team == TEAM_RED)
                {
                    reds += 1;
                    if (player.object != -1 and instance_exists(player.object))
                        livereds += 1;
                }
                else if (player.team == TEAM_BLUE)
                {
                    blues += 1;
                    if (player.object != -1 and instance_exists(player.object))
                        liveblues += 1;
                }
            }
            var maxCappingPower;
            maxCappingPower = 4;
            cappingPower[TEAM_BLUE] = max(1,reds)/((1-1/maxCappingPower)*livereds + (1/maxCappingPower)*max(1,reds));
            cappingPower[TEAM_RED] = max(1,blues)/((1-1/maxCappingPower)*liveblues + (1/maxCappingPower)*max(1,blues));
        }
        else
        {
            cappingPower[TEAM_RED] = 1;
            cappingPower[TEAM_BLUE] = 1;
        }

        if (cappingTeam == TEAM_RED or cappingTeam == TEAM_BLUE)
            cappingTeamPower = cappingPower[cappingTeam]
        else
            cappingTeamPower = 1;

        // If the player stands on the point all the point sounds should be centered for him.
        if(myselfOnPoint) {
            soundx = global.myself.object.x;
            soundy = global.myself.object.y;
        } else {
            soundx = x;
            soundy = y;
        }

        if(redPresence>0 and bluePresence>0) {
            // Both teams have some players on the point...
            if(not (oldRedPresence>0 and oldBluePresence>0)) {
                // ...and the defense happened this step, with the cap meter more than half full
                if(bluePresence>0 and oldBluePresence==0 and team==TEAM_BLUE) {
                    var isMe;
                    isMe = randomBlueCapper.player == global.myself;
                    recordEventInLog(2,TEAM_BLUE, randomBlueCapper.player.name, isMe);
                    playsound(soundx, soundy, CPDefendedSnd);
                }
                if(redPresence>0 and oldRedPresence==0 and team==TEAM_RED) {
                    var isMe;
                    isMe = randomRedCapper.player == global.myself;
                    recordEventInLog(2,TEAM_RED, randomRedCapper.player.name, isMe);
                    playsound(soundx, soundy, CPDefendedSnd);
                }
            }
        } else if(redPresence==0 and bluePresence==0) {
            // Nobody on the point, slowly revert the capture
            if(capping>0) capping=max(capping - cappingTeamPower*global.delta_factor, 0);
        } else {
            // Some team has players on an undefended point.
            var teamOnPoint, teamOnPointPresence;
            if(redPresence>0) {
                teamOnPoint = TEAM_RED;
                teamOnPointPresence = redPresence;
                teamOnPointOldPresence = oldRedPresence;
                teamOnPointCappers = redCappers;
            } else {
                teamOnPoint = TEAM_BLUE;
                teamOnPointPresence = bluePresence;
                teamOnPointOldPresence = oldBluePresence;
                teamOnPointCappers = blueCappers;
            }
           
            if (teamOnPointPresence == 1)
            {
                // Only an ubercharged player on the point
                // He cant cap, but he will prevent the point from reverting if his team
                // has partially capped it already
                if (teamOnPoint != cappingTeam)
                {
                    capping = max(capping - cappingTeamPower*global.delta_factor, 0);
                }
            }
            else
            {
                // One team has cap-able players on an undefended point...
                if(cappingTeam != -1 and teamOnPoint != cappingTeam)
                {
                    // ...but the other team has the point partially captured already, so
                    // they have to revert first.
                    capping=max(capping - (1+teamOnPointCappers*0.5)*cappingTeamPower*global.delta_factor, 0);
                }
                else if(teamOnPoint != team)
                {
                    // ...and the point is not partially capped by the enemy team, and we dont own it already.
                    // So lets cap!
                   
                    if(teamOnPointOldPresence<2 or cappingTeam != teamOnPoint or (oldRedPresence>0 and oldBluePresence>0)) {
                        // Play the cap start sound if the team just entered the point,
                        // OR we just finished reverting the capture from the other team,
                        // OR the point was defended last step.
                        playsound(soundx, soundy, CPBeginCapSnd);
                    }
                    cappingTeam = teamOnPoint;
                    cappers = teamOnPointCappers;
                    if(cappers<=2) {
                        capping += cappers * cappingPower[cappingTeam] * global.delta_factor;
                    } else {
                        capping += (cappers/2+1) * cappingPower[cappingTeam] * global.delta_factor;
                    }
                }
            }
        }

        if(capping <= 0) {
            capping = 0;
            cappingTeam = -1;
        } else if global.isHost {
            if floor(capping) == floor(capTime - capTime/4) || floor(capping) == floor(capTime/4) || floor(capping) == floor(capTime/10){
                GameServer.syncTimer = 1;
            } else if capping >= capTime {
                pointCapture(cp);
                if instance_exists(ControlPointHUD) {
                    if ControlPointHUD.mode == 1 ControlPointHUD.timer += 5400;
                }
                GameServer.syncTimer = 1;
            }
        }
    ');

    object_event_add(ControlPointHUD, ev_create, 0, '
        onMapVoting = false;
        if (string_pos("map_voting", string_lower(global.currentMap)) != 0) {
            onMapVoting = true;
        }

        mapVotingCapTime = ds_map_find_value(global.mapVotingSettings, "VoteCapPlayerSeconds");
        maps = ds_map_find_value(global.mapVotingSettings, "randomMaps");
        mapOne = ds_list_find_value(maps, 0);
        mapTwo = ds_list_find_value(maps, 1);
        randMap = ds_list_find_value(maps, 2);

        useCategories = ds_map_find_value(global.mapVotingSettings, "useRandomMapCategories") > 0;
        categoryMappings = ds_map_find_value(global.mapVotingSettings, "mapRotationCategoryMappings");
        randMapCategory = ds_map_find_value(categoryMappings, randMap);
    ');

« Last Edit: August 13, 2020, 12:57:55 am by Machidro »
Logged
A CHALLENGER HAS ARRIVED.

Machidro

  • 2013 Haxxy Award Winner
  • *
  • Karma: 5
  • Offline Offline
  • Posts: 1675
  • Gardicolo time is over.
Re: Map Voting: Redux 2020 Edition! [serverplugin]
« Reply #47 on: August 13, 2020, 12:54:40 am »

Final part two:

Code: [Select]
object_event_add(ControlPointHUD, ev_step, ev_step_end, '
        if (onMapVoting && global.isHost = true) {
            //No HP loss possible, stab issue solved. Yay.
            with(Character) {
                if (ubered == 0) {
                    ubered = 1;
                }
            }

            if (global.winners = -1) {
                prevVal = ds_map_find_value(global.mapVotingSettings, "timeTillPrompt");
                ds_map_replace(global.mapVotingSettings, "timeTillPrompt", prevVal - (1 * global.delta_factor));
            }

            if (ds_map_find_value(global.mapVotingSettings, "timeTillPrompt") <= 0)
            {
                //tell the players about what is going on.
                if (ds_map_find_value(global.mapVotingSettings, "prompted") == false) {
                    ds_map_replace(global.mapVotingSettings, "prompted", true);

                    initialString = "";
                    lockedPointSeconds = ds_map_find_value(global.mapVotingSettings, "LockedPointSeconds");
                   
                    if (lockedPointSeconds > 0) {
                        initialString = "The voting will begin in " + string(round(lockedPointSeconds / 30)) + " seconds!";
                        ds_map_replace(global.mapVotingSettings, "timeTillPrompt", lockedPointSeconds);
                    } else {
                        initialString = "Stand in a box to vote for a map!";
                        ds_map_replace(global.mapVotingSettings, "timeTillPrompt", 60);
                    }

                    ServerMessageString(initialString, global.sendBuffer);
                    with NoticeO instance_destroy();
                    notice = instance_create(0, 0, NoticeO);
                    notice.notice = NOTICE_CUSTOM;
                    notice.message = initialString;
                } else {
                    categoryString = "";
                    if (useCategories && is_string(randMapCategory) && string(randMapCategory) != "") {
                         categoryString = "(" + randMapCategory + ") "
                    }

                    printingString1 = "Votes for " + mapOne + ": " + string(round(global.cp[1].capping/mapVotingCapTime*100)) + " %";
                    printingString2 = ", random " + categoryString + ": " + string(round(global.cp[2].capping/mapVotingCapTime*100)) + " %";
                    printingString3 = ", " + mapTwo + ": " + string(round(global.cp[3].capping/mapVotingCapTime*100)) + " %";
                    printingString = printingString1 + printingString2 + printingString3;

                    ds_map_replace(global.mapVotingSettings, "timeTillPrompt", 60);
                    ServerMessageString(printingString, global.sendBuffer);
                    with NoticeO instance_destroy();
                    notice = instance_create(0, 0, NoticeO);
                    notice.notice = NOTICE_CUSTOM;
                    notice.message = printingString;
                }
            }
        }
    ');

    object_event_add(GameServer, ev_step, ev_step_end, '
        onMapVoting = false;
        if (string_pos("map_voting", string_lower(global.currentMap)) != 0) {
            onMapVoting = true;
        }
       
        if (onMapVoting && global.isHost)
        {
            if (global.cp[1].team == TEAM_BLUE
                || global.cp[2].team == TEAM_RED
                ||  global.cp[3].team == TEAM_RED
                || (global.cp[2].team = -1 && ControlPointHUD.timer == 0))
            {
               
                maps = ds_map_find_value(global.mapVotingSettings, "randomMaps");
                if (ds_map_find_value(global.mapVotingSettings, "prompted"))
                {
                    mapVotingCapTime = ds_map_find_value(global.mapVotingSettings, "VoteCapPlayerSeconds");
                    mapOneStringPercentage = string(global.cp[1].capping/mapVotingCapTime*100);
                    mapTwoStringPercentage = string(global.cp[3].capping/mapVotingCapTime*100);
                    randomMapStringPercentage = string(global.cp[2].capping/mapVotingCapTime*100);
                    victoryMap = "";
                    if (global.cp[1].team == TEAM_BLUE) {
                        global.winners = TEAM_BLUE;
                        victoryMap = ds_list_find_value(maps, 0);
                        victoryText = victoryMap + " has won the vote!";
                        mapOneStringPercentage = "100.0";
                    } else if (global.cp[2].team == TEAM_RED) {
                        global.winners = TEAM_RED;
                        victoryMap = ds_list_find_value(maps, 2);
                        victoryText = "The random map has won the vote!";
                        randomMapStringPercentage = "100.0"
                    } else if (global.cp[3].team == TEAM_RED) {
                        global.winners = TEAM_RED;                   
                        victoryMap = ds_list_find_value(maps, 1);
                        victoryText = victoryMap + " has won the vote!";
                        mapTwoStringPercentage = "100.0"
                    } else if (global.cp[2].team = -1 && ControlPointHUD.timer == 0) {
                        global.winners = TEAM_SPECTATOR;
                        victoryMap = ds_list_find_value(maps, 2);
                        victoryText = "For some inexplicable reason, none of you voted. Random has won the vote!";
                    }

                    ServerMessageString(victoryText, global.sendBuffer);
                    with NoticeO instance_destroy();
                    notice = instance_create(0, 0, NoticeO);
                    notice.notice = NOTICE_CUSTOM;
                    notice.message = victoryText;
                   
                    ds_map_replace(global.mapVotingSettings, "prompted", false);

                    // Set the prompt time to 30 - next time map loads if wait time is needed itll update right
                    ds_map_replace(global.mapVotingSettings, "timeTillPrompt", 30);

                    // If the user has requested logs, log them now
                    isLoggingOn = ds_map_find_value(global.mapVotingSettings, "LogResults");

                    //Initialize the log writing file if it doesnt exist and is on
                    if (isLoggingOn) {
                        logFileName = ds_map_find_value(global.mapVotingSettings, "ResultsLogFileName");
                        maps = ds_map_find_value(global.mapVotingSettings, "randomMaps");
                        mapOne = ds_list_find_value(maps, 0);
                        mapTwo = ds_list_find_value(maps, 1);
                        randMap = ds_list_find_value(maps, 2);

                        var fileHandle;
                        fileHandle = file_text_open_append(logFileName);

                        //header format is:
                        //file_text_write_string(fileHandle, "voteTime,playerCount,serverMaxPlayerCount,map1name,map2name,randomSecretMapName,map1vote%,map2vote%,randomMapVote%");
                       
                        log = date_datetime_string(date_current_datetime())
                                                + "," + string(ds_list_size(global.players))
                                                + "," + string(global.playerLimit)
                                                + "," + mapOne
                                                + "," + mapTwo
                                                + "," + randMap
                                                + "," + mapOneStringPercentage
                                                + "," + mapTwoStringPercentage
                                                + "," + randomMapStringPercentage;
                       
                        file_text_write_string(fileHandle, log);
                        file_text_writeln(fileHandle);
                        file_text_close(fileHandle);
                    }
                }
                // We already declared a winner - wait for the map change.
                else {
                    if (GameServer.impendingMapChange == 1) {
                        ds_map_replace(global.mapVotingSettings, "generateNewMaps", true);

                        if (global.cp[1].team == TEAM_BLUE) {
                            global.nextMap = ds_list_find_value(maps, 0);
                        } else if (global.cp[2].team == TEAM_RED) {
                            global.nextMap = ds_list_find_value(maps, 2);
                        } else if (global.cp[3].team == TEAM_RED) {
                            global.nextMap = ds_list_find_value(maps, 1);
                        } else if (global.cp[2].team = -1 && ControlPointHUD.timer == 0) {
                            global.nextMap = ds_list_find_value(maps, 2);
                        }
                    }
                }
            } // Post victory checking complete
        } // Map voting map handling complete
        else if (!onMapVoting && global.isHost) {   
            // We are not on map voting.
            // if we are playing ADCP and the map is not over, stay. Otherwise, back to a map_voting map from your rotation.
            if  (GameServer.impendingMapChange == 1)
            {
                if (global.winners == TEAM_RED and global.nextMap = global.currentMap)
                {
                //Dont do anything. Just keep going with the same map.
                }
                else
                {
                    checkPlayerCount = ds_map_find_value(global.mapVotingSettings, "TooSmallForVotes");
                    smallLobbySizeCap = ds_map_find_value(global.mapVotingSettings, "TooSmallForVotesCap");

                    if (!checkPlayerCount || (checkPlayerCount && ds_list_size(global.players) > smallLobbySizeCap)) {
                        // Load a random map_voting map.
                        mapVotingMaps = ds_map_find_value(global.mapVotingSettings, "mapVotingMaps");
                        ds_list_shuffle(mapVotingMaps);
                        global.nextMap = ds_list_find_value(mapVotingMaps, 0);
                    }
                }
            }
           
            //roll for new random maps if we have been requested to.
            if (ds_map_find_value(global.mapVotingSettings, "generateNewMaps")) {
                ds_map_replace(global.mapVotingSettings, "generateNewMaps", false);
               
                mapParsedList = ds_map_find_value(global.mapVotingSettings, "mapRotationParsed");
                randomMaps = ds_map_find_value(global.mapVotingSettings, "randomMaps");
                mapCount = ds_map_find_value(global.mapVotingSettings, "voteMapCount");
                mapsFound = 0;

                // No sets in GML is suffering. We will make do with a map.
                mapSet = ds_map_create();
                ds_list_shuffle(mapParsedList);
                ds_list_clear(randomMaps);

                // Find three unique candidate maps not in the set
                for (i = 0; i < ds_list_size(mapParsedList); i += 1) {
                    mapName = ds_list_find_value(mapParsedList, i);
                    if (!(ds_map_find_value(mapSet, mapName)))
                    {
                        ds_map_add(mapSet, mapName, true);
                        ds_list_add(randomMaps, mapName);
                        mapsFound += 1;
                    }

                    if (mapsFound >= mapCount) {
                        break;
                    }
                }

                ds_list_destroy(mapSet);
            }
        }
    ');
};
« Last Edit: August 13, 2020, 12:59:35 am by Machidro »
Logged
A CHALLENGER HAS ARRIVED.
Pages: 1 2 3 [4]
 

Page created in 0.027 seconds with 36 queries.