-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleSpawn.cs
More file actions
65 lines (56 loc) · 2.04 KB
/
SimpleSpawn.cs
File metadata and controls
65 lines (56 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("SimpleSpawn", "YourName", "1.6.0")]
[Description("Базовая система кастомного спавна")]
public class SimpleSpawn : RustPlugin
{
private Vector3? _spawn;
private const string PERM = "simplespawn.admin";
void Init()
{
permission.RegisterPermission(PERM, this);
try { _spawn = Interface.Oxide.DataFileSystem.ReadObject<SpawnData>(Name)?.Position; }
catch { }
}
void OnPlayerInit(BasePlayer p) => Spawn(p);
void OnPlayerRespawned(BasePlayer p) => Spawn(p);
[ChatCommand("spawn")]
void CmdSpawn(BasePlayer p, string cmd, string[] args)
{
if (!permission.UserHasPermission(p.UserIDString, PERM))
{
p.ChatMessage("Нет прав!");
return;
}
if (args.Length == 0)
{
p.ChatMessage(_spawn.HasValue
? $"Точка спавна: {_spawn.Value}"
: "Точка спавна не установлена");
return;
}
switch (args[0].ToLower())
{
case "set":
_spawn = p.transform.position;
SaveData();
p.ChatMessage("Точка спавна установлена!");
break;
case "none":
_spawn = null;
SaveData();
p.ChatMessage("Точка спавна сброшена");
break;
}
}
void Spawn(BasePlayer p)
{
if (_spawn.HasValue && p.IsConnected)
p.transform.position = _spawn.Value;
}
void SaveData() => Interface.Oxide.DataFileSystem.WriteObject(Name, new SpawnData { Position = _spawn ?? Vector3.zero });
class SpawnData { public Vector3 Position { get; set; } }
}
}