Example #1
0
        private void initVote(Entity owner, string subject)
        {
            subject = getMapName(subject);
            string mapAlias = getMapName(subject);

            nextMap = subject;

            if (subject == "[MapNotFound]" || mapAlias == "[MapNotFound]")
            {
                Utilities.SayTo(owner, "^1Map was not found or its DLC.");
                return;
            }
            if (subject == Call <string>("getdvar", "mapname"))
            {
                Utilities.SayTo(owner, "^1You are currently playing this map.");
                return;
            }

            voteInProgress = true;
            vote           = subject;

            int hudOffset = Call <int>("getDvarInt", "sv_votingHudOffsetY");

            //Voting hud
            voteBG                = HudElem.CreateServerIcon(voteBGMaterial, 1, 64);
            voteBG.AlignX         = "left";
            voteBG.AlignY         = "middle";
            voteBG.HorzAlign      = "left_adjustable";
            voteBG.VertAlign      = "middle";
            voteBG.X              = 0;
            voteBG.Y              = 5 + hudOffset;
            voteBG.Alpha          = 0;
            voteBG.Sort           = 10;
            voteBG.Foreground     = false;
            voteBG.HideWhenInMenu = false;
            voteBG.Call("fadeovertime", 1);
            voteBG.Alpha = 1;
            voteBG.Call("scaleovertime", 1, 228, 64);

            voteText                = HudElem.CreateServerFontString("objective", 1);
            voteText.AlignX         = "left";
            voteText.AlignY         = "middle";
            voteText.HorzAlign      = "left_adjustable";
            voteText.VertAlign      = "middle";
            voteText.X              = -100;
            voteText.Y              = -15 + hudOffset;
            voteText.Alpha          = 0;
            voteText.Sort           = 20;
            voteText.Foreground     = true;
            voteText.HideWhenInMenu = false;
            voteText.Call("fadeovertime", 1);
            voteText.Alpha = 1;
            voteText.Call("moveovertime", 1);
            voteText.X = 5;
            string type = "Map: ^5";

            voteText.SetText("Voting for " + type + mapAlias + "\n^7Called by " + owner.Name);

            voteControls                = HudElem.CreateServerFontString("objective", 1);
            voteControls.AlignX         = "left";
            voteControls.AlignY         = "middle";
            voteControls.HorzAlign      = "left_adjustable";
            voteControls.VertAlign      = "middle";
            voteControls.X              = -100;
            voteControls.Y              = 25 + hudOffset;
            voteControls.Alpha          = 0;
            voteControls.Sort           = 20;
            voteControls.Foreground     = true;
            voteControls.HideWhenInMenu = false;
            voteControls.Call("fadeovertime", 1);
            voteControls.Alpha = 1;
            voteControls.Call("moveovertime", 1);
            voteControls.X = 5;
            voteControls.SetText("^3[{vote yes}] ^7Yes(^20^7)    |    ^3[{vote no}] ^7No(^20^7)");

            voteTimer                = HudElem.CreateServerFontString("objective", 0.75f);
            voteTimer.AlignX         = "left";
            voteTimer.AlignY         = "middle";
            voteTimer.HorzAlign      = "left_adjustable";
            voteTimer.VertAlign      = "middle";
            voteTimer.X              = -100;
            voteTimer.Y              = 10 + hudOffset;
            voteTimer.Alpha          = 0;
            voteTimer.Sort           = 20;
            voteTimer.Foreground     = true;
            voteTimer.HideWhenInMenu = false;
            voteTimer.Call("fadeovertime", 1);
            voteTimer.Alpha = 1;
            voteTimer.Call("moveovertime", 1);
            voteTimer.X = 5;
            voteTimer.Call("settimer", Call <int>("getDvarInt", "sv_votingTime"));

            AfterDelay(Call <int>("getDvarInt", "sv_votingTime") * 1000, checkVoteResults);

            bool shouldPlaySounds = true;

            AfterDelay(Call <int>("getDvarInt", "sv_votingTime") * 1000, () => shouldPlaySounds = false);

            OnInterval(1000, () =>
            {
                foreach (Entity player in Players)
                {
                    if (player.GetField <string>("classname") == "player")
                    {
                        player.Call("playLocalSound", "trophy_detect_projectile");
                    }
                }
                if (shouldPlaySounds)
                {
                    return(true);
                }
                return(false);
            });
        }