示例#1
0
 bool OnCommandSetModel(int player, string command, string argument)
 {
     if (command.Equals("setmodel", StringComparison.InvariantCultureIgnoreCase))
     {
         if (!(m.PlayerHasPrivilege(player, "setmodel") || m.IsSinglePlayer()))
         {
             m.SendMessage(player, m.colorError() + "No setmodel privilege");
             return(true);
         }
         string[] ss = argument.Split(' ');
         string   targetplayername = ss[0];
         string   modelname        = ss[1];
         string   texturename      = null;
         if (ss.Length >= 3)
         {
             texturename = ss[2];
         }
         bool found = false;
         foreach (int p in m.AllPlayers())
         {
             if (m.GetPlayerName(p).Equals(targetplayername, StringComparison.InvariantCultureIgnoreCase))
             {
                 m.SetPlayerModel(p, modelname, texturename);
                 found = true;
             }
         }
         if (!found)
         {
             m.SendMessage(player, m.colorError() + string.Format("Player {0} not found", targetplayername));
         }
         return(true);
     }
     return(false);
 }
示例#2
0
        void f()
        {
            int[] clients = m.AllPlayers();
            foreach (int p in clients)
            {
                if (p == ghost)
                {
                    continue;
                }
                Pos pos = new Pos();
                pos.x = m.GetPlayerPositionX(p);
                pos.y = m.GetPlayerPositionY(p);
                pos.z = m.GetPlayerPositionZ(p);

                pos.heading = m.GetPlayerHeading(p);
                pos.pitch   = m.GetPlayerPitch(p);
                history.Add(pos);
            }
            if (history.Count < 20)
            {
                return;
            }
            Pos p1 = history[0];

            history.RemoveAt(0);
            m.SetPlayerPosition(ghost, p1.x, p1.y, p1.z);
            m.SetPlayerOrientation(ghost, p1.heading, p1.pitch, 0);
        }
示例#3
0
 void PlaySoundToAll(string filename)
 {
     int[] playerlist = m.AllPlayers();
     for (int i = 0; i < playerlist.Length; i++)
     {
         int playerID = playerlist[i];
         m.PlaySoundAt((int)m.GetPlayerPositionX(playerID), (int)m.GetPlayerPositionY(playerID), (int)m.GetPlayerPositionZ(playerID), filename);
     }
 }
示例#4
0
        void calculatePlayerStats()
        {
            players_online    = 0;
            players_npc       = 0;
            players_spectator = 0;
            players_max       = 0;

            int[] allPlayers = m.AllPlayers();
            for (int i = 0; i < allPlayers.Length; i++)
            {
                if (m.IsBot(allPlayers[i]))
                {
                    players_npc++;
                }
                if (m.IsPlayerSpectator(allPlayers[i]))
                {
                    players_spectator++;
                }
            }
            players_online = allPlayers.Length;
            players_max    = m.GetMaxPlayers();
        }
示例#5
0
 void CheckPlayerPosition()
 {
     int[] players = m.AllPlayers();
     for (int i = 0; i < players.Length; i++)
     {
         string lastSeen = "";
         try
         {
             //Happens if new player (ID never used before) joins
             lastSeen = PlayerLastSeenIn[players[i]];
         }
         catch
         {
             //Simply set to empty so he gets notified the next tick
             lastSeen = "";
         }
         bool PlayerInAnyZone = false;
         for (int j = 0; j < locationList.Count; j++)
         {
             if (IsInArea(locationList[j], GetPlayerPosition(players[i])))
             {
                 //Player is in a defined zone
                 PlayerInAnyZone = true;
                 if (!lastSeen.Equals(locationList[j].name, StringComparison.InvariantCultureIgnoreCase))
                 {
                     //Player entered different area
                     m.SendMessage(players[i], chatPrefix + string.Format(GetLocalizedString("location_change"), locationList[j].name));
                     PlayerLastSeenIn[players[i]] = locationList[j].name;
                     return;
                 }
             }
         }
         if (!PlayerInAnyZone)
         {
             PlayerLastSeenIn[players[i]] = "";
         }
     }
 }
