mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9d8826188 | ||
|
|
7412c14976 | ||
|
|
5242cf289d | ||
|
|
906383bbd9 | ||
|
|
a5b297e6f8 | ||
|
|
4551db736c | ||
|
|
30ac126949 | ||
|
|
220ecbbce1 | ||
|
|
9a7afdbc8f | ||
|
|
1b6870dd87 | ||
|
|
aa73db1111 | ||
|
|
68563c6d18 | ||
|
|
a9d42b9861 | ||
|
|
eac4de4623 | ||
|
|
08815f2ecd | ||
|
|
88e8a4218a | ||
|
|
99b8d85901 | ||
|
|
378e552fe7 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
config_server.lua
|
||||||
18
README.md
18
README.md
@@ -1,22 +1,28 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://user-images.githubusercontent.com/86536434/193703880-5cb7deef-af37-42cc-8df2-b13332afee67.png" />
|
<img src="https://user-images.githubusercontent.com/86536434/193703880-5cb7deef-af37-42cc-8df2-b13332afee67.png" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align='center'><b><a href="discord.gg/nc82d8zvjm">Discord</a></b>
|
<p align='center'><b><a href="discord.gg/nc82d8zvjm">Discord</a></b>
|
||||||
|
|
||||||
<p align='center'><b><a href="https://ndframework.gitbook.io/nd-framework/">Documentation</a></b>
|
<p align='center'><b><a href="https://ndfw.gitbook.io/nd-framework/">Documentation</a></b>
|
||||||
|
|
||||||
## Dependency:
|
## Dependency:
|
||||||
[oxmysql](https://github.com/overextended/oxmysql/releases/download/v2.4.0/oxmysql.zip)
|
[oxmysql](https://github.com/overextended/oxmysql/releases/download/v2.4.0/oxmysql.zip)
|
||||||
|
|
||||||
## Addons
|
## Addons
|
||||||
|
|
||||||
|
* [Ox Inventory](https://github.com/overextended/ox_inventory/releases)
|
||||||
* [Character Selection](https://github.com/ND-Framework/ND_CharacterSelection)
|
* [Character Selection](https://github.com/ND-Framework/ND_CharacterSelection)
|
||||||
|
* [No Characters (use framework without character selection)](https://github.com/ND-Framework/ND_NoCharacters)
|
||||||
|
* [Vehicle System](https://github.com/ND-Framework/ND_VehicleSystem)
|
||||||
|
* [Dealerships](https://github.com/ND-Framework/ND_Dealership)
|
||||||
* [Fuel (with nozzle and hose)](https://github.com/ND-Framework/ND_Fuel)
|
* [Fuel (with nozzle and hose)](https://github.com/ND-Framework/ND_Fuel)
|
||||||
|
* [Nitro](https://github.com/ND-Framework/ND_Nitro)
|
||||||
* [Shot Spotter](https://github.com/ND-Framework/ND_ShotSpotter)
|
* [Shot Spotter](https://github.com/ND-Framework/ND_ShotSpotter)
|
||||||
* [Banking](https://github.com/ND-Framework/ND_Banking)
|
* [Banking](https://github.com/ND-Framework/ND_Banking)
|
||||||
* [Door locks](https://github.com/ND-Framework/ND_Doorlocks)
|
* [Doorlocks](https://github.com/ND-Framework/ND_Doorlocks)
|
||||||
* [Ox Inventory](https://github.com/overextended/ox_inventory/releases)
|
* [Properties](https://github.com/ND-Framework/ND_Properties)
|
||||||
* [No Characters (use framework without character selection)](https://github.com/ND-Framework/ND_NoCharacters)
|
* [Appearance Shops](https://github.com/ND-Framework/ND_AppearanceShops)
|
||||||
|
|
||||||
# Need support?
|
# Need support?
|
||||||
[](https://discord.gg/Z9Mxu72zZ6)
|
[](https://discord.gg/Z9Mxu72zZ6)
|
||||||
|
|||||||
@@ -8,4 +8,73 @@ end
|
|||||||
|
|
||||||
function NDCore.Functions.GetCharacters()
|
function NDCore.Functions.GetCharacters()
|
||||||
return NDCore.Characters
|
return NDCore.Characters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function NDCore.Functions.GetPlayersFromCoords(distance, coords)
|
||||||
|
if coords then
|
||||||
|
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
|
||||||
|
else
|
||||||
|
coords = GetEntityCoords(PlayerPedId())
|
||||||
|
end
|
||||||
|
distance = distance or 5
|
||||||
|
local closePlayers = {}
|
||||||
|
local players = GetActivePlayers()
|
||||||
|
for _, player in ipairs(players) do
|
||||||
|
local target = GetPlayerPed(player)
|
||||||
|
local targetCoords = GetEntityCoords(target)
|
||||||
|
local targetdistance = #(targetCoords - coords)
|
||||||
|
if targetdistance <= distance then
|
||||||
|
closePlayers[#closePlayers + 1] = player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return closePlayers
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Callbacks are licensed under LGPL v3.0
|
||||||
|
-- <https://github.com/overextended/ox_lib>
|
||||||
|
NDCore.callback = {}
|
||||||
|
local events = {}
|
||||||
|
|
||||||
|
RegisterNetEvent("ND:callbacks", function(key, ...)
|
||||||
|
local cb = events[key]
|
||||||
|
return cb and cb(...)
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function triggerCallback(_, name, cb, ...)
|
||||||
|
local key = ("%s:%s"):format(name, math.random(0, 100000))
|
||||||
|
TriggerServerEvent(("ND:%s_cb"):format(name), key, ...)
|
||||||
|
|
||||||
|
local promise = not cb and promise.new()
|
||||||
|
|
||||||
|
events[key] = function(response, ...)
|
||||||
|
response = { response, ... }
|
||||||
|
events[key] = nil
|
||||||
|
|
||||||
|
if promise then
|
||||||
|
return promise:resolve(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
if cb then
|
||||||
|
cb(table.unpack(response))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if promise then
|
||||||
|
return table.unpack(Citizen.Await(promise))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(NDCore.callback, {
|
||||||
|
__call = triggerCallback
|
||||||
|
})
|
||||||
|
|
||||||
|
function NDCore.callback.await(name, ...)
|
||||||
|
return triggerCallback(nil, name, false, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
function NDCore.callback.register(name, callback)
|
||||||
|
RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...)
|
||||||
|
TriggerServerEvent("ND:callbacks", key, callback(...))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
author "Andyyy#7666, N1K0#0001"
|
author "Andyyy#7666, N1K0#0001"
|
||||||
description "ND Framework Core"
|
description "ND Framework Core"
|
||||||
version "1.0.0"
|
version "1.0.3"
|
||||||
|
|
||||||
fx_version "cerulean"
|
fx_version "cerulean"
|
||||||
game "gta5"
|
game "gta5"
|
||||||
@@ -15,16 +15,17 @@ shared_scripts {
|
|||||||
client_scripts {
|
client_scripts {
|
||||||
"client/main.lua",
|
"client/main.lua",
|
||||||
"client/functions.lua",
|
"client/functions.lua",
|
||||||
"client/events.lua"
|
"client/events.lua",
|
||||||
|
"shared/import.lua"
|
||||||
}
|
}
|
||||||
|
|
||||||
server_scripts {
|
server_scripts {
|
||||||
"@oxmysql/lib/MySQL.lua",
|
"@oxmysql/lib/MySQL.lua",
|
||||||
"config_server.lua",
|
"config_server.lua",
|
||||||
"server/main.lua",
|
"server/main.lua",
|
||||||
"server/functions.lua",
|
"server/functions.lua",
|
||||||
"server/events.lua",
|
"server/events.lua",
|
||||||
"server/commands.lua"
|
"server/commands.lua",
|
||||||
|
"shared/import.lua"
|
||||||
}
|
}
|
||||||
|
|
||||||
exports {
|
exports {
|
||||||
@@ -35,4 +36,4 @@ server_exports {
|
|||||||
"GetCoreObject"
|
"GetCoreObject"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependency "oxmysql"
|
dependency "oxmysql"
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ end)
|
|||||||
-- Update the characters clothes.
|
-- Update the characters clothes.
|
||||||
RegisterNetEvent("ND:updateClothes", function(clothing)
|
RegisterNetEvent("ND:updateClothes", function(clothing)
|
||||||
local player = source
|
local player = source
|
||||||
NDCore.Functions.SetPlayerData(player, "clothing", clothing)
|
local character = NDCore.Players[player]
|
||||||
|
NDCore.Functions.SetPlayerData(character.id, "clothing", clothing)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Disconnecting a player
|
-- Disconnecting a player
|
||||||
@@ -82,7 +83,9 @@ AddEventHandler("playerDropped", function()
|
|||||||
local player = source
|
local player = source
|
||||||
local character = NDCore.Players[player]
|
local character = NDCore.Players[player]
|
||||||
if character then
|
if character then
|
||||||
NDCore.Functions.UpdateLastLocation(character.id, character.lastLocation)
|
local ped = GetPlayerPed(player)
|
||||||
|
local lastLocation = GetEntityCoords(ped)
|
||||||
|
NDCore.Functions.UpdateLastLocation(character.id, {x = lastLocation.x, y = lastLocation.y, z = lastLocation.z})
|
||||||
end
|
end
|
||||||
TriggerEvent("ND:characterUnloaded", player, character)
|
TriggerEvent("ND:characterUnloaded", player, character)
|
||||||
character = nil
|
character = nil
|
||||||
@@ -111,4 +114,4 @@ AddEventHandler("onResourceStart", function(resourceName)
|
|||||||
NDCore.PlayersDiscordInfo[tonumber(playerId)] = discordInfo
|
NDCore.PlayersDiscordInfo[tonumber(playerId)] = discordInfo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -343,16 +343,12 @@ function NDCore.Functions.GetPlayerCharacters(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Creates a new character for the player and returns all their characters to the client.
|
-- Creates a new character for the player and returns all their characters to the client.
|
||||||
function NDCore.Functions.CreateCharacter(player, firstName, lastName, dob, gender, cash, bank, cb)
|
function NDCore.Functions.CreateCharacter(player, firstName, lastName, dob, gender, cb)
|
||||||
local characterId = false
|
local characterId = false
|
||||||
local license = NDCore.Functions.GetPlayerIdentifierFromType("license", player)
|
local license = NDCore.Functions.GetPlayerIdentifierFromType("license", player)
|
||||||
if not cash or not bank or tonumber(cash) > config.startingCash or tonumber(bank) > config.startingBank then
|
|
||||||
cash = config.startingCash
|
|
||||||
bank = config.startingBank
|
|
||||||
end
|
|
||||||
local result = MySQL.query.await("SELECT character_id FROM characters WHERE license = ?", {license})
|
local result = MySQL.query.await("SELECT character_id FROM characters WHERE license = ?", {license})
|
||||||
if result and config.characterLimit > #result then
|
if result and config.characterLimit > #result then
|
||||||
characterId = MySQL.insert.await("INSERT INTO characters (license, first_name, last_name, dob, gender, cash, bank) VALUES (?, ?, ?, ?, ?, ?, ?)", {license, firstName, lastName, dob, gender, cash, bank})
|
characterId = MySQL.insert.await("INSERT INTO characters (license, first_name, last_name, dob, gender, cash, bank, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", {license, firstName, lastName, dob, gender, config.startingCash, config.startingBank, json.encode({groups={}})})
|
||||||
if cb then cb(characterId) end
|
if cb then cb(characterId) end
|
||||||
TriggerClientEvent("ND:returnCharacters", player, NDCore.Functions.GetPlayerCharacters(player))
|
TriggerClientEvent("ND:returnCharacters", player, NDCore.Functions.GetPlayerCharacters(player))
|
||||||
end
|
end
|
||||||
@@ -690,6 +686,7 @@ function NDCore.Functions.VersionChecker(expectedResourceName, resourceName, dow
|
|||||||
end
|
end
|
||||||
PerformHttpRequest(rawGithubLink, function(errorCode, resultData, resultHeaders)
|
PerformHttpRequest(rawGithubLink, function(errorCode, resultData, resultHeaders)
|
||||||
local i, j = tostring(resultData):find("version")
|
local i, j = tostring(resultData):find("version")
|
||||||
|
if not i or not j then return end
|
||||||
local resultData = tostring(resultData):sub(i, j + 12)
|
local resultData = tostring(resultData):sub(i, j + 12)
|
||||||
local resultData = resultData:gsub("version \"", "")
|
local resultData = resultData:gsub("version \"", "")
|
||||||
local i, j = resultData:find("\"")
|
local i, j = resultData:find("\"")
|
||||||
@@ -717,3 +714,53 @@ function NDCore.Functions.VersionChecker(expectedResourceName, resourceName, dow
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
NDCore.Functions.VersionChecker("ND_Core", GetCurrentResourceName(), "https://github.com/ND-Framework/ND_Core", "https://raw.githubusercontent.com/ND-Framework/ND_Core/main/fxmanifest.lua")
|
NDCore.Functions.VersionChecker("ND_Core", GetCurrentResourceName(), "https://github.com/ND-Framework/ND_Core", "https://raw.githubusercontent.com/ND-Framework/ND_Core/main/fxmanifest.lua")
|
||||||
|
|
||||||
|
|
||||||
|
-- Callbacks are licensed under LGPL v3.0
|
||||||
|
-- <https://github.com/overextended/ox_lib>
|
||||||
|
NDCore.callback = {}
|
||||||
|
local events = {}
|
||||||
|
|
||||||
|
RegisterNetEvent("ND:callbacks", function(key, ...)
|
||||||
|
local cb = events[key]
|
||||||
|
return cb and cb(...)
|
||||||
|
end)
|
||||||
|
|
||||||
|
function triggerCallback(_, name, playerId, cb, ...)
|
||||||
|
local key = ("%s:%s:%s"):format(name, math.random(0, 100000), playerId)
|
||||||
|
TriggerClientEvent(("ND:%s_cb"):format(name), playerId, key, ...)
|
||||||
|
|
||||||
|
local promise = not cb and promise.new()
|
||||||
|
|
||||||
|
events[key] = function(response, ...)
|
||||||
|
response = { response, ... }
|
||||||
|
events[key] = nil
|
||||||
|
|
||||||
|
if promise then
|
||||||
|
return promise:resolve(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
if cb then
|
||||||
|
cb(table.unpack(response))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if promise then
|
||||||
|
return table.unpack(Citizen.Await(promise))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(NDCore.callback, {
|
||||||
|
__call = triggerCallback
|
||||||
|
})
|
||||||
|
|
||||||
|
function NDCore.callback.await(name, playerId, ...)
|
||||||
|
return triggerCallback(nil, name, playerId, false, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
function NDCore.callback.register(name, callback)
|
||||||
|
RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...)
|
||||||
|
local src = source
|
||||||
|
TriggerClientEvent("ND:callbacks", src, key, callback(src, ...))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|||||||
@@ -11,20 +11,6 @@ function GetCoreObject()
|
|||||||
return NDCore
|
return NDCore
|
||||||
end
|
end
|
||||||
|
|
||||||
CreateThread(function()
|
|
||||||
while true do
|
|
||||||
Wait(30000)
|
|
||||||
for player, playerInfo in pairs(NDCore.Players) do
|
|
||||||
local ped = GetPlayerPed(player)
|
|
||||||
if DoesEntityExist(ped) then
|
|
||||||
local lastLocation = GetEntityCoords(ped)
|
|
||||||
playerInfo.lastLocation = {x = lastLocation.x, y = lastLocation.y, z = lastLocation.z}
|
|
||||||
TriggerClientEvent("ND:updateLastLocation", player, playerInfo.lastLocation)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
isResourceStarted("ox_inventory", function(started)
|
isResourceStarted("ox_inventory", function(started)
|
||||||
if not started then return end
|
if not started then return end
|
||||||
SetConvarReplicated("inventory:framework", "nd")
|
SetConvarReplicated("inventory:framework", "nd")
|
||||||
|
|||||||
1
shared/import.lua
Normal file
1
shared/import.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
NDCore = exports["ND_Core"]:GetCoreObject()
|
||||||
Reference in New Issue
Block a user