This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggleVehicleSpawns.lua
80 lines (65 loc) · 2.81 KB
/
ToggleVehicleSpawns.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
80
-- List of permitted user names
local permittedUsers = {
"User1",
"User2",
"User3"
}
-- Variable to track the vehicle spawning state
local isVehicleSpawningEnabled = true
-- Command handler for the toggle command and adduser command
function onChatMessage(playerId, name, message)
-- Check if the player is in the list of permitted users
if IsUserPermitted(name) then
-- Check if the message is the toggle command
if message == "/togglespawn" then
-- Toggle the vehicle spawning state
isVehicleSpawningEnabled = not isVehicleSpawningEnabled
-- Send a chat message to all players indicating the new state
local status = isVehicleSpawningEnabled and "enabled" or "disabled"
MP.SendChatMessage(-1, "Vehicle spawning has been " .. status .. " by " .. name)
-- Send a chat message to the permitted player confirming the toggle
MP.SendChatMessage(playerId, "Vehicle spawning has been " .. status .. " successfully.")
-- Print debug message to the console
print("Vehicle spawning toggled " .. status .. " by " .. name)
end
-- Check if the message is the adduser command
local command, user = string.match(message, "^/adduser%s+(%w+)$")
if command and user then
-- Add the user to the list of permitted users
table.insert(permittedUsers, user)
-- Send a chat message to the player indicating the user has been added
MP.SendChatMessage(playerId, "User " .. user .. " has been added to the permitted users list.")
-- Print debug message to the console
print("User " .. user .. " added to the permitted users list by " .. name)
end
end
end
-- Register the chat message event
MP.RegisterEvent("onChatMessage", "onChatMessage")
-- Event handler for vehicle spawning
function onVehicleSpawn(playerId, vehicleId, data)
-- Check if vehicle spawning is enabled
if not isVehicleSpawningEnabled then
-- Cancel the vehicle spawn
return 1
end
end
-- Register the vehicle spawning event
MP.RegisterEvent("onVehicleSpawn", "onVehicleSpawn")
-- Function to check if a player is in the list of permitted users
function IsUserPermitted(name)
-- Check if the player's name is in the permitted users list
for _, user in ipairs(permittedUsers) do
if user == name then
return true
end
end
return false
end
-- Event handler for script initialization
function onInit()
-- Print a message to the console indicating that the script has initialized
print("Toggle vehicle spawning script initialized.")
end
-- Register the onInit event
MP.RegisterEvent("onInit", "onInit")