9 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
6 changed files with 31 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
<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>

View File

@@ -10,6 +10,27 @@ 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 -- Callbacks are licensed under LGPL v3.0
-- <https://github.com/overextended/ox_lib> -- <https://github.com/overextended/ox_lib>
NDCore.callback = {} NDCore.callback = {}
@@ -56,4 +77,4 @@ function NDCore.callback.register(name, callback)
RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...) RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...)
TriggerServerEvent("ND:callbacks", key, callback(...)) TriggerServerEvent("ND:callbacks", key, callback(...))
end) end)
end end

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"
@@ -36,4 +36,4 @@ server_exports {
"GetCoreObject" "GetCoreObject"
} }
dependency "oxmysql" dependency "oxmysql"

View File

@@ -83,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

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
@@ -767,4 +763,4 @@ function NDCore.callback.register(name, callback)
local src = source local src = source
TriggerClientEvent("ND:callbacks", src, key, callback(src, ...)) TriggerClientEvent("ND:callbacks", src, key, callback(src, ...))
end) end)
end end

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")