/savelocation

/savelocation

Postby Leeizazombie » 23 Jul 2013, 16:51

I want this to be used in parkours with /CmdBlock where it save location for players, and when they die from lava they will spawn at that location
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: /savelocation

Postby Conor » 23 Jul 2013, 19:04

A command block using /savelocation saveLocationMessage would have to be placed in the position you want the player to respawn when they die.

A command block would need to be placed either at the spawn (so its triggered when they die and respawn), or you can just replace the lava with command blocks - all of which have /savelocation sendToLocationMessage as there command. This will send the player back to the position last saved.

Code: Select all
using System;

namespace MCDzienny
{
    public class CmdSaveLocation : Command
    {
        public override string name { get { return "savelocation"; } }
        public override string shortcut { get { return "sl"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }

        private string saveLocationMessage = "saveloc";
        private string sendToLocationMessage = "sendloc";

        public override void Help(Player p)
        {
            Player.SendMessage(p, "You cannot use this command manually.");
        }

        public override void Use(Player p, string message)
        {
            if (message == saveLocationMessage)
            {
                PlayerExtra pe = PlayerExtra.Find(p);

                pe.oldPos = p.pos;
                pe.oldRot = p.rot;
            }
            else if (message == sendToLocationMessage)
            {
                PlayerExtra pe = PlayerExtra.Find(p);

                if (pe.oldPos != null && pe.oldRot != null)
                {
                    unchecked
                    {
                        p.SendPos((byte)-1, pe.oldPos[0], pe.oldPos[1], pe.oldPos[2], pe.oldRot[0], pe.oldRot[1]);
                    }
                }
            }
            else
            {
                Help(p);
            }
        }
    }
}


I didn't really spend much time on this so it could be faulty, just let me know if you need something else.

This relies on my PlayerExtra class plugin. So you must compile this too:
Code: Select all
using System;
using System.Collections.Generic;

namespace MCDzienny
{
    public class CmdPlayerExtraPlugin
    {
        public override string name { get { return "playerextraplugin"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } }

        public override void Init()
        {
            Player.Joined += (object sender, PlayerEventArgs e) =>
            {
                PlayerExtra addPlayer = new PlayerExtra(e.Player);
            };
        }

        public override void Help(Player p)
        {
            Player.SendMessage(p, "This is a plugin, the command does nothing.");
        }

        public override void Use(Player p, string message)
        {
            Help(p);
        }
    }

    public partial class PlayerExtra
    {
        public static List<PlayerExtra> all = new List<PlayerExtra>();
        public Player player;

        public PlayerExtra(Player player)
        {
            this.player = player;

            if (!all.Contains(this))
            {
                all.Add(this);
            }
        }

        public static PlayerExtra Find(Player player)
        {
            PlayerExtra toReturn = null;

            all.ForEach(delegate(PlayerExtra p)
            {
                if (p.player == player)
                {
                    toReturn = p;
                }
            });

            if (toReturn != null)
            {
                return toReturn;
            }

            if (player != null && !player.disconnected)
            {
                PlayerExtra newPlayer = new PlayerExtra(player);
                return newPlayer;
            }
            return null;
        }
    }

    public partial class PlayerExtra
    {
        public ushort[] oldPos;
        public byte[] oldRot;
    }
}
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 3 guests

cron