如何将脚本从限制更新为权重?Lua



我使用这个用Lua制作的救护工作。不幸的是,作为一个旧脚本,它没有更新,所以它仍然被设置为使用"限制";我将其改为&;weight&;因为我的游戏模式是基于权重以及数据库。但遗憾的是,它不工作,我得到这个错误。

RegisterServerEvent('esx_ambulancejob:giveItem')
AddEventHandler('esx_ambulancejob:giveItem', function(itemName)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name ~= 'ambulance' then
print(('esx_ambulancejob: %s attempted to spawn in an item!'):format(xPlayer.identifier))
return
elseif (itemName ~= 'medikit' and itemName ~= 'bandage') then
print(('esx_ambulancejob: %s attempted to spawn in an item!'):format(xPlayer.identifier))
return
end
local xItem = xPlayer.getInventoryItem(itemName)
local count = 1
if xItem.weight ~= -1 then (it was xItem.limit before)
count = xItem.weight - xItem.count
end
if xItem.count < xItem.weight then
xPlayer.addInventoryItem(itemName, count)
else
TriggerClientEvent('esx:showNotification', source, _U('max_item'))
end
end)

从药房取药时的错误画面:

控制台错误图像

我不知道哪一行是263,但是错误显示为object_name.weight is nil

观察代码,xItem没有字段权重(xItem.weight = nil)

错误在这一行

if xItem.weight ~= -1 then (it was xItem.limit before)
count = xItem.weight - xItem.count
end

知道什么值是空的,你可以在打印前加上

print("Test: " .. tostring(xItem.weith) .. " - " .. tostring(xItem.count);

但是,我认为你的操作是错误的,因为你做了

xItem.weight - xItem.count;

也许你想让

xItem.weight * xItem.count;

最新更新