给予物品时的数量错误
Amount bug when giving items
我需要你的帮助。
我们遇到的问题是玩家可以在库存中分配比正常情况下更多的东西(例如:我没有“25”三明治,但如果我输入“025”作为价值,我可以将 25 分给另一个玩家) .
有谁知道我该如何解决这个问题?
代码片段在这里:
(服务器端):
RegisterNetEvent('grv_inventory:giveItem')
AddEventHandler('grv_inventory:giveItem', function(name, count, target)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local xTarget = ESX.GetPlayerFromId(target)
if item == 'bandage' or 'bread' or 'bulletproof' or 'clip' or 'contract' or 'cuffs' or 'cuff_keys' or 'drill' or 'fixkit' or 'jewels' or 'medikit' or 'meth' or 'phone' or 'water' or 'kroeten' or 'kroeten_pooch' or 'ephi' or 'aramidfasern' or 'aramid' or 'kevlar' or 'holz' or 'schraube' or 'huelse' or 'radio' or 'bauxit' or 'aluminiumoxid' or 'aluminium' or 'eisenerz' or 'magazin' or 'trauben' or 'traubenverarbeitet' or 'lspdstandard' or 'orangen' or 'orangenverarbeitet' or 'lsfstandard' or 'weedsamen' or 'weed' or 'joint' or 'kocher' or 'tfcoupon' or 'ffcoupon' or 'teddy' or 'rose' or 'srose' or 'kaffee' or 'cola' or 'steine' or 'fib1' or 'fib2' or 'fib3' or 'lspdweste1' or 'lspdweste2' or 'lspdweste3' then
xPlayer.removeInventoryItem(name, count)
xTarget.addInventoryItem(name, count)
TriggerClientEvent('esx:showNotification', target, "Du hast " ..count.. "x " ..name.. " bekommen ")
TriggerClientEvent('grv_inventory:setMax', source, count)
end
end)
(客户端):
RegisterNUICallback('give', function(data, cb)
toggleField(false)
SetNuiFocus(false, false)
local playerPed = GetPlayerPed(-1)
loadAnimDict('anim@mp_snowball')
local player, dist = ESX.Game.GetClosestPlayer()
if player == -1 or dist > 3.0 then
ESX.ShowNotification('Es ist keine Person in der Nähe')
else
TaskPlayAnim(PlayerPedId(), 'anim@mp_snowball', 'pickup_snowball', 8.0, -1, -1, 0, 1, 0, 0, 0)
Citizen.Wait(1300)
ClearPedTasksImmediately(playerPed)
TriggerServerEvent('grv_inventory:giveItem', data.item, data.amount, GetPlayerServerId(player))
ESX.ShowNotification(("Du hast jemanden %sx %s zugesteckt"):format(data.amount, data.label))
end
cb('ok')
end)
非常感谢!
您有几个问题:
- 比较
if item == 'bandage' or 'bread' ... then
不会按照您的预期进行,因为 bread
将被评估为 true
(因为它没有与 item
进行比较值),因此无论实际值或 item
是什么,整个表达式都将被计算为 true
。您需要将其重写为 it item == 'bandage' or item = 'bread' ... and so on
- 我没有看到与可用项目的任何比较,所以它要么发生在其他地方(并且由于第一个问题而未应用)或者没有完成。
我需要你的帮助。
我们遇到的问题是玩家可以在库存中分配比正常情况下更多的东西(例如:我没有“25”三明治,但如果我输入“025”作为价值,我可以将 25 分给另一个玩家) .
有谁知道我该如何解决这个问题?
代码片段在这里:
(服务器端):
RegisterNetEvent('grv_inventory:giveItem')
AddEventHandler('grv_inventory:giveItem', function(name, count, target)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local xTarget = ESX.GetPlayerFromId(target)
if item == 'bandage' or 'bread' or 'bulletproof' or 'clip' or 'contract' or 'cuffs' or 'cuff_keys' or 'drill' or 'fixkit' or 'jewels' or 'medikit' or 'meth' or 'phone' or 'water' or 'kroeten' or 'kroeten_pooch' or 'ephi' or 'aramidfasern' or 'aramid' or 'kevlar' or 'holz' or 'schraube' or 'huelse' or 'radio' or 'bauxit' or 'aluminiumoxid' or 'aluminium' or 'eisenerz' or 'magazin' or 'trauben' or 'traubenverarbeitet' or 'lspdstandard' or 'orangen' or 'orangenverarbeitet' or 'lsfstandard' or 'weedsamen' or 'weed' or 'joint' or 'kocher' or 'tfcoupon' or 'ffcoupon' or 'teddy' or 'rose' or 'srose' or 'kaffee' or 'cola' or 'steine' or 'fib1' or 'fib2' or 'fib3' or 'lspdweste1' or 'lspdweste2' or 'lspdweste3' then
xPlayer.removeInventoryItem(name, count)
xTarget.addInventoryItem(name, count)
TriggerClientEvent('esx:showNotification', target, "Du hast " ..count.. "x " ..name.. " bekommen ")
TriggerClientEvent('grv_inventory:setMax', source, count)
end
end)
(客户端):
RegisterNUICallback('give', function(data, cb)
toggleField(false)
SetNuiFocus(false, false)
local playerPed = GetPlayerPed(-1)
loadAnimDict('anim@mp_snowball')
local player, dist = ESX.Game.GetClosestPlayer()
if player == -1 or dist > 3.0 then
ESX.ShowNotification('Es ist keine Person in der Nähe')
else
TaskPlayAnim(PlayerPedId(), 'anim@mp_snowball', 'pickup_snowball', 8.0, -1, -1, 0, 1, 0, 0, 0)
Citizen.Wait(1300)
ClearPedTasksImmediately(playerPed)
TriggerServerEvent('grv_inventory:giveItem', data.item, data.amount, GetPlayerServerId(player))
ESX.ShowNotification(("Du hast jemanden %sx %s zugesteckt"):format(data.amount, data.label))
end
cb('ok')
end)
非常感谢!
您有几个问题:
- 比较
if item == 'bandage' or 'bread' ... then
不会按照您的预期进行,因为bread
将被评估为true
(因为它没有与item
进行比较值),因此无论实际值或item
是什么,整个表达式都将被计算为true
。您需要将其重写为it item == 'bandage' or item = 'bread' ... and so on
- 我没有看到与可用项目的任何比较,所以它要么发生在其他地方(并且由于第一个问题而未应用)或者没有完成。