-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.lua
185 lines (160 loc) · 6.12 KB
/
main.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
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
NDCore = {}
NDCore.players = {}
PlayersInfo = {}
local resourceName = GetCurrentResourceName()
local tempPlayersInfo = {}
Config = {
serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"),
discordInvite = GetConvar("core:discordInvite", "https://discord.gg/Z9Mxu72zZ6"),
discordMemeberRequired = GetConvarInt("core:discordMemeberRequired", 1) == 1,
discordAppId = GetConvar("core:discordAppId", "858146067018416128"),
discordAsset = GetConvar("core:discordAsset", "andyyy"),
discordAssetSmall = GetConvar("core:discordAssetSmall", "andyyy"),
discordActionText = GetConvar("core:discordActionText", "DISCORD"),
discordActionLink = GetConvar("discordActionLink", "https://discord.gg/Z9Mxu72zZ6"),
discordActionText2 = GetConvar("core:discordActionText2", "STORE"),
discordActionLink2 = GetConvar("core:discordActionLink2", "https://andyyy.tebex.io/category/fivem-scripts"),
characterIdentifier = GetConvar("core:characterIdentifier", "license"),
discordGuildId = GetConvar("core:discordGuildId", "false"),
discordBotToken = GetConvar("core:discordBotToken", "false"),
randomUnlockedVehicleChance = GetConvarInt("core:randomUnlockedVehicleChance", 30),
disableVehicleAirControl = GetConvarInt("core:disableVehicleAirControl", 1) == 1,
useInventoryForKeys = GetConvarInt("core:useInventoryForKeys", 1) == 1,
groups = json.decode(GetConvar("core:groups", "[]")),
admins = json.decode(GetConvar("core:admins", "[]")),
adminDiscordRoles = json.decode(GetConvar("core:adminDiscordRoles", "[]")),
groupRoles = json.decode(GetConvar("core:groupRoles", "[]")),
multiCharacter = false,
compatibility = json.decode(GetConvar("core:compatibility", "[]")),
sv_lan = GetConvar("sv_lan", "false") == "true",
}
SetConvarServerInfo("Discord", Config.discordInvite)
SetConvarServerInfo("NDCore", GetResourceMetadata(resourceName, "version", 0) or "invalid")
SetConvarReplicated("inventory:framework", "nd")
local function getIdentifierList(src)
local list = {}
for i=0, GetNumPlayerIdentifiers(src) do
local identifier = GetPlayerIdentifier(src, i)
if identifier then
local colon = identifier:find(":")
local identifierType = identifier:sub(1, colon-1)
list[identifierType] = identifier
end
end
if Config.sv_lan then
list[Config.characterIdentifier] = NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)
end
return list
end
AddEventHandler("playerJoining", function(oldId)
local src = source
local oldTempId = tonumber(oldId)
PlayersInfo[src] = tempPlayersInfo[oldTempId]
tempPlayersInfo[oldTempId] = nil
if Config.sv_lan then
lib.addPrincipal(("player.%s"):format(src), "group.admin")
end
if Config.multiCharacter then return end
Wait(3000)
local characters = NDCore.fetchAllCharacters(src)
local id = next(characters)
if id then
return NDCore.setActiveCharacter(src, id)
end
local player = NDCore.newCharacter(src, {
firstname = GetPlayerName(src),
lastname = "",
dob = "",
gender = ""
})
NDCore.setActiveCharacter(src, player.id)
end)
local function checkDiscordIdentifier(identifiers)
if Config.discordBotToken == "false" or Config.discordGuildId == "false" then return end
local discordIdentifier = identifiers["discord"]
if not discordIdentifier then return end
return NDCore.getDiscordInfo(discordIdentifier:gsub("discord:", ""))
end
AddEventHandler("onResourceStart", function(name)
if name ~= resourceName then return end
for _, playerId in ipairs(GetPlayers()) do
local src = tonumber(playerId)
local identifiers = getIdentifierList(src)
PlayersInfo[src] = {
identifiers = identifiers,
discord = checkDiscordIdentifier(identifiers) or {}
}
Wait(65)
end
end)
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
local tempSrc = source
local identifiers = getIdentifierList(tempSrc)
local mainIdentifier = identifiers[Config.characterIdentifier]
local discordInfo = nil
deferrals.defer()
Wait(0)
if mainIdentifier and Config.discordBotToken ~= "false" and Config.discordGuildId ~= "false" then
discordInfo = checkDiscordIdentifier(identifiers)
if not discordInfo and Config.discordMemeberRequired and not Config.sv_lan then
deferrals.done(("Your discord was not found, join our discord here: %s."):format(Config.discordInvite))
Wait(0)
end
end
deferrals.update("Connecting...")
Wait(0)
if Config.sv_lan then
tempPlayersInfo[tempSrc] = {
identifiers = {
[Config.characterIdentifier] = "sv_lan"
},
discord = discordInfo
}
deferrals.done()
return
end
if mainIdentifier then
tempPlayersInfo[tempSrc] = {
identifiers = identifiers,
discord = discordInfo
}
deferrals.done()
else
deferrals.done(("Your %s was not found."):format(Config.characterIdentifier))
Wait(0)
end
end)
AddEventHandler("playerDropped", function()
local src = source
local char = NDCore.players[src]
if char then char.unload() end
PlayersInfo[src] = nil
end)
AddEventHandler("onResourceStop", function(name)
if name ~= resourceName then return end
for _, player in pairs(NDCore.players) do
player.unload()
Wait(10)
end
end)
MySQL.ready(function()
NDCore.loadSQL({
"database/characters.sql",
"database/vehicles.sql"
}, resourceName)
end)
RegisterNetEvent("ND:playerEliminated", function(info)
local src = source
local player = NDCore.getPlayer(src)
if not player then return end
player.setMetadata({
dead = true,
deathInfo = info
})
end)
RegisterNetEvent("ND:updateClothing", function(clothing)
local src = source
local player = NDCore.getPlayer(src)
if not player or not clothing or type(clothing) ~= "table" then return end
player.setMetadata("clothing", clothing)
end)