18 Commits
Author SHA1 Message Date
Andyyy7666 e9d8826188 Update fxmanifest.lua 2023-01-11 13:16:33 +01:00
Andyyy7666 7412c14976 Merge pull request #35 from Dark3581/patch-1
feat(server/functions): GetPlayersFromCoords
2023-01-11 13:03:02 +01:00
Andyyy7666 5242cf289d perf: updating last location 2023-01-05 17:05:50 +01:00
Andyyy7666 906383bbd9 fix: groups nil 2023-01-04 19:30:50 +01:00
Dark3581 a5b297e6f8 ipair 2023-01-03 18:24:38 -08:00
Dark3581 4551db736c requested changes 2023-01-03 18:18:54 -08:00
Dark3581 30ac126949 GetPlayersFromCoords - Converted from qb/esx
gets all players within an area
2022-12-27 12:33:36 -08:00
Niko 220ecbbce1 Refactor: speed * 10000000 2022-12-26 18:15:57 -05:00
Andyyy7666 9a7afdbc8f refactor: starting bank & cash 2022-12-26 00:19:45 +01:00
Andyyy7666 1b6870dd87 Create .gitignore 2022-12-25 16:50:31 +01:00
Andyyy7666 aa73db1111 fix: index id twice 2022-12-25 16:46:25 +01:00
Andyyy7666 68563c6d18 fix: saving clothes by character id error 2022-12-25 16:39:49 +01:00
Andyyy7666 a9d42b9861 Update README.md 2022-12-25 14:50:25 +01:00
Andyyy7666 eac4de4623 feat: import core object 2022-12-24 17:01:28 +01:00
Andyyy7666 08815f2ecd feat: callbacks 2022-12-24 17:01:07 +01:00
Andyyy7666 88e8a4218a fix: nil value in version checker from wrong links 2022-12-19 19:54:43 +01:00
Andyyy7666 99b8d85901 Merge pull request #34 from marshular/main
Added more addons to list
2022-12-19 19:43:33 +01:00
Marshular's Development 378e552fe7 Added more addons to list 2022-12-19 10:41:04 -08:00
8 changed files with 150 additions and 35 deletions
+2
View File
@@ -0,0 +1,2 @@
config_server.lua
+12 -6
View File
@@ -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?
[![Need Support?](https://user-images.githubusercontent.com/86536434/147299047-73691b78-2690-4786-b58b-27d24e48a0d2.png)](https://discord.gg/Z9Mxu72zZ6) [![Discord](https://discordapp.com/api/guilds/857672921912836116/widget.png?style=banner3)](https://discord.gg/Z9Mxu72zZ6)
+70 -1
View File
@@ -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
+6 -5
View File
@@ -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"
+6 -3
View File
@@ -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)
+53 -6
View File
@@ -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
-14
View File
@@ -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
View File
@@ -0,0 +1 @@
NDCore = exports["ND_Core"]:GetCoreObject()