mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-19 14:56:02 +01:00
fix: character id
This commit is contained in:
@@ -2,6 +2,7 @@ local function createCharacterTable(info)
|
|||||||
local playerInfo = PlayersInfo[info.source] or {}
|
local playerInfo = PlayersInfo[info.source] or {}
|
||||||
|
|
||||||
local self = {
|
local self = {
|
||||||
|
id = info.id,
|
||||||
source = info.source,
|
source = info.source,
|
||||||
identifier = info.identifier,
|
identifier = info.identifier,
|
||||||
identifiers = playerInfo.identifiers or {},
|
identifiers = playerInfo.identifiers or {},
|
||||||
@@ -236,7 +237,7 @@ function NDCore.newCharacter(src, info)
|
|||||||
local identifier = GetPlayerIdentifierByType(src, Config.characterIdentifier)
|
local identifier = GetPlayerIdentifierByType(src, Config.characterIdentifier)
|
||||||
if not identifier then return end
|
if not identifier then return end
|
||||||
|
|
||||||
local charInfo = createCharacterTable({
|
local charInfo = {
|
||||||
source = src,
|
source = src,
|
||||||
identifier = identifier,
|
identifier = identifier,
|
||||||
name = GetPlayerName(src) or "",
|
name = GetPlayerName(src) or "",
|
||||||
@@ -249,7 +250,7 @@ function NDCore.newCharacter(src, info)
|
|||||||
groups = info.groups or {},
|
groups = info.groups or {},
|
||||||
metadata = info.metadata or {},
|
metadata = info.metadata or {},
|
||||||
inventory = info.inventory or {},
|
inventory = info.inventory or {},
|
||||||
})
|
}
|
||||||
|
|
||||||
charInfo.id = MySQL.insert.await("INSERT INTO nd_characters (identifier, name, firstname, lastname, dob, gender, cash, bank, groups, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", {
|
charInfo.id = MySQL.insert.await("INSERT INTO nd_characters (identifier, name, firstname, lastname, dob, gender, cash, bank, groups, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", {
|
||||||
identifier,
|
identifier,
|
||||||
@@ -264,7 +265,7 @@ function NDCore.newCharacter(src, info)
|
|||||||
json.encode(charInfo.metadata)
|
json.encode(charInfo.metadata)
|
||||||
})
|
})
|
||||||
|
|
||||||
return charInfo
|
return createCharacterTable(charInfo)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param id number
|
---@param id number
|
||||||
@@ -275,7 +276,7 @@ function NDCore.fetchCharacter(id)
|
|||||||
|
|
||||||
local info = result[1]
|
local info = result[1]
|
||||||
return createCharacterTable({
|
return createCharacterTable({
|
||||||
id = id,
|
id = info.charid,
|
||||||
identifier = info.identifier,
|
identifier = info.identifier,
|
||||||
name = info.name,
|
name = info.name,
|
||||||
firstname = info.firstname,
|
firstname = info.firstname,
|
||||||
@@ -321,15 +322,10 @@ end
|
|||||||
---@param id number
|
---@param id number
|
||||||
---@return table
|
---@return table
|
||||||
function NDCore.setActiveCharacter(src, id)
|
function NDCore.setActiveCharacter(src, id)
|
||||||
local char = ActivePlayers[src]
|
if not src then return 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
|
character.active()
|
||||||
|
|
||||||
TriggerEvent("ND:characterLoaded", character)
|
|
||||||
TriggerClientEvent("ND:characterLoaded", src, character)
|
|
||||||
return ActivePlayers[src]
|
return ActivePlayers[src]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user