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
// 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]);
}
// 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]);
}
}
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 "
string[] redSpawn = { "64", "64", "64" };
string team = "red";
SaveSpawnPoint(redSpawn, team);
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?
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);
}
}
}
-------------------------
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
Users browsing this forum: No registered users and 2 guests