esx-community / esx_thief

FXServer ESX Thief
GNU General Public License v3.0
32 stars 22 forks source link

Error Steal #30

Open matikhh opened 4 years ago

matikhh commented 4 years ago

He won't let me steal the money or anything from the inventory, it appears on the console: @esx_thief/server/main.lua.57 attempt to compare number with nil

BartukyGames commented 3 years ago

Replace in esx_thief/main/server.lua: For Steal ITEMS: Lines 35 to 53 Last Code: l local label = sourceXPlayer.getInventoryItem(itemName).label local itemLimit = sourceXPlayer.getInventoryItem(itemName).limit local sourceItemCount = sourceXPlayer.getInventoryItem(itemName).count local targetItemCount = targetXPlayer.getInventoryItem(itemName).count

if amount > 0 and targetItemCount >= amount then
    if itemLimit ~= -1 and (sourceItemCount + amount) > itemLimit then
        TriggerClientEvent('esx:showNotification', targetXPlayer.source, _U('ex_inv_lim_target'))
        TriggerClientEvent('esx:showNotification', sourceXPlayer.source, _U('ex_inv_lim_source'))
    else
        targetXPlayer.removeInventoryItem(itemName, amount)
        sourceXPlayer.addInventoryItem(itemName, amount)

        TriggerClientEvent('esx:showNotification', sourceXPlayer.source, _U('you_stole') .. ' ~g~x' .. amount .. ' ' .. label .. ' ~w~' .. _U('from_your_target') )
        TriggerClientEvent('esx:showNotification', targetXPlayer.source, _U('someone_stole') .. ' ~r~x'  .. amount .. ' ' .. label )
    end
else
    TriggerClientEvent('esx:showNotification', _source, _U('invalid_quantity'))
end

New Code:

local label = sourceXPlayer.getInventoryItem(itemName).label

if amount > 0 then
    if sourceXPlayer.canCarryItem(itemName, amount) then
        targetXPlayer.removeInventoryItem(itemName, amount)
        sourceXPlayer.addInventoryItem(itemName, amount)
        TriggerClientEvent('esx:showNotification', sourceXPlayer.source, _U('you_stole') .. ' ~g~x' .. amount .. ' ' .. label .. ' ~w~' .. _U('from_your_target') )
        TriggerClientEvent('esx:showNotification', targetXPlayer.source, _U('someone_stole') .. ' ~r~x'  .. amount .. ' ' .. label )
    else 
        sourceXPlayer.showNotification("No puedes con tanto peso", sourceXPlayer.name)
    end
else
    TriggerClientEvent('esx:showNotification', _source, _U('invalid_quantity'))
end
BartukyGames commented 3 years ago

Replace in esx_thief/main/server.lua: For MONEY: Lines 56 to 66 Last Code:

if amount > 0 and targetXPlayer.get('money') >= amount then
    targetXPlayer.removeMoney(amount)
    sourceXPlayer.addMoney(amount)

    TriggerClientEvent('esx:showNotification', sourceXPlayer.source, _U('you_stole') .. ' ~g~$' .. amount .. ' ~w~' .. _U('from_your_target') )
    TriggerClientEvent('esx:showNotification', targetXPlayer.source, _U('someone_stole') .. ' ~r~$'  .. amount )
else
    TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
end

New Code: if amount > 0 and targetXPlayer.getAccount("money").money >= amount then targetXPlayer.removeMoney(amount) sourceXPlayer.addMoney(amount) TriggerClientEvent('esx:showNotification', sourceXPlayer.source, _U('you_stole') .. ' g$' .. amount .. ' w' .. _U('from_your_target') ) TriggerClientEvent('esx:showNotification', targetXPlayer.source, _U('someone_stole') .. ' r$' .. amount ) else TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) end