-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomPlayerSpawns.cs
147 lines (135 loc) · 4.39 KB
/
CustomPlayerSpawns.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Spawns = map(); //Stores spawns
SpawnsSaveFile = "Spawns.config"; //name for spawns file
PermissionPrefix = "Spawn"; //Permission will be PermissionPrefix.CommandName
MinReputation = 15; // players with this group won't get forced to the spawn
wipeConfigMessage = "[CustomSpawns] Spawns have been wiped!";
event onLoad()
{
loadConfig(Spawns);
print("[CustomSpawns] {0} Spawns loaded from unturned/uScript/Data/{1}!".format(Spawns.count, SpawnsSaveFile));
}
event onPlayerJoined(player)
{
rand = random();
roll = rand.int(0, Spawns.count);
spawnvar = Spawns.get(0);
if (player.reputation >= 15 and player.reputation <= -15) return;
if (player.reputation <= 15 and player.reputation >= -15)
{
player.teleport(spawnvar);
player.setData("status", 1);
print("[CustomSpawns] {0} seems to be new here, sent him to safezone.".format(player.name));
}
}
event onPlayerRespawned(player)
{
if (player.getData("status") == 0)
{
player.setData("status", 1);
if(!player.hasBed or player.bedPosition.distance(player.position) > 2)
{
rand = random();
roll = rand.int(0, Spawns.count);
spawnvar = Spawns.get(roll);
player.teleport(spawnvar);
}
}
}
event onPlayerDeath(victim, killer, cause)
{
victim.setData("status", 0);
}
command Wild()
{
allowCaller = "player";
permission = "{0}.Wild".format(PermissionPrefix);
execute()
{
rand = random();
roll = rand.int(0, Spawns.count);
spawnvar = Spawns.get(roll);
player.teleport(spawnvar);
}
}
command SpawnSet()
{
allowCaller = "player";
permission = "{0}.Set".format(PermissionPrefix);
execute()
{
player.message("[CustomSpawns] Spawn set at: {0}".format(player.position.toString()), "white");
PlayerPos = player.position;
Spawns.set(Spawns.count, PlayerPos);
saveConfig(Spawns);
print("[CustomSpawns] {0} Spawns saved to unturned/uScript/Data/{1}!".format(Spawns.count, SpawnsSaveFile), "white");
}
}
command SpawnList()
{
allowCaller = "player";
permission = "{0}.List".format(PermissionPrefix);
execute()
{
if(Spawns.count == 0) return player.message("[CustomSpawns] There are no spawns set yet!, use /SpawnSet to get started", "red");
if(Spawns.count == 1) return player.message("[CustomSpawns] There are {1} spawns (ID 0), use /SpawnView <ID> to view it in your map".format(Spawns.count-1, Spawns.count), "white");
player.message("[CustomSpawns] There are {1} spawns (ID 0 to {0}), use /SpawnView <ID> to view it in your map".format(Spawns.count-1, Spawns.count), "white");
}
}
command SpawnView(arg)
{
allowCaller = "player";
permission = "{0}.View".format(PermissionPrefix);
execute()
{
if(arguments.count < 1) return player.message("Missing argument. Please choose an ID");
if(Spawns.count == 0) return player.message("There are no spawns set yet!!! get started with /spawnset", "red");
if(!Spawns.containsKey(arg.toNumber())) return player.message("This spawn doesn't Exist {0}".format(arg));
player.marker.set(Spawns.get(arg.toNumber()), "CustomSpawn {0}".format(arg));
player.message("[CustomSpawns] Spawn {0} found [{1}], Check your map marker".format(arg.toString(), player.marker.position.toString()), "white");
}
}
command SpawnWipe()
{
allowCaller = "player";
permission = "{0}.Wipe".format(PermissionPrefix);
execute()
{
wipeConfig(Spawns);
print(wipeConfigMessage);
player.message(wipeConfigMessage, "red");
Spawns.clear();
wipeConfigMessage = "[CustomSpawns] Spawns have been wiped!";
}
}
// Saves the spawns from the map to the Spawns file
function saveConfig(configMap) {
text = "";
foreach(keyValuePair in configMap) {
text += "{0}={1}\n".format(keyValuePair.key, keyValuePair.value.toString().replace("x", "").replace("y", "").replace("z", "").trim());
}
file.writeAll(SpawnsSaveFile, text);
}
// Takes care of completely clearing the Spawns file
function wipeConfig(configMap)
{
text = "";
file.writeAll(SpawnsSaveFile, text);
}
// Loads the Spawns file to the map
function loadConfig(configMap)
{
configText = file.read(SpawnsSaveFile);
configLines = configText.split("\n");
foreach(line in configLines)
{
if(line == "") continue;
p = line.split("=");
partnumber = p[0].toNumber();
vectorpart = p[1].split(",");
vx = vectorpart[0].toNumber();
vy = vectorpart[1].toNumber();
vz = vectorpart[2].toNumber();
v3 = vector3(vx, vy, vz);
Spawns.set(partnumber, v3);
}
}