mirror of
https://github.com/project-error/qb-pefcl.git
synced 2026-03-31 06:33:54 -04:00
Merge pull request #2 from mohmando/main
Guide to update player function on qb-core
This commit is contained in:
117
README.md
117
README.md
@@ -2,6 +2,7 @@
|
||||
|
||||
**This is a compatibility resource that enables PEFCL to function properly with QBCore. Please ensure that you have the latest version
|
||||
of PEFCL and QBCore installed**
|
||||
**Note this currently only works on PEFCL develop branch**
|
||||
|
||||
## Installation Steps:
|
||||
|
||||
@@ -14,5 +15,119 @@ of PEFCL and QBCore installed**
|
||||
- Under `target`
|
||||
- `type`: `"qb-target"`
|
||||
- `enabled`: `true`
|
||||
4. Navigate to `qb-core\server\player.lua` and replace those functions:
|
||||
- self.Functions.AddMoney =>
|
||||
```lua
|
||||
function self.Functions.AddMoney(moneytype, amount, reason)
|
||||
reason = reason or 'unknown'
|
||||
moneytype = moneytype:lower()
|
||||
amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if moneytype == 'bank' then
|
||||
local data = {}
|
||||
data.amount = amount
|
||||
data.message = reason
|
||||
exports.pefcl:addBankBalance(self.PlayerData.source, data)
|
||||
else
|
||||
if not self.PlayerData.money[moneytype] then return false end
|
||||
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] + amount
|
||||
end
|
||||
|
||||
if not self.Offline then
|
||||
self.Functions.UpdatePlayerData()
|
||||
if amount > 100000 then
|
||||
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
|
||||
else
|
||||
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
|
||||
end
|
||||
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, false)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
```
|
||||
- self.Functions.RemoveMoney =>
|
||||
```lua
|
||||
function self.Functions.RemoveMoney(moneytype, amount, reason)
|
||||
reason = reason or 'unknown'
|
||||
moneytype = moneytype:lower()
|
||||
amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if not self.PlayerData.money[moneytype] then return false end
|
||||
for _, mtype in pairs(QBCore.Config.Money.DontAllowMinus) do
|
||||
if mtype == moneytype then
|
||||
if (self.PlayerData.money[moneytype] - amount) < 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
if moneytype == 'bank' then
|
||||
if (exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data - amount) < 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
if moneytype == 'bank' then
|
||||
local data = {}
|
||||
data.amount = amount
|
||||
data.message = reason
|
||||
exports.pefcl:removeBankBalance(self.PlayerData.source, data)
|
||||
self.PlayerData.money[moneytype] = exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data or 0
|
||||
else
|
||||
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
|
||||
end
|
||||
if not self.Offline then
|
||||
self.Functions.UpdatePlayerData()
|
||||
if amount > 100000 then
|
||||
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
|
||||
else
|
||||
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
|
||||
end
|
||||
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
|
||||
if moneytype == 'bank' then
|
||||
TriggerClientEvent('qb-phone:client:RemoveBankMoney', self.PlayerData.source, amount)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
```
|
||||
- self.Functions.SetMoney
|
||||
```lua
|
||||
function self.Functions.SetMoney(moneytype, amount, reason)
|
||||
reason = reason or 'unknown'
|
||||
moneytype = moneytype:lower()
|
||||
amount = tonumber(amount)
|
||||
if amount < 0 then return false end
|
||||
if moneytype == 'bank' then
|
||||
local data = {}
|
||||
data.message = reason
|
||||
data.amount = amount
|
||||
exports.pefcl:setBankBalance(self.PlayerData.source, data)
|
||||
self.PlayerData.money[moneytype] = exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data or 0
|
||||
else
|
||||
if not self.PlayerData.money[moneytype] then return false end
|
||||
self.PlayerData.money[moneytype] = amount
|
||||
end
|
||||
|
||||
if not self.Offline then
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'SetMoney', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') set, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
```
|
||||
- self.Functions.GetMoney
|
||||
```lua
|
||||
function self.Functions.GetMoney(moneytype)
|
||||
if not moneytype then return false end
|
||||
moneytype = moneytype:lower()
|
||||
if moneytype == 'bank' then
|
||||
self.PlayerData.money[moneytype] = exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data or 0
|
||||
return exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data
|
||||
end
|
||||
return self.PlayerData.money[moneytype]
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
**Note this currently only works on PEFCL develop branch**
|
||||
|
||||
Reference in New Issue
Block a user