Skip to content

Commit

Permalink
Revert other pull request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cocodrulo committed Dec 28, 2024
1 parent 7478da8 commit bf506ae
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 113 deletions.
72 changes: 0 additions & 72 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -721,75 +721,3 @@ function QBCore.Functions.PrepForSQL(source, data, pattern)
end
return true
end

---Do a money transactio between players
---@param sourcecid string
---@param sourcemoneytype string -- Only money types in QBConfig.Money.MoneyTypes
---@param targetcid string
---@param targetmoneytype string -- Only money types in QBConfig.Money.MoneyTypes
---@param amount number
---@param reason string
---@return boolean
function QBCore.Functions.TransferMoney(sourcecid, sourcemoneytype, targetcid, targetmoneytype, amount, reason)
local SourcePlayer = QBCore.Functions.GetPlayerByCitizenId(sourcecid)
local TargetPlayer = QBCore.Functions.GetPlayerByCitizenId(targetcid)
if not tonumber(amount) then return false end
amount = tonumber(amount) or 0
if tonumber(amount) <= 0 then return true end
local errorOnLast = false
if SourcePlayer then
if not SourcePlayer.Functions.RemoveMoney(amount, sourcemoneytype, reason) then return false end
else
local result = MySQL.single.await('SELECT money FROM players WHERE citizendid = ?', { sourcecid })
if not result then return false end
result = json.decode(result)
result[sourcemoneytype] -= amount
if not MySQL.update.await('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(result), sourcecid }) then errorOnLast = true end
end
if TargetPlayer then
if not TargetPlayer.Functions.AddMoney(amount, targetmoneytype, reason) then errorOnLast = true end
else
local result = MySQL.single.await('SELECT money FROM players WHERE citizendid = ?', { targetcid })
if not result then errorOnLast = true end
result = json.decode(result)
result[targetmoneytype] += amount
if not MySQL.update.await('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(result), targetcid }) then errorOnLast = true end
end

if errorOnLast then
if SourcePlayer then
if not SourcePlayer.Functions.AddMoney(amount, sourcemoneytype, reason) then return false end
else
local result = MySQL.single.await('SELECT money FROM players WHERE citizendid = ?', { sourcecid })
if not result then return false end
result = json.decode(result)
result[sourcemoneytype] += amount
if not MySQL.update.await('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(result), sourcecid }) then return false end
end
return false
end

if SourcePlayer then
TriggerClientEvent('hud:client:OnMoneyChange', SourcePlayer.PlayerData.source, sourcemoneytype, true)
TriggerClientEvent('QBCore:Client:OnMoneyChange', SourcePlayer.PlayerData.source, sourcemoneytype, amount, 'transfer', reason)
TriggerEvent('QBCore:Server:OnMoneyChange', SourcePlayer.PlayerData.source, sourcemoneytype, amount, 'transfer', reason)
end

if TargetPlayer then
TriggerClientEvent('hud:client:OnMoneyChange', TargetPlayer.PlayerData.source, targetmoneytype, true)
TriggerClientEvent('QBCore:Client:OnMoneyChange', TargetPlayer.PlayerData.source, targetmoneytype, amount, 'transfer', reason)
TriggerEvent('QBCore:Server:OnMoneyChange', TargetPlayer.PlayerData.source, targetmoneytype, amount, 'transfer', reason)
end

if not SourcePlayer and not TargetPlayer then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'TransferMoney', 'yellow', '**' .. sourcecid .. '** gived $' .. amount .. ' (' .. sourcemoneytype .. ') to **' .. targetcid .. '** reason: ' .. reason .. ' | (Both offline)')
elseif not TargetPlayer and SourcePlayer then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'TransferMoney', 'yellow', '**' .. GetPlayerName(SourcePlayer.PlayerData.source) .. ' (citizenid: ' .. SourcePlayer.PlayerData.citizenid .. ' | id: ' .. SourcePlayer.PlayerData.source .. ')**, new balance: ' .. SourcePlayer.PlayerData.money[sourcemoneytype] .. ' gived $' .. amount .. ' (' .. sourcemoneytype .. ') to **' .. targetcid .. ' in ('..targetmoneytype..') reason: ' .. reason .. ' | (Target offline)')
elseif not SourcePlayer and TargetPlayer then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'TransferMoney', 'yellow', '**' .. sourcecid .. '** gived $' .. amount .. ' (' .. sourcemoneytype .. ') to **' .. GetPlayerName(TargetPlayer.PlayerData.source) .. ' (citizenid: ' .. TargetPlayer.PlayerData.citizenid .. ' | id: ' .. TargetPlayer.PlayerData.source .. ')**, new balance: ' .. TargetPlayer.PlayerData.money[targetmoneytype] .. ' in ('..targetmoneytype..') reason: ' .. reason .. ' | (Source offline)')
elseif SourcePlayer and TargetPlayer then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'TransferMoney', 'yellow', '**' .. GetPlayerName(SourcePlayer.PlayerData.source) .. ' (citizenid: ' .. SourcePlayer.PlayerData.citizenid .. ' | id: ' .. SourcePlayer.PlayerData.source .. ')**, new balance: ' .. SourcePlayer.PlayerData.money[sourcemoneytype] .. ' gived $' .. amount .. ' (' .. sourcemoneytype .. ') to **' .. GetPlayerName(TargetPlayer.PlayerData.source) .. ' (citizenid: ' .. TargetPlayer.PlayerData.citizenid .. ' | id: ' .. TargetPlayer.PlayerData.source .. ')**, new balance: ' .. TargetPlayer.PlayerData.money[targetmoneytype] .. ' in ('..targetmoneytype..') reason: ' .. reason)
end

return true
end
41 changes: 0 additions & 41 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -382,47 +382,6 @@ function QBCore.Player.CreatePlayer(PlayerData, Offline)
return true
end

function self.Functions.TransferMoneyTo(sourcemoneytype, targetcid, targetmoneytype, amount, reason)
local TargetPlayer = QBCore.Functions.GetPlayerByCitizenId(targetcid)
if not tonumber(amount) then return false end
amount = tonumber(amount) or 0
if amount <= 0 then return true end
local errorOnLast = false
if not self.Functions.RemoveMoney(amount, sourcemoneytype, reason) then return false end
if TargetPlayer then
if not TargetPlayer.Functions.AddMoney(amount, targetmoneytype, reason) then errorOnLast = true end
else
local result = MySQL.single.await('SELECT money FROM players WHERE citizendid = ?', { targetcid })
if not result then errorOnLast = true end
result = json.decode(result)
result[targetmoneytype] += amount
if not MySQL.update.await('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(result), targetcid }) then errorOnLast = true end
end

if errorOnLast then
self.Functions.AddMoney(amount, sourcemoneytype, reason)
return false
end

TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, sourcemoneytype, true)
TriggerClientEvent('QBCore:Client:OnMoneyChange', self.PlayerData.source, sourcemoneytype, amount, 'transfer', reason)
TriggerEvent('QBCore:Server:OnMoneyChange', self.PlayerData.source, sourcemoneytype, amount, 'transfer', reason)

if TargetPlayer then
TriggerClientEvent('hud:client:OnMoneyChange', TargetPlayer.PlayerData.source, targetmoneytype, true)
TriggerClientEvent('QBCore:Client:OnMoneyChange', TargetPlayer.PlayerData.source, targetmoneytype, amount, 'transfer', reason)
TriggerEvent('QBCore:Server:OnMoneyChange', TargetPlayer.PlayerData.source, targetmoneytype, amount, 'transfer', reason)
end

if not TargetPlayer then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'TransferMoney', 'yellow', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')**, new balance: ' .. self.PlayerData.money[sourcemoneytype] .. ' gived $' .. amount .. ' (' .. sourcemoneytype .. ') to **' .. targetcid .. ' in ('..targetmoneytype..') reason: ' .. reason .. ' | (Target offline)')
elseif TargetPlayer then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'TransferMoney', 'yellow', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')**, new balance: ' .. self.PlayerData.money[sourcemoneytype] .. ' gived $' .. amount .. ' (' .. sourcemoneytype .. ') to **' .. GetPlayerName(TargetPlayer.PlayerData.source) .. ' (citizenid: ' .. TargetPlayer.PlayerData.citizenid .. ' | id: ' .. TargetPlayer.PlayerData.source .. ')**, new balance: ' .. TargetPlayer.PlayerData.money[targetmoneytype] .. ' in ('..targetmoneytype..') reason: ' .. reason)
end

return true
end

function self.Functions.GetMoney(moneytype)
if not moneytype then return false end
moneytype = moneytype:lower()
Expand Down

0 comments on commit bf506ae

Please sign in to comment.