To Conor and all other users (important)

To Conor and all other users (important)

Postby toystory_justin » 23 Feb 2013, 13:21

Hello guys, I was just browsing for some code's and I found this, which might work for CTF Game Mode in McDzienny.
Here's the code: P.S. Can someone edit and post if it works or no?

Code: Select all
using System;
using System.Collections.Generic;
using System.Threading;


/* CTF TO-DO LIST
* Team-chat
* Delayed respawns.  Dunno, put player somewhere in the mid-term?  Put them out of the map?  I dunno.
* Fix the java client crash on RemoveMember that rarely but consistantly occurs.
*/



namespace McDzienny
{
    public class CTFGame
    {
        public List<Team> teams = new List<Team>();

        public Level mapOn;

        public int maxPoints = 3;

        public bool gameOn = false;

        public bool friendlyfire = false;

        public System.Timers.Timer onTeamCheck = new System.Timers.Timer(500);
        public System.Timers.Timer flagReturn = new System.Timers.Timer(1000);

        public int returnCount = 0;

        public void GameStart()
        {
            mapOn.ChatLevel("Capture the flag game has started!");
            foreach (Team team in teams)
            {
                ReturnFlag(null, team, false);
                foreach (Player p in team.players)
                {
                    team.SpawnPlayer(p);
                }
            }

            onTeamCheck.Start();
            onTeamCheck.Elapsed += delegate
            {
                foreach (Team team in teams)
                {
                    foreach (Player p in team.players)
                    {
                        if (!p.loggedIn || p.level != mapOn)
                        {
                            team.RemoveMember(p);
                        }
                    }
                }
            };

            flagReturn.Start();
            flagReturn.Elapsed += delegate
            {
                foreach (Team team in teams)
                {
                    if (!team.flagishome && team.holdingFlag == null)
                    {
                        team.ftcount++;
                        if (team.ftcount > 30)
                        {
                            mapOn.ChatLevel("The " + team.teamstring + " flag has returned to their base.");
                            team.ftcount = 0;
                            ReturnFlag(null, team, false);
                        }
                    }
                }
            };

            Thread flagThread = new Thread(new ThreadStart(delegate
                {
                    while (gameOn)
                    {
                        foreach (Team team in teams)
                        {
                            team.Drawflag();
                        }
                        Thread.Sleep(200);
                    }

                })); flagThread.Start();
        }

        public void GameEnd(Team winTeam)
        {
            mapOn.ChatLevel("The game has ended! " + winTeam.teamstring + " has won with " + winTeam.points + " point(s)!");
            foreach (Team team in teams)
            {
                ReturnFlag(null, team, false);
                foreach (Player p in team.players)
                {
                    p.hasflag = null;
                    p.carryingFlag = false;

                }
                team.points = 0;
               
            }

            gameOn = false;
           
        }

        public void GrabFlag(Player p, Team team)
        {
            if (p.carryingFlag) { return; }
            ushort x = (ushort)(p.pos[0] / 32);
            ushort y = (ushort)((p.pos[1] / 32) + 3);
            ushort z = (ushort)(p.pos[2] / 32);

            team.tempFlagblock.x = x; team.tempFlagblock.y = y; team.tempFlagblock.z = z; team.tempFlagblock.type = mapOn.GetTile(x, y, z);

            mapOn.Blockchange(x, y, z, Team.GetColorBlock(team.color));

            mapOn.ChatLevel(p.color + p.prefix + p.name + Server.DefaultColor + " has stolen the " + team.teamstring + " flag!");
            p.hasflag = team;
            p.carryingFlag = true;
            team.holdingFlag = p;
            team.flagishome = false;

            if (p.aiming)
            {
                p.ClearBlockchange();
                p.aiming = false;
            }
        }

