-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsandbox.lua
79 lines (63 loc) · 2.24 KB
/
sandbox.lua
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
function PrintTable( t, indent, done )
done = done or {}
indent = indent or 0
for k,v in pairs(t) do
if (type(v) == "table" and not done[v]) then
done[v] = true
print(string.rep(" ", indent) .. tostring(k) .. ": {")
PrintTable(v, indent + 1, done)
print(string.rep(" ", indent) .. "}")
else
print(string.rep(" ", indent) .. tostring(k) .. ": " .. tostring(v))
end
end
end
function table.Count(t)
local count = 0
for k,v in pairs(t) do
count = count + 1
end
return count
end
local nextSpaceshipCheck = 0
local players = {}
local timeSinceStart = 0
local spawnDelay = 5
function OnPlayerJoined(player)
Arena:PrintChatMessage(string.format("Player %s has joined", player:GetName()));
players[player:GetSessionId()] = {
RespawnTime = 0,
Player = player
}
end
function OnPlayerLeave(player)
Arena:PrintChatMessage(string.format("Player %s left", player:GetName()));
local playerData = players[player:GetSessionId()]
if (playerData.Spaceship and playerData.Spaceship:IsValidHandle()) then
playerData.Spaceship:Kill()
end
players[player:GetSessionId()] = nil
end
function OnPlayerDeath(player)
print("Player " .. player:GetName() .. " died")
players[player:GetSessionId()].RespawnTime = timeSinceStart + spawnDelay
player:PrintMessage("Respawning in 5 seconds...")
end
function OnReset()
print("On reset (Sandbox), " .. Arena:GetName())
Ball = Arena:CreateEntity("ball", "The (big) ball created from script", nil, Vector3(0, 60, 0), Quaternion.Identity)
Earth = Arena:CreateEntity("earth", "The (small) Earth created from script", nil, Vector3(0, 0, -60), Quaternion.Identity)
Light = Arena:CreateEntity("light", "", nil, Vector3(0, 0, 0), Quaternion.Identity)
end
function OnUpdate(elapsedTime)
timeSinceStart = timeSinceStart + elapsedTime
if (timeSinceStart >= nextSpaceshipCheck) then
for sessionId, playerData in pairs(players) do
if (playerData.RespawnTime < timeSinceStart and not playerData.Player:GetControlledEntity():IsValidHandle()) then
playerData.Spaceship = Arena:CreateSpaceship(playerData.Player:GetName(), playerData.Player, 1, Vector3(0, 0, 0), Quaternion.Identity)
playerData.Player:UpdateControlledEntity(playerData.Spaceship)
end
end
nextSpaceshipCheck = timeSinceStart + 1
end
end