multiple spawns idea, color dependant

multiple spawns idea, color dependant

Postby Leeizazombie » 11 Jun 2013, 00:02

would it be possible to create a command that can set color spawns eg: /setspawn red so that people with a red colored name would spawn at it when they are dead, idk if its out there but i thought it would be a good thing to use for making tons of games
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: multiple spawns idea, color dependant

Postby Conor » 11 Jun 2013, 01:25

Leeizazombie wrote:would it be possible to create a command that can set color spawns eg: /setspawn red so that people with a red colored name would spawn at it when they are dead, idk if its out there but i thought it would be a good thing to use for making tons of games


Yes that is possible. You said you know how to code a little in another post of yours so I'll just go over it briefly to give you some direction.

You can save the spawn point when they set a spawn, for example in a text file; something like:

Code: Select all
// Called when the players uses /setspawn [message] where the message is split into string[] spawnPoint
// i.e. /setspawn red 12 64 23 - You could call the SaveSpawnPoint method with the string "red" for the team, and the string[] { "12", "64", "23" } for the position to save.
public void SaveSpawnPoint(string[] spawnPoint, string team)
{
   File.WriteAllText("extra/spawning/" + team + ".txt", spawnPoint[0] + " " + spawnPoint[1] + " " + spawnPoint[2]);
}


Meanwhile, take advantage of the Player.ExtraData Dictionary to store the players team. So when they respawn, you can check what team they're on, and check where their spawn point is;

Code: Select all
// The key to use for the dictionary
public const string TeamKey = "PlayerTeam";

// Sets the player to a certain team
public void SetPlayerTeam(Player p, string team)
{
   if (!p.ExtraData.ContainsKey(TeamKey))
   {
       p.ExtraData.Add(TeamKey, team);
   }
   p.ExtraData[TeamKey] = team;
}

// When the player spawns, send them to the team's spawn point
public void SpawnTeamPlayer(Player p)
{
   string[] spawnPos = File.ReadAllText("extra/spawning/" + (p.ExtraData[TeamKey]).ToString() + ".txt").Split(' ');
   unchecked
   {
       p.SendPos((byte)-1, (ushort)spawnPos[0], (ushort)spawnPos[1], (ushort)spawnPos[2], p.rot[0], p.rot[1]);
   }
}


I hope that might help you.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: multiple spawns idea, color dependant

Postby Leeizazombie » 11 Jun 2013, 01:30

I'm going to look trought it thank you so much :)
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: multiple spawns idea, color dependant

Postby Leeizazombie » 11 Jun 2013, 01:35

So if i wanted my 1st spawn in the middle of a 128 128 128 map its code should be like this? spawnPoint[0] + "64 65 64 "
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: multiple spawns idea, color dependant

Postby Conor » 11 Jun 2013, 01:40

Leeizazombie wrote:So if i wanted my 1st spawn in the middle of a 128 128 128 map its code should be like this? spawnPoint[0] + "64 65 64 "


It all depends on how you're going to code it. If you want to save it to the text file like I showed in the example, then you'd have to call the method from your command with the correct arguments. So if you wanted a spawn point for the red team, at the centre of the map, you could call the method like:

Code: Select all
string[] redSpawn = { "64", "64", "64" };
string team = "red";

SaveSpawnPoint(redSpawn, team);
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: multiple spawns idea, color dependant

Postby ismellike » 11 Jun 2013, 15:43

Leeizazombie wrote:Hey there, when I mentioned I know a bit about coding I meant that I can read it and understand how it works I know HTML and I have an idea on javascript, I'm new to C# completely, and I am interested in it, but I have no idea how to use the spawns code and put it in a command, compile error? or it has to be with a command?


ok in this code I left you a lot of little notes; If you need any other help just feel free to post it on here :p.

Code: Select all
using System.IO;
using System; //this helps us handle files easier.