        public void CaptureFlag(Player p, Team playerTeam, Team capturedTeam)
        {
            playerTeam.points++;
            mapOn.Blockchange(capturedTeam.tempFlagblock.x, capturedTeam.tempFlagblock.y, capturedTeam.tempFlagblock.z, capturedTeam.tempFlagblock.type);
            mapOn.ChatLevel(p.color + p.prefix + p.name + Server.DefaultColor + " has captured the " + capturedTeam.teamstring + " flag!");

            if (playerTeam.points >= maxPoints)
            {
                GameEnd(playerTeam);
                return;
            }

            mapOn.ChatLevel(playerTeam.teamstring + " now has " + playerTeam.points + " point(s).");
            p.hasflag = null;
            p.carryingFlag = false;
            ReturnFlag(null, capturedTeam, false);
        }

        public void DropFlag(Player p, Team team)
        {
            mapOn.ChatLevel(p.color + p.prefix + p.name + Server.DefaultColor + " has dropped the " + team.teamstring + " flag!");
            ushort x = (ushort)(p.pos[0] / 32);
            ushort y = (ushort)((p.pos[1] / 32) - 1);
            ushort z = (ushort)(p.pos[2] / 32);

            mapOn.Blockchange(team.tempFlagblock.x, team.tempFlagblock.y, team.tempFlagblock.z, team.tempFlagblock.type);

            team.flagLocation[0] = x;
            team.flagLocation[1] = y;
            team.flagLocation[2] = z;

            p.hasflag = null;
            p.carryingFlag = false;

            team.holdingFlag = null;
            team.flagishome = false;
        }
        public void ReturnFlag(Player p, Team team, bool verbose)
        {
            if (p != null && p.spawning) { return; }
            if (verbose)
            {
                if (p != null)
                {
                    mapOn.ChatLevel(p.color + p.prefix + p.name + Server.DefaultColor + " has returned the " + team.teamstring + " flag!");
                }
                else
                {
                    mapOn.ChatLevel("The " + team.teamstring + " flag has been returned.");
                }
            }
            team.holdingFlag = null;
            team.flagLocation[0] = team.flagBase[0];
            team.flagLocation[1] = team.flagBase[1];
            team.flagLocation[2] = team.flagBase[2];
            team.flagishome = true;
        }

        public void AddTeam(string color)
        {
            char teamCol = (char)color[1];

            Team workteam = new Team();

            workteam.color = teamCol;
            workteam.points = 0;
            workteam.mapOn = mapOn;
            char[] temp = c.Name("&" + teamCol).ToCharArray();
            temp[0] = char.ToUpper(temp[0]);
            string tempstring = new string(temp);
            workteam.teamstring = "&" + teamCol + tempstring + " team" + Server.DefaultColor;

            teams.Add(workteam);
           
            mapOn.ChatLevel(workteam.teamstring + " has been initialized!");
        }

        public void RemoveTeam(string color)
        {
            char teamCol = (char)color[1];

            Team workteam = teams.Find(team => team.color == teamCol);
            List<Player> storedP = new List<Player>();

            for (int i = 0; i < workteam.players.Count; i++)
            {
                storedP.Add(workteam.players[i]);
            }
            foreach (Player p in storedP)
            {
                workteam.RemoveMember(p);
            }
           
           
        }
    }
}


Please tell me can it be compiled in VS Express. Reply please. Important for the server, might be added to the next update? @dzienny you can move this post to the Help Section
toystory_justin
 
Posts: 224
Joined: 11 Nov 2012, 07:12
Location: On a dark place

Re: To Conor and all other users (important)

Postby ismellike » 23 Feb 2013, 15:30

That is just the normal ctf game mode. It is very similar, if not exactly the same thing mcdzienny already has.

It needs to be compiled with the software since its not a command.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: To Conor and all other users (important)

Postby Conor » 23 Feb 2013, 17:50

^That

Also this code relies on another class (Team.cs).
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: To Conor and all other users (important)

Postby toystory_justin » 24 Feb 2013, 00:07

I found this from the,software that Jacob's CTF use. But thanks for the information.
toystory_justin
 
Posts: 224
Joined: 11 Nov 2012, 07:12
Location: On a dark place

Re: To Conor and all other users (important)

Postby Alshima » 06 May 2013, 07:05

Where did you find this plugin? I was looking for it for a long time :o
Alshima
 
Posts: 160
Joined: 11 Mar 2013, 02:22
Location: Alshima Island


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron