Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): deprecate player functions #611

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ return {
---@param player Player Player object
---@param payment number Payment amount
sendPaycheck = function (player, payment)
player.Functions.AddMoney('bank', payment)
AddMoney(player.PlayerData.source, 'bank', payment)
Notify(player.PlayerData.source, locale('info.received_paycheck', payment))
end,
}
8 changes: 4 additions & 4 deletions server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ lib.addCommand('givemoney', {
return
end

player.Functions.AddMoney(args[locale('command.givemoney.params.moneytype.name')], args[locale('command.givemoney.params.amount.name')])
AddMoney(source, args[locale('command.givemoney.params.moneytype.name')], args[locale('command.givemoney.params.amount.name')])
Manason marked this conversation as resolved.
Show resolved Hide resolved
end)

lib.addCommand('setmoney', {
Expand All @@ -221,7 +221,7 @@ lib.addCommand('setmoney', {
return
end

player.Functions.SetMoney(args[locale('command.setmoney.params.moneytype.name')], args[locale('command.setmoney.params.amount.name')])
SetMoney(source, args[locale('command.setmoney.params.moneytype.name')], args[locale('command.setmoney.params.amount.name')])
Manason marked this conversation as resolved.
Show resolved Hide resolved
end)

lib.addCommand('job', {
Expand All @@ -246,7 +246,7 @@ lib.addCommand('setjob', {
return
end

local success, errorResult = player.Functions.SetJob(args[locale('command.setjob.params.job.name')], args[locale('command.setjob.params.grade.name')] or 0)
local success, errorResult = SetJob(source, args[locale('command.setjob.params.job.name')], args[locale('command.setjob.params.grade.name')] or 0)
assert(success, json.encode(errorResult))
end)

Expand Down Expand Up @@ -327,7 +327,7 @@ lib.addCommand('setgang', {
return
end

local success, errorResult = player.Functions.SetGang(args[locale('command.setgang.params.gang.name')], args[locale('command.setgang.params.grade.name')] or 0)
local success, errorResult = SetGang(source, args[locale('command.setgang.params.gang.name')], args[locale('command.setgang.params.grade.name')] or 0)
assert(success, json.encode(errorResult))
end)

Expand Down
8 changes: 4 additions & 4 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ AddEventHandler('playerDropped', function(reason)
color = 'red',
message = ('**%s** (%s) left...\n **Reason:** %s'):format(GetPlayerName(src), player.PlayerData.license, reason),
})
player.Functions.Save()
Save(src --[[@as Source]])
QBX.Player_Buckets[player.PlayerData.license] = nil
QBX.Players[src] = nil
end)
Expand Down Expand Up @@ -188,10 +188,10 @@ RegisterNetEvent('QBCore:ToggleDuty', function()
local player = GetPlayer(src)
if not player then return end
if player.PlayerData.job.onduty then
player.Functions.SetJobDuty(false)
SetJobDuty(src, false)
Notify(src, locale('info.off_duty'))
else
player.Functions.SetJobDuty(true)
SetJobDuty(src, true)
Notify(src, locale('info.on_duty'))
end
end)
Expand All @@ -207,7 +207,7 @@ local function playerStateBagCheck(bagName, meta, value)
local player = QBX.Players[plySrc]
if not player then return end
if player.PlayerData.metadata[meta] == value then return end
player.Functions.SetMetaData(meta, value)
SetMetadata(plySrc, meta, value)
end

---@diagnostic disable-next-line: param-type-mismatch
Expand Down
2 changes: 1 addition & 1 deletion server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function ToggleOptin(source)
if not license or not IsPlayerAceAllowed(source --[[@as string]], 'admin') then return end
local player = GetPlayer(source)
player.PlayerData.optin = not player.PlayerData.optin
player.Functions.SetPlayerData('optin', player.PlayerData.optin)
SetPlayerData(source, 'optin', player.PlayerData.optin)
end

exports('ToggleOptin', ToggleOptin)
Expand Down
6 changes: 3 additions & 3 deletions server/loops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ local function removeHungerAndThirst(src, player)
local newHunger = playerState.hunger - config.player.hungerRate
local newThirst = playerState.thirst - config.player.thirstRate

player.Functions.SetMetaData('thirst', math.max(0, newThirst))
player.Functions.SetMetaData('hunger', math.max(0, newHunger))
SetMetadata(player.PlayerData.source, 'thirst', math.max(0, newThirst))
SetMetadata(player.PlayerData.source, 'hunger', math.max(0, newHunger))

player.Functions.Save()
Save(player.PlayerData.source)
end

CreateThread(function()
Expand Down
1 change: 0 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ SetRoutingBucketEntityLockdownMode(0, bucketLockDownMode)
QBX = {}
QBX.Shared = require 'shared.main'

---@alias Source integer
---@type table<Source, Player>
QBX.Players = {}
GlobalState.PlayerCount = 0
Expand Down
Loading