C#:
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("TownTeleport", "Ali", "1.0.1")]
[Description("Allows admins to set a teleport spawn point and players to teleport to that spawn point")]
public class TownTeleport : RustPlugin
{
private Vector3 spawnPoint;
private StoredData storedData;
private class StoredData
{
public Vector3 SpawnPoint { get; set; }
}
private void Init()
{
permission.RegisterPermission("townteleport.admin", this);
permission.RegisterPermission("townteleport.use", this);
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>(Name);
spawnPoint = storedData?.SpawnPoint ?? Vector3.zero;
}
private void SaveData()
{
storedData.SpawnPoint = spawnPoint;
Interface.Oxide.DataFileSystem.WriteObject(Name, storedData);
}
[ChatCommand("setspawn")]
private void SetSpawnCommand(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, "townteleport.admin"))
{
SendReply(player, "You don't have permission to use this command!");
return;
}
spawnPoint = player.transform.position;
SaveData();
SendReply(player, "Spawn point set!");
}
[ChatCommand("town")]
private void TownCommand(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, "townteleport.use"))
{
SendReply(player, "You don't have permission to use this command!");
return;
}
if (spawnPoint == Vector3.zero)
{
SendReply(player, "The spawn point has not been set yet!");
return;
}
player.Teleport(spawnPoint);
}
}
}