forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
ef0ad6cdc0
commit
c9fb3c9b95
1 changed files with 10 additions and 89 deletions
|
@ -1,21 +1,5 @@
|
|||
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()
|
||||
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)
|
||||
|
@ -68,22 +52,12 @@ lib.callback.register('r_moneywash:startWashingProgressBar', function()
|
|||
end)
|
||||
|
||||
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'
|
||||
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)
|
||||
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)
|
||||
|
||||
-- Ensure metadata is properly handled
|
||||
local safeMetadata = metadata or {}
|
||||
TriggerServerEvent('r_moneywash:startWashingMoney', cache.serverId, amount, safeMetadata)
|
||||
|
||||
TriggerServerEvent('r_moneywash:startWashingMoney', cache.serverId, amount, metadata)
|
||||
_debug('[DEBUG] - Money given, starting exchange')
|
||||
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)
|
||||
|
@ -92,25 +66,7 @@ end
|
|||
|
||||
local function giveExchangeOffer(amount, metadata)
|
||||
local taxRate = lib.callback.await('r_moneywash:getTaxRate', false)
|
||||
|
||||
-- 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 given = amount if metadata then given = metadata.worth end
|
||||
local offer = math.ceil(given - (given * taxRate / 100))
|
||||
local confirm = lib.alertDialog({
|
||||
header = _L('money_wash'),
|
||||
|
@ -128,43 +84,19 @@ local function buildMarkedBillsMenu()
|
|||
ClearPedTasks(entities.npc)
|
||||
PlayPedAmbientSpeechNative(entities.npc, 'GENERIC_HOWS_IT_GOING', 'SPEECH_PARAMS_FORCE')
|
||||
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
|
||||
if item and item.name == Cfg.Options.Currency then
|
||||
-- Add a check for metadata and item count
|
||||
local description = ""
|
||||
if item.metadata and item.metadata.worth then
|
||||
description = _L('marked_worth', item.metadata.worth)
|
||||
else
|
||||
description = _L('marked_worth', item.count or 0) -- Fallback to using the count or 0
|
||||
end
|
||||
|
||||
if item.name == Cfg.Options.Currency then
|
||||
table.insert(options, {
|
||||
title = item.label or Cfg.Options.Currency,
|
||||
description = description,
|
||||
title = item.label,
|
||||
description = _L('marked_worth', item.metadata.worth),
|
||||
icon = 'fas fa-money-bill-wave',
|
||||
iconColor = '#fa5252',
|
||||
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)
|
||||
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({
|
||||
id = 'moneywash_markedbills',
|
||||
title = _L('money_wash'),
|
||||
|
@ -176,24 +108,13 @@ end
|
|||
|
||||
local function openMoneyWashInput()
|
||||
local playerCash = lib.callback.await('r_moneywash:getInventoryItem', false, Cfg.Options.Currency)
|
||||
if not playerCash or not playerCash.count then
|
||||
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
|
||||
|
||||
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')
|
||||
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 },
|
||||
})
|
||||
|
||||
if not input or not input[1] then return end
|
||||
if not input then return end
|
||||
giveExchangeOffer(tonumber(input[1]))
|
||||
end
|
||||
|
||||
|
@ -280,7 +201,7 @@ function locPoint:onEnter()
|
|||
distance = 2,
|
||||
onSelect = function()
|
||||
local onCooldown = lib.callback.await('r_moneywash:getPlayerCooldown', false)
|
||||
_debug('[DEBUG] - Player cooldown status:', onCooldown)
|
||||
print(onCooldown)
|
||||
if onCooldown then Core.Framework.Notify(_L('on_cooldown'), 'info') return end
|
||||
if Cfg.Options.Currency == 'markedbills' then return buildMarkedBillsMenu() end
|
||||
openMoneyWashInput()
|
||||
|
@ -310,4 +231,4 @@ AddEventHandler('onResourceStop', function(resource)
|
|||
if DoesEntityExist(entity) then DeleteEntity(entity) end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue