This repository was archived by the owner on May 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrustygames.lua
More file actions
161 lines (133 loc) · 4.73 KB
/
Copy pathrustygames.lua
File metadata and controls
161 lines (133 loc) · 4.73 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
PLUGIN.Title = "Rusty Games"
PLUGIN.Description = "An Oxide plugin inspired by movies such as The Hunger Games and Battle Royale."
PLUGIN.Author = "DaGodz"
PLUGIN.Version = "1.0"
if (not rustyGames) then
rustyGames = {}
rustyGames.tributes = {}
rustyGames.inProgress = false
end
function PLUGIN:Init()
print("Loading " .. self.Title .. " (" .. self.Version .. ")...")
self:LoadConfig(false)
self:AddChatCommand("startthegames", self.CmdStartTheGames)
self:AddChatCommand("stopthegames", self.CmdStopTheGames)
self:AddChatCommand("tinroof...", self.CmdTinRoof) -- a bit of fun
self:AddCommand("rustygames", "resetconfig", self.CCmdResetConfig)
end
function PLUGIN:LoadConfig(isReset)
local b, res = config.Read("rustygames")
self.Config = res or {}
if (not b or isReset) then
self:LoadDefaultConfig()
if (res) then config.Save("rustygames") end
end
end
function PLUGIN:LoadDefaultConfig()
self.Config.chatName = "The Rusty Announcer"
self.Config.broadcastChat = true
self.Config.log = true
self.Config.say = {}
self.Config.say.start = "Tributes ready? Let the Rusty Games Commence!"
self.Config.say.stop = "The Rusty Games have been abandoned!"
self.Config.say.loser = "is out of this Games!"
end
function PLUGIN:CCmdResetConfig(arg)
self:LoadConfig(true)
arg:ReplyWith("Rusty Games config reset")
self:Log("Config reset")
end
function PLUGIN:CmdTinRoof(netUser, cmd, args)
rust.Notice(netUser,"Rusted!")
end
function PLUGIN:CmdStartTheGames(netUser, cmd, args)
if (netUser and not netUser:canAdmin()) then return end
self:StartTheGames(netUser)
end
function PLUGIN:CmdStopTheGames(netUser, cmd, args)
if (netUser and not netUser:canAdmin()) then return end
if (not rustyGames.inProgress) then
rust.Notice(netUser,"The Rusty Games are not in progress! You can start them with /startthegames")
else
self:StopTheGames()
self:BroadcastChat(self.Config.say.stop)
end
end
function PLUGIN:StartTheGames(netUser)
if (rustyGames.inProgress) then
rust.Notice(netUser,"The Rusty Games are already in progress! You can abandon them with /stopthegames")
else
local netUsers = rust.GetAllNetUsers()
if (#netUsers < 2) then
rust.Notice(netUser,"The Rusty Games need at least 2 tributes! Go and find a volunteer.")
else
for i, netUser in pairs(netUsers) do
table.insert(rustyGames.tributes, netUser.playerClient.userName)
end
rust.RunServerCommand("falldamage.enabled false")
self:SpawnTributes()
timer.Once( 60, function() rust.RunServerCommand("falldamage.enabled true"); end )
rustyGames.inProgress = true
self:BroadcastChat(self.Config.say.start)
end
end
end
function PLUGIN:StopTheGames()
rustyGames.inProgress = false
rustyGames.tributes = {}
end
function PLUGIN:SpawnTributes()
points = #rustyGames.tributes
radius = 50
center = {}
center.x = 5500
center.y = 1000
center.z = -5250
slice = 2 * math.pi / points
coords = {}
for i=1,points,1 do
self:Log("SpawnTributes: i=" .. i .. " points=" .. points)
angle = slice * i-1
local b, targetuser = rust.FindNetUsersByName(rustyGames.tributes[i])
local coords = targetuser.playerClient.lastKnownPosition
coords.x = math.floor(center.x + radius * math.cos(angle))
coords.y = math.floor(center.y + radius * math.sin(angle))
coords.z = center.z
self:Log("Target user: " .. targetuser.playerClient.userName)
self:Log("Target X:" .. coords.x .. " Y:" .. coords.y .. " Z:" .. coords.z)
if (b) then
rust.ServerManagement():TeleportPlayer(targetuser.playerClient.netPlayer, coords)
end
end
end
function PLUGIN:OnSpawnPlayer(playerClient, useCamp, avatar)
if (not rustyGames.inProgress) then return end
playerClient.netUser:Kick(NetError.Facepunch_Kick_RCON, true)
end
function PLUGIN:OnUserDisconnect(networkPlayer)
local netUser = networkPlayer:GetLocalData()
self:RemoveTribute(self:FindTribute(netUser.playerClient.userName))
end
function PLUGIN:RemoveTribute(key)
if (not key) then return end
self:BroadcastChat(rustyGames.tributes[key] .. " " .. self.Config.say.loser)
table.remove(rustyGames.tributes, key)
self:CheckWin()
end
function PLUGIN:FindTribute(userName)
for key, value in pairs(rustyGames.tributes) do
if (value == userName) then return key end
end
end
function PLUGIN:CheckWin()
if (#rustyGames.tributes < 2) then
self:BroadcastChat("There is only one player remaining! " .. rustyGames.tributes[1] .. " has won the Rusty Games!")
self:StopTheGames()
end
end
function PLUGIN:BroadcastChat(msg)
if (self.Config.broadcastChat) then rust.BroadcastChat(self.Config.chatName, msg) end
end
function PLUGIN:Log(msg)
if (self.Config.log) then print(self.Title .. ": " .. msg) end
end