示例#6
0
        void OnTabKey(int player, SpecialKey key)
        {
            if (key != SpecialKey.TabPlayerList)
            {
                return;
            }
            tabOpen[m.GetPlayerName(player)] = true;
            Dialog d = new Dialog();

            d.IsModal = true;
            List <Widget> widgets = new List <Widget>();

            // table alignment
            float tableX = xcenter(m.GetScreenResolution(player)[0], tableWidth);
            float tableY = tableMarginTop;

            // text to draw
            string row1 = m.GetServerName();

            row1 = cutText(row1, HeadingFont, tableWidth - 2 * tablePadding);

            string row2 = m.GetServerMotd();

            row2 = cutText(row2, SmallFontBold, tableWidth - 2 * tablePadding);


            string row3_1 = "IP: " + m.GetServerIp() + ":" + m.GetServerPort();
            string row3_2 = (int)(m.GetPlayerPing(player) * 1000) + "ms";

            string row4_1 = "Players: " + m.AllPlayers().Length;
            string row4_2 = "Page: " + (page + 1) + "/" + (pageCount + 1);

            string row5_1 = "ID";
            string row5_2 = "Player";
            string row5_3 = "Ping";

            // row heights
            float row1Height      = textHeight(row1, HeadingFont) + 2 * tablePadding;
            float row2Height      = textHeight(row2, SmallFontBold) + 2 * tablePadding;
            float row3Height      = textHeight(row3_1, SmallFont) + 2 * tablePadding;
            float row4Height      = textHeight(row4_1, SmallFont) + 2 * tablePadding;
            float row5Height      = textHeight(row5_1, NormalFontBold) + 2 * tablePadding;
            float listEntryHeight = textHeight("Player", NormalFont) + 2 * listEntryPaddingTopBottom;

            float heightOffset = 0;

            // determine how many entries can be displayed
            tableHeight = m.GetScreenResolution(player)[1] - tableMarginTop - tableMarginBottom;
            float availableEntrySpace = tableHeight - row1Height - row2Height - row3Height - row4Height - (row5Height + tableLineWidth);

            int entriesPerPage = (int)(availableEntrySpace / listEntryHeight);

            pageCount = (int)Math.Ceiling((float)(m.AllPlayers().Length / entriesPerPage));
            if (page > pageCount)
            {
                page = 0;
            }

            // 1 - heading: Servername
            widgets.Add(Widget.MakeSolid(tableX, tableY, tableWidth, row1Height, Color.DarkGreen.ToArgb()));
            widgets.Add(Widget.MakeText(row1, HeadingFont, tableX + xcenter(tableWidth, textWidth(row1, HeadingFont)), tableY + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row1Height;

            // 2 - MOTD
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, row2Height, Color.ForestGreen.ToArgb()));
            widgets.Add(Widget.MakeText(row2, SmallFontBold, tableX + xcenter(tableWidth, textWidth(row2, SmallFontBold)), tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row2Height;

            // 3 - server info: IP Motd Serverping
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, row3Height, Color.DarkSeaGreen.ToArgb()));
            // row3_1 - IP align left
            widgets.Add(Widget.MakeText(row3_1, SmallFont, tableX + tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            // row3_2 - Serverping align right
            widgets.Add(Widget.MakeText(row3_2, SmallFont, tableX + tableWidth - textWidth(row3_2, SmallFont) - tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row3Height;

            // 4 - infoline: Playercount, Page
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, row4Height, Color.DimGray.ToArgb()));
            // row4_1 PlayerCount
            widgets.Add(Widget.MakeText(row4_1, SmallFont, tableX + tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            // row4_2 PlayerCount
            widgets.Add(Widget.MakeText(row4_2, SmallFont, tableX + tableWidth - textWidth(row4_2, SmallFont) - tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row4Height;

            // 5 - playerlist heading: ID | Player | Ping
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableIdColumnWidth, row5Height, Color.DarkGray.ToArgb()));
            widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth, tableY + heightOffset, tablePlayerColumnWidth, row5Height, Color.DarkGray.ToArgb()));
            widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth + tablePlayerColumnWidth, tableY + heightOffset, tablePingColumnWidth, row5Height, Color.DarkGray.ToArgb()));
            // separation lines
            widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth, tableY + heightOffset, tableLineWidth, row5Height, Color.DimGray.ToArgb()));
            widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth + tablePlayerColumnWidth - tableLineWidth, tableY + heightOffset, tableLineWidth, row5Height, Color.DimGray.ToArgb()));
            // row4_1 ID - align center
            widgets.Add(Widget.MakeText(row5_1, NormalFontBold, tableX + xcenter(tableIdColumnWidth, textWidth(row5_1, NormalFontBold)), tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            // row4_2 Player - align center
            widgets.Add(Widget.MakeText(row5_2, NormalFontBold, tableX + tableIdColumnWidth + tablePlayerColumnWidth / 2 - textWidth(row5_2, NormalFontBold) / 2, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            // row4_3 Ping - align center
            widgets.Add(Widget.MakeText(row5_3, NormalFontBold, tableX + tableIdColumnWidth + tablePlayerColumnWidth + tablePingColumnWidth / 2 - textWidth(row5_3, NormalFontBold) / 2, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row5Height;
            // horizontal line
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, tableLineWidth, Color.DimGray.ToArgb()));
            heightOffset += tableLineWidth;

            // 6 - actual playerlist
            // entries:
            Color entryRowColor;

            int[] AllPlayers = m.AllPlayers();
            for (int i = page * entriesPerPage; i < Math.Min(AllPlayers.Length, page * entriesPerPage + entriesPerPage); i++)
            {
                if (i % 2 == 0)
                {
                    entryRowColor = Color.Gainsboro;
                }
                else
                {
                    entryRowColor = Color.Honeydew;
                }
                widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableIdColumnWidth, listEntryHeight, entryRowColor.ToArgb()));
                widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth, tableY + heightOffset, tablePlayerColumnWidth, listEntryHeight, entryRowColor.ToArgb()));
                widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth + tablePlayerColumnWidth, tableY + heightOffset, tablePingColumnWidth, listEntryHeight, entryRowColor.ToArgb()));

                // separation lines
                widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth, tableY + heightOffset, tableLineWidth, listEntryHeight, Color.DimGray.ToArgb()));
                widgets.Add(Widget.MakeSolid(tableX + tableIdColumnWidth + tablePlayerColumnWidth - tableLineWidth, tableY + heightOffset, tableLineWidth, listEntryHeight, Color.DimGray.ToArgb()));

                widgets.Add(Widget.MakeText(AllPlayers[i].ToString(), NormalFont, tableX + tableIdColumnWidth - textWidth(AllPlayers[i].ToString(), NormalFont) - tablePadding, tableY + heightOffset + listEntryPaddingTopBottom, TEXT_COLOR.ToArgb()));
                widgets.Add(Widget.MakeText(getPrefix(AllPlayers[i]) + m.GetPlayerName(AllPlayers[i]), NormalFont, tableX + tableIdColumnWidth + tablePadding, tableY + heightOffset + listEntryPaddingTopBottom, TEXT_COLOR.ToArgb()));
                string pingString;
                if (m.IsBot(AllPlayers[i]))
                {
                    pingString = "BOT";
                }
                else
                {
                    pingString = ((int)(m.GetPlayerPing(AllPlayers[i]) * 1000)).ToString();
                }
                widgets.Add(Widget.MakeText(pingString, NormalFont, tableX + tableIdColumnWidth + tablePlayerColumnWidth + tablePingColumnWidth - textWidth(pingString, NormalFont) - tablePadding, tableY + heightOffset + listEntryPaddingTopBottom, TEXT_COLOR.ToArgb()));
                heightOffset += listEntryHeight;
            }
            var wtab = Widget.MakeSolid(0, 0, 0, 0, 0);

            wtab.ClickKey = '\t';
            wtab.Id       = "Tab";
            widgets.Add(wtab);
            var wesc = Widget.MakeSolid(0, 0, 0, 0, 0);

            wesc.ClickKey = (char)27;
            wesc.Id       = "Esc";
            widgets.Add(wesc);

            d.Width   = m.GetScreenResolution(player)[0];
            d.Height  = m.GetScreenResolution(player)[1];
            d.Widgets = widgets.ToArray();
            m.SendDialog(player, "PlayerList", d);
        }
