mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
@@ -29,4 +29,4 @@ AddEventHandler("playerSpawned", function()
|
|||||||
print("^0ND Framework support discord: ^5https://discord.gg/Z9Mxu72zZ6")
|
print("^0ND Framework support discord: ^5https://discord.gg/Z9Mxu72zZ6")
|
||||||
SetCanAttackFriendly(PlayerPedId(), true, false)
|
SetCanAttackFriendly(PlayerPedId(), true, false)
|
||||||
NetworkSetFriendlyFireOption(true)
|
NetworkSetFriendlyFireOption(true)
|
||||||
end)
|
end)
|
||||||
@@ -17,9 +17,3 @@ function NDCore.GetPlayersFromCoords(distance, coords)
|
|||||||
end
|
end
|
||||||
return closePlayers
|
return closePlayers
|
||||||
end
|
end
|
||||||
|
|
||||||
for name, func in pairs(NDCore) do
|
|
||||||
if type(func) == "function" then
|
|
||||||
exports(name, func)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
NDCore = {}
|
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
SetDiscordAppId(Config.discordAppId)
|
SetDiscordAppId(Config.discordAppId)
|
||||||
SetDiscordRichPresenceAsset(Config.discordAsset)
|
SetDiscordRichPresenceAsset(Config.discordAsset)
|
||||||
|
|||||||
@@ -8,19 +8,18 @@ fx_version "cerulean"
|
|||||||
game "gta5"
|
game "gta5"
|
||||||
lua54 "yes"
|
lua54 "yes"
|
||||||
|
|
||||||
|
shared_scripts {
|
||||||
|
"init.lua"
|
||||||
|
}
|
||||||
client_scripts {
|
client_scripts {
|
||||||
"client/main.lua",
|
|
||||||
"client/functions.lua",
|
"client/functions.lua",
|
||||||
"client/events.lua",
|
"client/events.lua",
|
||||||
|
"client/main.lua"
|
||||||
}
|
}
|
||||||
server_scripts {
|
server_scripts {
|
||||||
"@oxmysql/lib/MySQL.lua",
|
"@oxmysql/lib/MySQL.lua",
|
||||||
"server/main.lua",
|
"server/main.lua",
|
||||||
"server/functions.lua",
|
|
||||||
"server/player.lua"
|
"server/player.lua"
|
||||||
}
|
}
|
||||||
shared_scripts {
|
|
||||||
"init.lua"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependency "oxmysql"
|
dependency "oxmysql"
|
||||||
|
|||||||
15
init.lua
15
init.lua
@@ -8,16 +8,9 @@ Config = {
|
|||||||
discordActionLink = GetConvar("discordActionLink", "https://discord.gg/Z9Mxu72zZ6"),
|
discordActionLink = GetConvar("discordActionLink", "https://discord.gg/Z9Mxu72zZ6"),
|
||||||
discordActionText2 = GetConvar("core:discordActionText2", "STORE"),
|
discordActionText2 = GetConvar("core:discordActionText2", "STORE"),
|
||||||
discordActionLink2 = GetConvar("core:discordActionLink2", "https://andyyy.tebex.io/category/fivem-scripts"),
|
discordActionLink2 = GetConvar("core:discordActionLink2", "https://andyyy.tebex.io/category/fivem-scripts"),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local nd_core = exports["ND_Core"]
|
NDCore = {
|
||||||
|
config = Config
|
||||||
NDCore = setmetatable({}, {
|
}
|
||||||
__index = function(self, index)
|
|
||||||
self[index] = function(...)
|
|
||||||
return nd_core[index](nil, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
return self[index]
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
function NDCore.getPlayer(src)
|
|
||||||
return ActivePlayers[src]
|
|
||||||
end
|
|
||||||
|
|
||||||
function NDCore.getPlayers(metadata, data)
|
|
||||||
if not metadata or not data then return ActivePlayers end
|
|
||||||
local players = {}
|
|
||||||
for src, info in pairs(ActivePlayers) do
|
|
||||||
if info.metadata[metadata] == data then
|
|
||||||
players[src] = info
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return players
|
|
||||||
end
|
|
||||||
|
|
||||||
for name, func in pairs(NDCore) do
|
|
||||||
if type(func) == "function" then
|
|
||||||
exports(name, func)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,6 +1,20 @@
|
|||||||
NDCore = {}
|
|
||||||
ActivePlayers = {}
|
ActivePlayers = {}
|
||||||
|
|
||||||
|
function NDCore.getPlayer(src)
|
||||||
|
return ActivePlayers[src]
|
||||||
|
end
|
||||||
|
|
||||||
|
function NDCore.getPlayers(metadata, data)
|
||||||
|
if not metadata or not data then return ActivePlayers end
|
||||||
|
local players = {}
|
||||||
|
for src, info in pairs(ActivePlayers) do
|
||||||
|
if info.metadata[metadata] == data then
|
||||||
|
players[src] = info
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return players
|
||||||
|
end
|
||||||
|
|
||||||
AddEventHandler("playerDropped", function()
|
AddEventHandler("playerDropped", function()
|
||||||
local src = source
|
local src = source
|
||||||
local char = ActivePlayers[src]
|
local char = ActivePlayers[src]
|
||||||
|
|||||||
@@ -1,137 +1,133 @@
|
|||||||
local function createCharacterTable(info)
|
local function charDelete(self)
|
||||||
local self = {
|
local result = MySQL.query.await("DELETE FROM nd_characters WHERE charid = ?", {self.id})
|
||||||
source = info.source,
|
if result and self.source then
|
||||||
name = info.name,
|
|
||||||
firstname = info.firstname,
|
|
||||||
lastname = info.lastname,
|
|
||||||
dob = info.dob,
|
|
||||||
gender = info.gender,
|
|
||||||
cash = info.cash,
|
|
||||||
bank = info.bank,
|
|
||||||
license = info.license,
|
|
||||||
metadata = info.metadata,
|
|
||||||
inventory = info.inventory
|
|
||||||
}
|
|
||||||
|
|
||||||
function self.delete()
|
|
||||||
local result = MySQL.query.await("DELETE FROM nd_characters WHERE charid = ?", {self.id})
|
|
||||||
if result and self.source then
|
|
||||||
ActivePlayers[self.source] = nil
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.deductMoney(account, amount, reason)
|
|
||||||
local amount = tonumber(amount)
|
|
||||||
if not amount or account ~= "bank" and account ~= "cash" then return end
|
|
||||||
self[account] -= amount
|
|
||||||
if self.source then
|
|
||||||
TriggerEvent("ND:moneyChange", self.source, account, amount, "remove", reason)
|
|
||||||
ActivePlayers[self.source] = self
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.addMoney(account, amount, reason)
|
|
||||||
local amount = tonumber(amount)
|
|
||||||
if not amount or account ~= "bank" and account ~= "cash" then return end
|
|
||||||
self[account] += amount
|
|
||||||
if self.source then
|
|
||||||
TriggerEvent("ND:moneyChange", self.source, account, amount, "add", reason)
|
|
||||||
ActivePlayers[self.source] = self
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.depositMoney(amount)
|
|
||||||
local amount = tonumber(amount)
|
|
||||||
if not amount or self.cash < amount or amount <= 0 then return end
|
|
||||||
return self:deductMoney("cash", amount, "Deposit") and self:AddMoney("bank", amount, "Deposit")
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.withdrawMoney(amount)
|
|
||||||
local amount = tonumber(amount)
|
|
||||||
if not amount or self.bank < amount or amount <= 0 then return end
|
|
||||||
return self:deductMoney("bank", amount, "Withdraw") and self:AddMoney("cash", amount, "Withdraw")
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.setMetadata(key, value)
|
|
||||||
self.metadata[key] = value
|
|
||||||
if self.source then
|
|
||||||
ActivePlayers[self.source] = self
|
|
||||||
return ActivePlayers[self.source].metadata
|
|
||||||
end
|
|
||||||
return self.metadata
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.unload(self)
|
|
||||||
TriggerEvent("ND:characterUnloaded", self.source, self)
|
|
||||||
local ped = GetPlayerPed(self.source)
|
|
||||||
self:setMetadata("location", GetEntityCoords(ped))
|
|
||||||
self:save()
|
|
||||||
if not self.source then return end
|
|
||||||
ActivePlayers[self.source] = nil
|
ActivePlayers[self.source] = nil
|
||||||
end
|
end
|
||||||
|
return result
|
||||||
function self.save(self)
|
end
|
||||||
MySQL.update.await("UPDATE nd_characters SET name = ?, firstname = ?, lastname = ?, dob = ?, gender = ?, cash = ?, bank = ?, metadata = ?, inventory = ? WHERE charid = ?", {
|
|
||||||
self.name,
|
local function charDeductMoney(self, account, amount, reason)
|
||||||
self.firstname,
|
local amount = tonumber(amount)
|
||||||
self.lastname,
|
if not amount or account ~= "bank" and account ~= "cash" then return end
|
||||||
self.dob,
|
self[account] -= amount
|
||||||
self.gender,
|
if self.source then
|
||||||
self.cash,
|
TriggerEvent("ND:moneyChange", self.source, account, amount, "remove", reason)
|
||||||
self.bank,
|
|
||||||
json.encode(self.metadata),
|
|
||||||
json.encode(self.inventory),
|
|
||||||
self.id,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.createLicense(licenseType, expire)
|
|
||||||
local expireIn = tonumber(expire) or 2592000
|
|
||||||
local time = os.time()
|
|
||||||
local licenses = self.metadata.licenses
|
|
||||||
local identifier = {}
|
|
||||||
|
|
||||||
for i=1, 16 do
|
|
||||||
identifier[i] = math.random(0, 1) == 1 and string.char(math.random(65, 90)) or math.random(0, 9)
|
|
||||||
end
|
|
||||||
|
|
||||||
local license = {
|
|
||||||
type = licenseType,
|
|
||||||
status = "valid",
|
|
||||||
issued = time,
|
|
||||||
expires = time+expireIn,
|
|
||||||
identifier = table.concat(identifier)
|
|
||||||
}
|
|
||||||
|
|
||||||
if licenses then
|
|
||||||
self.metadata.licenses[#licenses+1] = license
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.metadata.licenses = {license}
|
|
||||||
|
|
||||||
if not self.source then return end
|
|
||||||
ActivePlayers[self.source] = self
|
ActivePlayers[self.source] = self
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
function self.setCoords(coords)
|
end
|
||||||
if not self.source or not coords then return end
|
|
||||||
local ped = GetPlayerPed(self.source)
|
local function charAddMoney(self, account, amount, reason)
|
||||||
if not DoesEntityExist(ped) then return end
|
local amount = tonumber(amount)
|
||||||
SetEntityCoords(ped, coords.x, coords.y, coords.z)
|
if not amount or account ~= "bank" and account ~= "cash" then return end
|
||||||
return true
|
self[account] += amount
|
||||||
|
if self.source then
|
||||||
|
TriggerEvent("ND:moneyChange", self.source, account, amount, "add", reason)
|
||||||
|
ActivePlayers[self.source] = self
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charDepositMoney(self, amount)
|
||||||
|
local amount = tonumber(amount)
|
||||||
|
if not amount or self.cash < amount or amount <= 0 then return end
|
||||||
|
return self:deductMoney("cash", amount, "Deposit") and self:AddMoney("bank", amount, "Deposit")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charWithdrawMoney(self, amount)
|
||||||
|
local amount = tonumber(amount)
|
||||||
|
if not amount or self.bank < amount or amount <= 0 then return end
|
||||||
|
return self:deductMoney("bank", amount, "Withdraw") and self:AddMoney("cash", amount, "Withdraw")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charSetMetadata(self, key, value)
|
||||||
|
self.metadata[key] = value
|
||||||
|
if self.source then
|
||||||
|
ActivePlayers[self.source] = self
|
||||||
|
return ActivePlayers[self.source].metadata
|
||||||
|
end
|
||||||
|
return self.metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charUnload(self)
|
||||||
|
TriggerEvent("ND:characterUnloaded", self.source, self)
|
||||||
|
local ped = GetPlayerPed(self.source)
|
||||||
|
self:setMetadata("location", GetEntityCoords(ped))
|
||||||
|
self:save()
|
||||||
|
if not self.source then return end
|
||||||
|
ActivePlayers[self.source] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charSave(self)
|
||||||
|
MySQL.update.await("UPDATE nd_characters SET name = ?, firstname = ?, lastname = ?, dob = ?, gender = ?, cash = ?, bank = ?, metadata = ?, inventory = ? WHERE charid = ?", {
|
||||||
|
self.name,
|
||||||
|
self.firstname,
|
||||||
|
self.lastname,
|
||||||
|
self.dob,
|
||||||
|
self.gender,
|
||||||
|
self.cash,
|
||||||
|
self.bank,
|
||||||
|
json.encode(self.metadata),
|
||||||
|
json.encode(self.inventory),
|
||||||
|
self.id,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charCreateLicense(self, licenseType, expire)
|
||||||
|
local expireIn = tonumber(expire) or 2592000
|
||||||
|
local time = os.time()
|
||||||
|
local licenses = self.metadata.licenses
|
||||||
|
local identifier = {}
|
||||||
|
|
||||||
|
for i=1, 16 do
|
||||||
|
identifier[i] = math.random(0, 1) == 1 and string.char(math.random(65, 90)) or math.random(0, 9)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
local license = {
|
||||||
|
type = licenseType,
|
||||||
|
status = "valid",
|
||||||
|
issued = time,
|
||||||
|
expires = time+expireIn,
|
||||||
|
identifier = table.concat(identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
if licenses then
|
||||||
|
self.metadata.licenses[#licenses+1] = license
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self.metadata.licenses = {license}
|
||||||
|
|
||||||
|
if not self.source then return end
|
||||||
|
ActivePlayers[self.source] = self
|
||||||
|
end
|
||||||
|
|
||||||
|
local function charSetCoords(self, coords)
|
||||||
|
if not self.source or not coords then return end
|
||||||
|
local ped = GetPlayerPed(self.source)
|
||||||
|
if not DoesEntityExist(ped) then return end
|
||||||
|
SetEntityCoords(ped, coords.x, coords.y, coords.z)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function initPlayerTable(playerTable)
|
||||||
|
playerTable.delete = charDelete,
|
||||||
|
playerTable.deductMoney = charDeductMoney,
|
||||||
|
playerTable.addMoney = charAddMoney
|
||||||
|
playerTable.depositMoney = charDepositMoney,
|
||||||
|
playerTable.withdrawMoney = charWithdrawMoney,
|
||||||
|
playerTable.setMetadata = charSetMetadata,
|
||||||
|
playerTable.save = charSave,
|
||||||
|
playerTable.unload = charUnload,
|
||||||
|
playerTable.createLicense = charCreateLicense
|
||||||
|
playerTable.setCoords = charSetCoords
|
||||||
|
return playerTable
|
||||||
end
|
end
|
||||||
|
|
||||||
function NDCore.newCharacter(src, info)
|
function NDCore.newCharacter(src, info)
|
||||||
local license = GetPlayerIdentifierByType(src, "license")
|
local license = GetPlayerIdentifierByType(src, "license")
|
||||||
if not license then return end
|
if not license then return end
|
||||||
|
|
||||||
local charInfo = createCharacterTable({
|
local charInfo = initPlayerTable({
|
||||||
source = src,
|
source = src,
|
||||||
name = GetPlayerName(src) or "",
|
name = GetPlayerName(src) or "",
|
||||||
firstname = info.firstname or "",
|
firstname = info.firstname or "",
|
||||||
@@ -155,7 +151,7 @@ function NDCore.newCharacter(src, info)
|
|||||||
charInfo.cash,
|
charInfo.cash,
|
||||||
charInfo.bank,
|
charInfo.bank,
|
||||||
charInfo.metadata
|
charInfo.metadata
|
||||||
})
|
)
|
||||||
|
|
||||||
return charInfo
|
return charInfo
|
||||||
end
|
end
|
||||||
@@ -165,7 +161,7 @@ function NDCore.fetchCharacter(id)
|
|||||||
if not result then return end
|
if not result then return end
|
||||||
|
|
||||||
local info = result[1]
|
local info = result[1]
|
||||||
return createCharacterTable({
|
return initPlayerTable({
|
||||||
id = id,
|
id = id,
|
||||||
name = info.name,
|
name = info.name,
|
||||||
firstname = info.firstname,
|
firstname = info.firstname,
|
||||||
@@ -187,7 +183,7 @@ function NDCore.getPlayerCharacters(src)
|
|||||||
|
|
||||||
for i=1, amount do
|
for i=1, amount do
|
||||||
local info = result[i]
|
local info = result[i]
|
||||||
characters[info.charid] = createCharacterTable({
|
characters[info.charid] = initPlayerTable({
|
||||||
id = info.charid,
|
id = info.charid,
|
||||||
name = info.name,
|
name = info.name,
|
||||||
firstname = info.firstname,
|
firstname = info.firstname,
|
||||||
@@ -209,7 +205,7 @@ function NDCore.setActiveCharacter(src, id)
|
|||||||
if char then char:unload() end
|
if char then char:unload() end
|
||||||
|
|
||||||
local character = NDCore.fetchCharacter(id)
|
local character = NDCore.fetchCharacter(id)
|
||||||
character.source = src
|
character.source = src,
|
||||||
character.name = GetPlayerName(src)
|
character.name = GetPlayerName(src)
|
||||||
ActivePlayers[src] = character
|
ActivePlayers[src] = character
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user