-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·342 lines (289 loc) · 8.36 KB
/
init.lua
File metadata and controls
executable file
·342 lines (289 loc) · 8.36 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
---@type Plugin
local mode = ...
mode.name = 'Sandbox'
mode.author = 'jdb'
mode.description = 'Do whatever.'
local server = server
local vehiclesGetAll = vehicles.getAll
local itemsGetAll = items.getAll
local humansGetAll = humans.getAll
local bulletsGetAll = bullets.getAll
local rigidBodiesGetAll = rigidBodies.getAll
local physicsLineIntersectAnyQuick = physics.lineIntersectAnyQuick
local HOOK_OVERRIDE = hook.override
local SAVE_PROFILES_TICKS = server.TPS * 6
-- local SUN_SPEED = 100
-- local TIME_MIDNIGHT = server.TPS * 60 * 60 * 24
local saveProfilesTicks
mode:require('reset')
mode:require('menu')
local util = mode:require('util')
local tools = mode:require('tools')
local utilAreMutualFriends = util.areMutualFriends
local utilHasFriendAdded = util.hasFriendAdded
local utilLineIntersectAllQuick = util.lineIntersectAllQuick
local utilAlertNotFriendInfrequently = util.alertNotFriendInfrequently
function mode.onEnable (isReload)
util.loadProfiles()
saveProfilesTicks = 0
if not isReload then
server:reset()
end
end
function mode.onDisable ()
saveProfilesTicks = nil
end
mode:addHook(
'Logic',
function ()
saveProfilesTicks = saveProfilesTicks + 1
if saveProfilesTicks >= SAVE_PROFILES_TICKS then
saveProfilesTicks = 0
util.saveProfilesIfDirty()
end
-- server.sunTime = (server.sunTime + SUN_SPEED) % TIME_MIDNIGHT
end
)
mode:addHook(
'ServerReceive',
function ()
server.type = TYPE_WORLD
end
)
mode:addHook(
'PostServerReceive',
function ()
server.type = 20
end
)
-- Global text chat
function mode.hooks.PlayerChat (ply, message)
if message:gsub('%W',''):lower():find('nigge') then
message = "i'm an idiot"
end
local str = string.format('<%s> %s', ply.name, message)
chat.announceWrap(str)
local man = ply.human
if man then
man:speak(message, 1)
end
if log then
log('[Chat][G] %s (%s): %s', ply.name, dashPhoneNumber(ply.phoneNumber), message)
end
return HOOK_OVERRIDE
end
function mode.hooks.HumanDelete (man)
util.abortTools(tools, man)
end
function mode.hooks.PostHumanDelete (man)
util.eraseUndosWhere('obj', man)
util.clearOrphanedBonds()
util.clearOrphanedBotPlayers()
end
function mode.hooks.PlayerDelete (ply)
if ply.isBot then return end
local man = ply.human
if man then
util.abortTools(tools, man)
util.eraseObjectBodyUndos(man)
man:remove()
util.clearOrphanedBonds()
end
local phone = ply.phoneNumber
util.clearObjects(phone, vehiclesGetAll())
util.clearObjects(phone, itemsGetAll())
util.clearBots(phone)
end
local tpaRequests = {}
mode.commands['/tpa'] = {
info = "Teleport to somebody.",
---@param ply Player
---@param man Human?
---@param args string[]
call = function (ply, man, args)
if not man or args[1] == nil then return end
local victimPly = findOnePlayer(table.concat(args, ' '))
assert(victimPly ~= ply, 'You cannot teleport to yourself')
local victimMan = victimPly.human
if not victimMan then
error(string.format('%s is not spawned in', victimPly.name))
end
victimPly:sendMessage(string.format('%s has requested to teleport to you!', ply.name))
victimPly:sendMessage('Type /tpaccept to accept.')
tpaRequests[victimPly.phoneNumber] = ply.phoneNumber
ply:sendMessage('Request sent.')
end
}
mode.commands['/tpaccept'] = {
info = "Accept a teleport request.",
---@param victimPly Player
---@param victimMan Human?
call = function (victimPly, victimMan)
if not victimMan then return end
local ply = players.getByPhone(tpaRequests[victimPly.phoneNumber])
assert(ply, 'No teleport requst found')
local man = ply.human
assert(man, string.format('%s is not spawned in.', ply.name))
if man.vehicle then
man.vehicle = nil
end
tpaRequests[victimPly.phoneNumber] = nil
local pos = victimMan.pos:clone()
pos.x = pos.x + 1
pos.y = pos.y + 0.2
man:teleport(pos)
man:setVelocity(Vector())
end
}
mode:addHook(
'Physics',
function ()
local origin = Vector()
for _, vcl in ipairs(vehiclesGetAll()) do
local speed = vcl.vel:distSquare(origin)
if speed > 4 then
util.eraseObjectBodyUndos(vcl)
vcl:remove()
util.eraseUndosWhere('obj', vcl)
util.clearOrphanedBonds()
end
end
for _, item in ipairs(itemsGetAll()) do
if item.hasPhysics or item.physicsSettled then
local speed = item.vel:distSquare(origin)
if speed > 4 then
util.eraseObjectBodyUndos(item)
item:remove()
util.eraseUndosWhere('obj', item)
util.clearOrphanedBonds()
elseif item.data.sandboxCreatorPhone then
item.despawnTime = 65536
end
end
end
for _, man in ipairs(humansGetAll()) do
local speed = man:getRigidBody(0).vel:distSquare(origin)
if speed > 4 then
util.abortTools(tools, man)
util.eraseObjectBodyUndos(man)
man:remove()
util.eraseUndosWhere('obj', man)
util.clearOrphanedBonds()
util.clearOrphanedBotPlayers()
elseif man.data.sandboxRagdoll then
man.despawnTime = 65536
end
end
for _, body in ipairs(rigidBodiesGetAll()) do
local data = body.data
local pos = data.sandboxFreezePos
if pos then
body.isSettled = true
body.pos:set(pos)
body.vel:set(Vector())
body.rot:set(data.sandboxFreezeRot)
body.rotVel:set(RotMatrix())
end
end
end
)
function mode.hooks.CollideBodies (aBody, bBody)
local aData = aBody.data
local bData = bBody.data
if aData.sandboxNoCollideAll or bData.sandboxNoCollideAll then
return HOOK_OVERRIDE
end
local aPhone = aData.sandboxCreatorPhone
if not aPhone then return HOOK_OVERRIDE end
local bPhone = bData.sandboxCreatorPhone
if not bPhone then return HOOK_OVERRIDE end
if aPhone == bPhone then return end
if utilAreMutualFriends(aPhone, bPhone) then return end
return HOOK_OVERRIDE
end
function mode.hooks.ItemLink (item, _, parentHuman)
if item and parentHuman then
local itemPhone = item.data.sandboxCreatorPhone
if itemPhone then
local manPhone = parentHuman.data.sandboxCreatorPhone
if manPhone then
if itemPhone ~= manPhone and not utilHasFriendAdded(itemPhone, manPhone) then
local ply = parentHuman.player
if ply then
utilAlertNotFriendInfrequently(ply, parentHuman, itemPhone)
end
return HOOK_OVERRIDE
end
end
end
end
end
function mode.hooks.HumanGrabbing (man)
local phone = man.data.sandboxCreatorPhone
if not phone then return end
if man.rightHandGrab then
local otherPhone = man.rightHandGrab.data.sandboxCreatorPhone
if otherPhone and otherPhone ~= phone and not utilHasFriendAdded(otherPhone, phone) then
man.rightHandGrab = nil
local ply = man.player
if ply then
utilAlertNotFriendInfrequently(ply, man, otherPhone)
end
end
end
if man.leftHandGrab then
local otherPhone = man.leftHandGrab.data.sandboxCreatorPhone
if otherPhone and otherPhone ~= phone and not utilHasFriendAdded(otherPhone, phone) then
man.leftHandGrab = nil
local ply = man.player
if ply then
utilAlertNotFriendInfrequently(ply, man, otherPhone)
end
end
end
end
function mode.hooks.HumanCollisionVehicle (man, vcl)
local phone = man.data.sandboxCreatorPhone
if not phone then return end
local vclPhone = vcl.data.sandboxCreatorPhone
if not vclPhone then return end
if phone ~= vclPhone and not utilHasFriendAdded(phone, vclPhone) then
local ply = man.player
if ply then
utilAlertNotFriendInfrequently(ply, man, vclPhone)
end
return HOOK_OVERRIDE
end
end
function mode.hooks.PhysicsBullets ()
local doGC = false
for _, bullet in ipairs(bulletsGetAll()) do
local ply = bullet.player
local man = ply.human
if man then
local obj = physicsLineIntersectAnyQuick(bullet.lastPos, bullet.lastPos + bullet.vel, man)
if obj then
local phone = man.data.sandboxCreatorPhone
if phone then
local objPhone = obj.data.sandboxCreatorPhone
if objPhone then
if phone ~= objPhone and not utilHasFriendAdded(objPhone, phone) then
bullet.time = -1
doGC = true
utilAlertNotFriendInfrequently(ply, man, objPhone)
end
else
bullet.time = -1
doGC = true
end
end
end
else
bullet.time = -1
doGC = true
end
end
if doGC then
physics.garbageCollectBullets()
end
end