示例#7
0
        void OnTabKey(int player, SpecialKey key)
        {
            if (key != SpecialKey.TabPlayerList)
            {
                return;
            }
            tabOpen[m.GetPlayerName(player)] = true;
            Dialog d = new Dialog();

            d.IsModal = true;
            List <Widget> widgets = new List <Widget>();

            // table alignment
            float tableX = xcenter(m.GetScreenResolution(player)[0], tableWidth);
            float tableY = tableMarginTop;

            // text to draw
            string row1 = m.GetServerName();

            row1 = cutText(row1, HeadingFont, tableWidth - 2 * tablePadding);

            string row2 = m.GetServerMotd();

            row2 = cutText(row2, SmallFontBold, tableWidth - 2 * tablePadding);

            string row3_1 = "IP: " + m.GetServerIp() + ":" + m.GetServerPort();
            string row3_2 = (int)(m.GetPlayerPing(player) * 1000) + "ms";

            string row4_1 = "Players: " + m.AllPlayers().Length;
            string row4_2 = "Page: " + (page + 1) + "/" + (pageCount + 1);

            string row5_1 = "ID";
            //string row5_2 = "Player";
            //string row5_3 = "Ping";

            // row heights
            float row1Height      = textHeight(row1, HeadingFont) + 2 * tablePadding;
            float row2Height      = textHeight(row2, SmallFontBold) + 2 * tablePadding;
            float row3Height      = textHeight(row3_1, SmallFont) + 2 * tablePadding;
            float row4Height      = textHeight(row4_1, SmallFont) + 2 * tablePadding;
            float row5Height      = textHeight(row5_1, NormalFontBold) + 2 * tablePadding;
            float listEntryHeight = textHeight("Player", NormalFont) + 2 * listEntryPaddingTopBottom;

            float heightOffset = 0;

            // determine how many entries can be displayed
            tableHeight = m.GetScreenResolution(player)[1] - tableMarginTop - tableMarginBottom;
            float availableEntrySpace = tableHeight - row1Height - row2Height - row3Height - row4Height - (row5Height + tableLineWidth);

            int entriesPerPage = (int)(availableEntrySpace / listEntryHeight);

            pageCount = (int)Math.Ceiling((float)(m.AllPlayers().Length / entriesPerPage));
            if (page > pageCount)
            {
                page = 0;
            }

            // 1 - heading: Servername
            widgets.Add(Widget.MakeSolid(tableX, tableY, tableWidth, row1Height, Color.DarkGreen.ToArgb()));
            widgets.Add(Widget.MakeText(row1, HeadingFont, tableX + xcenter(tableWidth, textWidth(row1, HeadingFont)), tableY + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row1Height;

            // 2 - MOTD
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, row2Height, Color.ForestGreen.ToArgb()));
            widgets.Add(Widget.MakeText(row2, SmallFontBold, tableX + xcenter(tableWidth, textWidth(row2, SmallFontBold)), tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row2Height;

            // 3 - server info: IP Motd Serverping
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, row3Height, Color.DarkSeaGreen.ToArgb()));
            // row3_1 - IP align left
            widgets.Add(Widget.MakeText(row3_1, SmallFont, tableX + tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            // row3_2 - Serverping align right
            widgets.Add(Widget.MakeText(row3_2, SmallFont, tableX + tableWidth - textWidth(row3_2, SmallFont) - tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row3Height;

            // 4 - infoline: Playercount, Page
            widgets.Add(Widget.MakeSolid(tableX, tableY + heightOffset, tableWidth, row4Height, Color.DimGray.ToArgb()));
            // row4_1 PlayerCount
            widgets.Add(Widget.MakeText(row4_1, SmallFont, tableX + tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            // row4_2 PlayerCount
            widgets.Add(Widget.MakeText(row4_2, SmallFont, tableX + tableWidth - textWidth(row4_2, SmallFont) - tablePadding, tableY + heightOffset + tablePadding, TEXT_COLOR.ToArgb()));
            heightOffset += row4Height;

            Dictionary <Team, List <int> > playersByTeam = new Dictionary <Team, List <int> >();

            playersByTeam[Team.Blue]      = new List <int>();
            playersByTeam[Team.Spectator] = new List <int>();
            playersByTeam[Team.Green]     = new List <int>();
            int[] AllPlayers = m.AllPlayers();
            foreach (int p in AllPlayers)
            {
                playersByTeam[players[p].team].Add(p);
            }
            Team[] allteams = new Team[] { Team.Blue, Team.Spectator, Team.Green };
            for (int t = 0; t < allteams.Length; t++)
            {
                List <int> players = playersByTeam[allteams[t]];
                players.Sort((a, b) => (this.players[b].kills.CompareTo(this.players[a].kills)));
                for (int i = 0; i < players.Count; i++)
                {
                    string s = string.Format("{0} {1}ms {2} kills", m.GetPlayerName(players[i]), (int)(m.GetPlayerPing(players[i]) * 1000), this.players[players[i]].kills);
                    widgets.Add(Widget.MakeText(s, NormalFont, tableX + 200 * t, tableY + heightOffset + listEntryHeight * i, Color.White.ToArgb()));
                }
            }


            var wtab = Widget.MakeSolid(0, 0, 0, 0, 0);

            wtab.ClickKey = '\t';
            wtab.Id       = "Tab";
            widgets.Add(wtab);
            var wesc = Widget.MakeSolid(0, 0, 0, 0, 0);

            wesc.ClickKey = (char)27;
            wesc.Id       = "Esc";
            widgets.Add(wesc);

            d.Width   = m.GetScreenResolution(player)[0];
            d.Height  = m.GetScreenResolution(player)[1];
            d.Widgets = widgets.ToArray();
            m.SendDialog(player, "PlayerList", d);
        }