forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
979424888b
commit
cd11095ed2
1 changed files with 98 additions and 28 deletions
|
@ -1,5 +1,21 @@
|
||||||
local entities = {}
|
local entities = {}
|
||||||
|
|
||||||
|
-- Enhanced debug function
|
||||||
|
function _debug(...)
|
||||||
|
if Cfg.Debug then
|
||||||
|
local args = {...}
|
||||||
|
local message = ""
|
||||||
|
for i, v in ipairs(args) do
|
||||||
|
if type(v) == "table" then
|
||||||
|
message = message .. " " .. json.encode(v)
|
||||||
|
else
|
||||||
|
message = message .. " " .. tostring(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function taskNpcGiveEnvelope()
|
local function taskNpcGiveEnvelope()
|
||||||
Core.Natives.PlayAnim(entities.npc, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
Core.Natives.PlayAnim(entities.npc, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
||||||
Core.Natives.PlayAnim(cache.ped, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
Core.Natives.PlayAnim(cache.ped, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
||||||
|
@ -52,12 +68,22 @@ lib.callback.register('r_moneywash:startWashingProgressBar', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function taskGiveNpcMoney(amount, metadata)
|
local function taskGiveNpcMoney(amount, metadata)
|
||||||
|
-- Check if amount is valid
|
||||||
|
if not amount or type(amount) ~= "number" then
|
||||||
|
_debug('[DEBUG] - Error: Invalid amount in taskGiveNpcMoney')
|
||||||
|
return Core.Framework.Notify(_L('invalid_amount'), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
local cashProp = 'prop_anim_cash_pile_02'
|
local cashProp = 'prop_anim_cash_pile_02'
|
||||||
entities.cash = Core.Natives.CreateProp(cashProp, Cfg.Options.Location, 0.0, false)
|
entities.cash = Core.Natives.CreateProp(cashProp, Cfg.Options.Location, 0.0, false)
|
||||||
AttachEntityToEntity(entities.cash, cache.ped, 90, 0.003, 0.008, 0.015, 44.108, 29.315, 20.733, true, true, false, true, 2, true)
|
AttachEntityToEntity(entities.cash, cache.ped, 90, 0.003, 0.008, 0.015, 44.108, 29.315, 20.733, true, true, false, true, 2, true)
|
||||||
Core.Natives.PlayAnim(cache.ped, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
Core.Natives.PlayAnim(cache.ped, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
||||||
Core.Natives.PlayAnim(entities.npc, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
Core.Natives.PlayAnim(entities.npc, 'mp_common', 'givetake1_a', 1000, 0, 0.0)
|
||||||
TriggerServerEvent('r_moneywash:startWashingMoney', cache.serverId, amount, metadata)
|
|
||||||
|
-- Ensure metadata is properly handled
|
||||||
|
local safeMetadata = metadata or {}
|
||||||
|
TriggerServerEvent('r_moneywash:startWashingMoney', cache.serverId, amount, safeMetadata)
|
||||||
|
|
||||||
_debug('[DEBUG] - Money given, starting exchange')
|
_debug('[DEBUG] - Money given, starting exchange')
|
||||||
SetTimeout(750, function()
|
SetTimeout(750, function()
|
||||||
AttachEntityToEntity(entities.cash, entities.npc, GetPedBoneIndex(entities.npc, 28422), 0, 0, 0, 168.93, -83.80, 76.29, true, true, false, true, 2, true)
|
AttachEntityToEntity(entities.cash, entities.npc, GetPedBoneIndex(entities.npc, 28422), 0, 0, 0, 168.93, -83.80, 76.29, true, true, false, true, 2, true)
|
||||||
|
@ -66,7 +92,25 @@ end
|
||||||
|
|
||||||
local function giveExchangeOffer(amount, metadata)
|
local function giveExchangeOffer(amount, metadata)
|
||||||
local taxRate = lib.callback.await('r_moneywash:getTaxRate', false)
|
local taxRate = lib.callback.await('r_moneywash:getTaxRate', false)
|
||||||
local given = amount if metadata then given = metadata.worth end
|
|
||||||
|
-- Check if amount is nil
|
||||||
|
if not amount then
|
||||||
|
_debug('[DEBUG] - Error: amount is nil in giveExchangeOffer')
|
||||||
|
return Core.Framework.Notify(_L('invalid_amount'), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set given with proper checks
|
||||||
|
local given = amount
|
||||||
|
if metadata and metadata.worth then
|
||||||
|
given = metadata.worth
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Double check that given is a valid number
|
||||||
|
if not given or type(given) ~= "number" then
|
||||||
|
_debug('[DEBUG] - Error: given is not a valid number in giveExchangeOffer')
|
||||||
|
return Core.Framework.Notify(_L('invalid_amount'), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
local offer = math.ceil(given - (given * taxRate / 100))
|
local offer = math.ceil(given - (given * taxRate / 100))
|
||||||
local confirm = lib.alertDialog({
|
local confirm = lib.alertDialog({
|
||||||
header = _L('money_wash'),
|
header = _L('money_wash'),
|
||||||
|
@ -84,28 +128,43 @@ local function buildMarkedBillsMenu()
|
||||||
ClearPedTasks(entities.npc)
|
ClearPedTasks(entities.npc)
|
||||||
PlayPedAmbientSpeechNative(entities.npc, 'GENERIC_HOWS_IT_GOING', 'SPEECH_PARAMS_FORCE')
|
PlayPedAmbientSpeechNative(entities.npc, 'GENERIC_HOWS_IT_GOING', 'SPEECH_PARAMS_FORCE')
|
||||||
local playerInventory = lib.callback.await('r_moneywash:getPlayerInventory', false)
|
local playerInventory = lib.callback.await('r_moneywash:getPlayerInventory', false)
|
||||||
|
|
||||||
|
if not playerInventory or type(playerInventory) ~= "table" then
|
||||||
|
_debug('[DEBUG] - Error: Invalid player inventory')
|
||||||
|
return Core.Framework.Notify(_L('inventory_error'), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
for _, item in pairs(playerInventory) do
|
for _, item in pairs(playerInventory) do
|
||||||
if item.name == Cfg.Options.Currency then
|
if item and item.name == Cfg.Options.Currency then
|
||||||
-- Add a check for metadata
|
-- Add a check for metadata and item count
|
||||||
local description = ""
|
local description = ""
|
||||||
if item.metadata and item.metadata.worth then
|
if item.metadata and item.metadata.worth then
|
||||||
description = _L('marked_worth', item.metadata.worth)
|
description = _L('marked_worth', item.metadata.worth)
|
||||||
else
|
else
|
||||||
description = _L('marked_worth', item.count) -- Fallback to using the count or another appropriate value
|
description = _L('marked_worth', item.count or 0) -- Fallback to using the count or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(options, {
|
table.insert(options, {
|
||||||
title = item.label,
|
title = item.label or Cfg.Options.Currency,
|
||||||
description = description,
|
description = description,
|
||||||
icon = 'fas fa-money-bill-wave',
|
icon = 'fas fa-money-bill-wave',
|
||||||
iconColor = '#fa5252',
|
iconColor = '#fa5252',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
|
-- Check if item.count exists and is a number
|
||||||
|
if not item.count or type(item.count) ~= "number" then
|
||||||
|
return Core.Framework.Notify(_L('invalid_amount'), 'error')
|
||||||
|
end
|
||||||
giveExchangeOffer(item.count, item.metadata)
|
giveExchangeOffer(item.count, item.metadata)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #options == 0 then
|
||||||
|
_debug('[DEBUG] - No marked bills found in inventory')
|
||||||
|
return Core.Framework.Notify(_L('no_marked_bills'), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'moneywash_markedbills',
|
id = 'moneywash_markedbills',
|
||||||
title = _L('money_wash'),
|
title = _L('money_wash'),
|
||||||
|
@ -117,13 +176,24 @@ end
|
||||||
|
|
||||||
local function openMoneyWashInput()
|
local function openMoneyWashInput()
|
||||||
local playerCash = lib.callback.await('r_moneywash:getInventoryItem', false, Cfg.Options.Currency)
|
local playerCash = lib.callback.await('r_moneywash:getInventoryItem', false, Cfg.Options.Currency)
|
||||||
if playerCash.count < Cfg.Options.MinWash then return Core.Framework.Notify(_L('not_enough_money', Cfg.Options.MinWash), 'error') end
|
if not playerCash or not playerCash.count then
|
||||||
if playerCash.count > Cfg.Options.MaxWash then playerCash.count = Cfg.Options.MaxWash end
|
return Core.Framework.Notify(_L('not_enough_money', Cfg.Options.MinWash), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
|
if playerCash.count < Cfg.Options.MinWash then
|
||||||
|
return Core.Framework.Notify(_L('not_enough_money', Cfg.Options.MinWash), 'error')
|
||||||
|
end
|
||||||
|
|
||||||
|
if playerCash.count > Cfg.Options.MaxWash then
|
||||||
|
playerCash.count = Cfg.Options.MaxWash
|
||||||
|
end
|
||||||
|
|
||||||
PlayPedAmbientSpeechNative(entities.npc, 'GENERIC_HOWS_IT_GOING', 'SPEECH_PARAMS_FORCE')
|
PlayPedAmbientSpeechNative(entities.npc, 'GENERIC_HOWS_IT_GOING', 'SPEECH_PARAMS_FORCE')
|
||||||
local input = lib.inputDialog(_L('wash_money'), {
|
local input = lib.inputDialog(_L('wash_money'), {
|
||||||
{ type = 'number', label = _L('wash_amount'), icon = 'dollar-sign', required = true, min = Cfg.Options.MinWash, max = playerCash.count },
|
{ type = 'number', label = _L('wash_amount'), icon = 'dollar-sign', required = true, min = Cfg.Options.MinWash, max = playerCash.count },
|
||||||
})
|
})
|
||||||
if not input then return end
|
|
||||||
|
if not input or not input[1] then return end
|
||||||
giveExchangeOffer(tonumber(input[1]))
|
giveExchangeOffer(tonumber(input[1]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -210,7 +280,7 @@ function locPoint:onEnter()
|
||||||
distance = 2,
|
distance = 2,
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
local onCooldown = lib.callback.await('r_moneywash:getPlayerCooldown', false)
|
local onCooldown = lib.callback.await('r_moneywash:getPlayerCooldown', false)
|
||||||
print(onCooldown)
|
_debug('[DEBUG] - Player cooldown status:', onCooldown)
|
||||||
if onCooldown then Core.Framework.Notify(_L('on_cooldown'), 'info') return end
|
if onCooldown then Core.Framework.Notify(_L('on_cooldown'), 'info') return end
|
||||||
if Cfg.Options.Currency == 'markedbills' then return buildMarkedBillsMenu() end
|
if Cfg.Options.Currency == 'markedbills' then return buildMarkedBillsMenu() end
|
||||||
openMoneyWashInput()
|
openMoneyWashInput()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue