a lot of changes

This commit is contained in:
Andyyy7666
2023-07-09 21:19:35 +02:00
parent 24caa1a857
commit bf9604e851
8 changed files with 174 additions and 148 deletions

View File

@@ -17,3 +17,9 @@ function NDCore.GetPlayersFromCoords(distance, coords)
end
return closePlayers
end
for name, func in pairs(NDCore) do
if type(func) == "function" then
exports(name, func)
end
end

View File

@@ -1,3 +1,5 @@
NDCore = {}
CreateThread(function()
SetDiscordAppId(Config.discordAppId)
SetDiscordRichPresenceAsset(Config.discordAsset)

View File

@@ -8,18 +8,19 @@ fx_version "cerulean"
game "gta5"
lua54 "yes"
shared_scripts {
"init.lua"
}
client_scripts {
"client/main.lua",
"client/functions.lua",
"client/events.lua",
"client/main.lua"
}
server_scripts {
"@oxmysql/lib/MySQL.lua",
"server/main.lua",
"server/functions.lua",
"server/player.lua"
}
shared_scripts {
"init.lua"
}
dependency "oxmysql"

View File

@@ -8,9 +8,16 @@ Config = {
discordActionLink = GetConvar("discordActionLink", "https://discord.gg/Z9Mxu72zZ6"),
discordActionText2 = GetConvar("core:discordActionText2", "STORE"),
discordActionLink2 = GetConvar("core:discordActionLink2", "https://andyyy.tebex.io/category/fivem-scripts"),
}
NDCore = {
config = Config
}
local nd_core = exports["ND_Core"]
NDCore = setmetatable({}, {
__index = function(self, index)
self[index] = function(...)
return nd_core[index](nil, ...)
end
return self[index]
end
})

20
server/functions.lua Normal file
View File

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

View File

@@ -1,20 +1,6 @@
NDCore = {}
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()
local src = source
local char = ActivePlayers[src]

View File

@@ -1,4 +1,19 @@
local function charDelete(self)
local function createCharacterTable(info)
local self = {
source = info.source,
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
@@ -6,7 +21,7 @@ local function charDelete(self)
return result
end
local function charDeductMoney(self, account, amount, reason)
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
@@ -17,7 +32,7 @@ local function charDeductMoney(self, account, amount, reason)
return true
end
local function charAddMoney(self, account, amount, reason)
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
@@ -28,19 +43,19 @@ local function charAddMoney(self, account, amount, reason)
return true
end
local function charDepositMoney(self, amount)
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
local function charWithdrawMoney(self, amount)
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
local function charSetMetadata(self, key, value)
function self.setMetadata(key, value)
self.metadata[key] = value
if self.source then
ActivePlayers[self.source] = self
@@ -49,7 +64,7 @@ local function charSetMetadata(self, key, value)
return self.metadata
end
local function charUnload(self)
function self.unload(self)
TriggerEvent("ND:characterUnloaded", self.source, self)
local ped = GetPlayerPed(self.source)
self:setMetadata("location", GetEntityCoords(ped))
@@ -58,7 +73,7 @@ local function charUnload(self)
ActivePlayers[self.source] = nil
end
local function charSave(self)
function self.save(self)
MySQL.update.await("UPDATE nd_characters SET name = ?, firstname = ?, lastname = ?, dob = ?, gender = ?, cash = ?, bank = ?, metadata = ?, inventory = ? WHERE charid = ?", {
self.name,
self.firstname,
@@ -73,7 +88,7 @@ local function charSave(self)
})
end
local function charCreateLicense(self, licenseType, expire)
function self.createLicense(licenseType, expire)
local expireIn = tonumber(expire) or 2592000
local time = os.time()
local licenses = self.metadata.licenses
@@ -101,7 +116,7 @@ local function charCreateLicense(self, licenseType, expire)
ActivePlayers[self.source] = self
end
local function charSetCoords(self, coords)
function self.setCoords(coords)
if not self.source or not coords then return end
local ped = GetPlayerPed(self.source)
if not DoesEntityExist(ped) then return end
@@ -109,25 +124,14 @@ local function charSetCoords(self, coords)
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
return self
end
function NDCore.newCharacter(src, info)
local license = GetPlayerIdentifierByType(src, "license")
if not license then return end
local charInfo = initPlayerTable({
local charInfo = createCharacterTable({
source = src,
name = GetPlayerName(src) or "",
firstname = info.firstname or "",
@@ -151,7 +155,7 @@ function NDCore.newCharacter(src, info)
charInfo.cash,
charInfo.bank,
charInfo.metadata
)
})
return charInfo
end
@@ -161,7 +165,7 @@ function NDCore.fetchCharacter(id)
if not result then return end
local info = result[1]
return initPlayerTable({
return createCharacterTable({
id = id,
name = info.name,
firstname = info.firstname,
@@ -183,7 +187,7 @@ function NDCore.getPlayerCharacters(src)
for i=1, amount do
local info = result[i]
characters[info.charid] = initPlayerTable({
characters[info.charid] = createCharacterTable({
id = info.charid,
name = info.name,
firstname = info.firstname,
@@ -205,7 +209,7 @@ function NDCore.setActiveCharacter(src, id)
if char then char:unload() end
local character = NDCore.fetchCharacter(id)
character.source = src,
character.source = src
character.name = GetPlayerName(src)
ActivePlayers[src] = character