⚙️Add new currency
Installation for SA-Money script (Adding new currency)
This works only like item as money. That means to add or remove the money you have to edit scripts that use that.
Example
From
Player.Functions.RemoveMoney('cash', amount, "Bank deposit")
To
Player.Functions.RemoveMoney('blackmoney', amount, "Bank deposit")
If you have successfully installed the script, then you can add new currency by these steps
More currencies = bigger impact on performance
First of all, we need to config your config.lua in SA-Money-v2
Another = {
Enabled = false, -- This enables the function.
Currencies = {
[1] = {
currency = 'blackmoney', --Here is the name of currency that you choose in qb-core > config.lua
item = 'black', -- Here is the name of item that you choose in qb-core > shared > items.lua
prop = 'prop_cash_pile_02',
--chance = 1.0, -- 0.7 = 70% chance to success / 30% to call a cops (DOESN'T WORK FOR NOW)
},
--To addd new currency just add same things and increase number in []
[2] = {
currency = 'printedbills', --Here is the name of currency that you choose in qb-core > config.lua
item = 'printedbills', --Here is the name of item that you choose in qb-core > shared > items.lua
prop = 'prop_cash_pile_02',
--chance = 1.0, -- 0.7 = 70% chance to success / 30% to call a cops (DOESN'T WORK FOR NOW)
},
}
}
Now, we have to create an item in qb-core > shared > items.lua same way as you added cash
['black'] = {['name'] = 'black', ['label'] = 'Black Money', ['weight'] = 0, ['type'] = 'item', ['image'] = 'cash.png', ['unique'] = false, ['useable'] = false, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Money?'},
The next step is to add new currency into the config.lua in QB-Core
QBConfig.Money = {}
QBConfig.Money.MoneyTypes = { cash = 500, bank = 5000, crypto = 0, blackmoney = 0, printedbills = 0 } -- type = startamount - Add or remove money types for your server (for ex. blackmoney = 0), remember once added it will not be removed from the database!
QBConfig.Money.DontAllowMinus = { 'cash', 'crypto', 'blackmoney', 'printedbills' } -- Money that is not allowed going in minus
The last thing is uncommenting the lines that we added at the Installation so we open player.lua find functions AddMoney and RemoveMoney and we uncomment those commented lines. So player.lua will look like this.
function self.Functions.AddMoney(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
if moneytype == 'cash' then
if self.PlayerData.money[moneytype] == self.PlayerData.money['cash'] then
exports['SA-Money-v2']:AddMoney(PlayerData, amount, reason)
end
elseif moneytype == 'blackmoney' then
if self.PlayerData.money[moneytype] == self.PlayerData.money['blackmoney'] then
exports['SA-Money-v2']:AddMoney(PlayerData, amount, reason, 'blackmoney')
end
elseif moneytype == 'printedbills' then
if self.PlayerData.money[moneytype] == self.PlayerData.money['printedbills'] then
exports['SA-Money-v2']:AddMoney(PlayerData, amount, reason, 'printedbills')
end
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', '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
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
end
if moneytype == 'cash' then
if self.PlayerData.money[moneytype] == self.PlayerData.money['cash'] then
exports['SA-Money-v2']:RemoveMoney(PlayerData, amount, reason)
end
elseif moneytype == 'blackmoney' then
if self.PlayerData.money[moneytype] == self.PlayerData.money['blackmoney'] then
exports['SA-Money-v2']:RemoveMoney(PlayerData, amount, reason, 'blackmoney')
end
elseif moneytype == 'printedbills' then
if self.PlayerData.money[moneytype] == self.PlayerData.money['printedbills'] then
exports['SA-Money-v2']:RemoveMoney(PlayerData, amount, reason, 'printedbills')
end
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
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 not self.PlayerData.money[moneytype] then return false end
self.PlayerData.money[moneytype] = amount
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
function self.Functions.GetMoney(moneytype)
local src = PlayerData.source
exports['SA-Money-v2']:GetCash(src)
if not moneytype then return false end
moneytype = moneytype:lower()
return self.PlayerData.money[moneytype]
end
Now it's done and it should work. If it doesn't work try other tips or contact us on Discord
If you get some errors in the console, try the section Error Fixes
Last updated