namespace MCDzienny  //the usual stuff^v
{
    public class CmdSphere : Command
    {
        public int count = 20; //this is how long it takes for players to lose health
        private System.Timers.Timer timer = new System.Timers.Timer(1000); //this is how much the timer checks, 1000 ms->1 second.
        public override string name { get { return "tag"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        // ok this Init() code is going to be run on start
        public override void Init()
        {
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); //this says, when the timer passes 1 second of waiting, it does what's below
        }
        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) // this
        {
            count -= 1; //every time 1 second passes, the count down to lose health goes down by 1.
            if (count <= 0) //if it reaches the minimum it does this
            {
                Player.players.ForEachSync(p =>
                {
                    p.health -= 25; //player health goes down by 25
                    Player.SendMessage(p, "You now have " + p.health.ToString() + " life left.");
                });
                count = 20; //countdown restarts :O
            }
            Player.players.ForEachSync(p =>  //this checks every single person for something
                {
                    if (p.health <= 0) //the something is if their health is less than or equal to 0.
                    {
                        Player.GlobalMessage(p.PublicName + " has died from starvation");
                        using (var sr = new StreamReader("extra/spawns.txt")) // if it is they spawn at their designated color spawn
                        {
                            string line;
                            while ((line = sr.ReadLine()) != null) //this keeps reading to the end
                            {
                                if (line.Split(' ')[0].Contains(p.color)) //checks if the spawn color is their color
                                {
                                    Command.all.Find("move").Use(p, line.Split(' ')[1] + " " + line.Split(' ')[2] + " " + line.Split(' ')[3]);
                                } //if it is, it moves them^
                            }
                        }
                    }
                });
        }
        public override void Use(Player p, string message) //this is what happens whnen you use /tag
        {
            string[] split = message.Trim().Split(' '); //splits the message into parts based on a space.
            switch (split[0]) //so this would check the part right here /tag [message] <-
            {
                case "spawn":
                    string color;
                    try
                    {
                        color = split[1];
                    }
                    catch { Player.SendMessage(p, "You did not specify a team color"); return; }
                    SetSpawn(p, color);  // here is the method to set the spawn for a team color
                    return;
                case "play":
                    timer.Start(); //starts the game, checking.
                    return;
                case "stop":
                    timer.Stop(); //stops checking
                    return;
            }
        }
        public override void Help(Player p)
        {

        }
        private void SetSpawn(Player p, string color)
        {
            int y = p.pos[1] / 32 - 1;
            if (!File.Exists("extra/spawns.txt"))
            { //if a file doesnt exist for spawns, it makes it and writes your spawn
                File.WriteAllText("extra/spawns", string.Format(color + " " + p.pos[0] / 32 + " " + y + " " + p.pos[2] / 32));
            }
            else
            { //otherwise it just adds to the current file
                File.AppendAllText("extra/spawns.txt", string.Format(Environment.NewLine + color + " " + p.pos[0] / 32 + " " + y + " " + p.pos[2] / 32));
            }
            Player.SendMessage(p, "Spawn set for " + color);
        }
    }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: multiple spawns idea, color dependant

Postby Leeizazombie » 11 Jun 2013, 16:13

This is amazing help thanks, altough i get this error code during /compile

Code: Select all

-------------------------

Error #CS1061
Message: 'MCDzienny.PlayerCollection' does not contain a definition for 'ForEachSync' and no extension method 'ForEachSync' accepting a first argument of type 'MCDzienny.PlayerCollection' could be found (are you missing a using directive or an assembly reference?)
Line: 25

-------------------------

Error #CS1061
Message: 'MCDzienny.PlayerCollection' does not contain a definition for 'ForEachSync' and no extension method 'ForEachSync' accepting a first argument of type 'MCDzienny.PlayerCollection' could be found (are you missing a using directive or an assembly reference?)
Line: 32
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: multiple spawns idea, color dependant

Postby Leeizazombie » 11 Jun 2013, 16:16

Another question, umm what program do you use? I use notepad and i predict its not the best thing to use lol
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: multiple spawns idea, color dependant

Postby ismellike » 11 Jun 2013, 16:21

For the first response, update your mcdzienny_.dll version

2nd response, use microsoft visual studio c#.

It's free but it takes some time to download :P.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: multiple spawns idea, color dependant

Postby Leeizazombie » 11 Jun 2013, 16:26

Um how do I ugrade the dll? where do i download it?
Dang, no hope with that on an Android Hotspot lol, il get notepad++ for the time being
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Next

Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 2 guests

cron