我需要你的帮助一分钟。
我们的问题是玩家可以在库存中分配比通常可能更多的东西(例如:我没有“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)
非常感谢!