Skip to content

Commit c261fd2

Browse files
committed
Add option to store player fields in PlayerData
Updated AddField and AddPlayerField functions to support storing fields in the PlayerData table when the inPlayerData flag is set. This allows for more flexible management of player attributes.
1 parent 5cf9f4b commit c261fd2

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

server/player.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,12 @@ function QBCore.Player.CreatePlayer(PlayerData, Offline)
410410
self.Functions[methodName] = handler
411411
end
412412

413-
function self.Functions.AddField(fieldName, data)
414-
self[fieldName] = data
413+
function self.Functions.AddField(fieldName, data, inPlayerData)
414+
if inPlayerData then
415+
self.PlayerData[fieldName] = data
416+
else
417+
self[fieldName] = data
418+
end
415419
end
416420

417421
if self.Offline then
@@ -461,21 +465,21 @@ end
461465
end)
462466
]]
463467

464-
function QBCore.Functions.AddPlayerField(ids, fieldName, data)
468+
function QBCore.Functions.AddPlayerField(ids, fieldName, data, inPlayerData)
465469
local idType = type(ids)
466470
if idType == 'number' then
467471
if ids == -1 then
468472
for _, v in pairs(QBCore.Players) do
469-
v.Functions.AddField(fieldName, data)
473+
v.Functions.AddField(fieldName, data, inPlayerData)
470474
end
471475
else
472476
if not QBCore.Players[ids] then return end
473477

474-
QBCore.Players[ids].Functions.AddField(fieldName, data)
478+
QBCore.Players[ids].Functions.AddField(fieldName, data, inPlayerData)
475479
end
476480
elseif idType == 'table' and table.type(ids) == 'array' then
477481
for i = 1, #ids do
478-
QBCore.Functions.AddPlayerField(ids[i], fieldName, data)
482+
QBCore.Functions.AddPlayerField(ids[i], fieldName, data, inPlayerData)
479483
end
480484
end
481485
end

0 commit comments

Comments
 (0)