example
example

已解决√ 求助 毒品采集 背包没东西 毒品重量也改了但是还是显示背包满

ox 文档
里边介绍了将 setr inventory:weight 30000 添加到server.cfg来修改背包容量
 
把配置setr inventory:weight 30000放在ensure ox_inventory后边试试
 
1733904995453.png
ensure ox_inventor????
麻烦仔细检查一下
 
人家的文档就是这样写,没有其他的可能性,没效果的话就是你自己哪里没弄好,多检查检查。
 
可以的話,發毒品的sever/client,因該是偵測的問題
--ESX = nil
ESX = exports["es_extended"]:getSharedObject()
--TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
-- Logs
local discord = {
['webhook'] = '',
['name'] = 'DrugBot',
['image'] = 'https://media.discordapp.net/attach...79955616-612x612.jpg.png?width=676&height=676'
}
function Log(name, message)
local data = {
{
["color"] = '15277667',
["title"] = "**".. name .."**",
["description"] = "**".. message .."**",
}
}
PerformHttpRequest(discord['webhook'], function(err, text, headers) end, 'POST', json.encode({username = discord['name'], embeds = data, avatar_url = discord['image']}), { ['Content-Type'] = 'application/json' })
end
-- Support old ESX btw idk why you dont want update :/
function showNotification(src, msg)
TriggerClientEvent('esx:showNotification', src, msg)
end
-- thanks to loaf he made this snip long time ago so i didnt put time to read old esx to see how those work :D https://docs.loaf-scripts.com/
function canCarryItem(src, item, count)
local xPlayer = ESX.GetPlayerFromId(src)
if not count then count = 1 end
local item = xPlayer.getInventoryItem(item)
return ((item.weight == -1) or ((item.count + count) <= item.weight))
end


-- Get Enough Jobs Is in Server Or No
function HaveEnough(JobTable)
local Have = true
if ESX.GetExtendedPlayers then
for k,v in pairs(JobTable) do
local xPlayers = ESX.GetExtendedPlayers("job",k)
if #xPlayers < v then
Have = false
break
end
end
elseif ESX.GetPlayers then
local xPlayers = ESX.GetPlayers()
local Connected = {}
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers)
if JobTable[xPlayer.job.name] then
if not Connected[xPlayer.job.name] then Connected[xPlayer.job.name] = 0 end
Connected[xPlayer.job.name] = Connected[xPlayer.job.name] + 1
end
end
for k,v in pairs(JobTable) do
if not Connected[k] or Connected[k] < v then
Have = false
break
end
end
else
local Players = GetPlayers()
local Connected = {}
for i=1, #Players, 1 do
local xPlayer = ESX.GetPlayerFromId(Players)
if xPlayer and xPlayer.job and xPlayer.job.name then
if JobTable[xPlayer.job.name] then
if not Connected[xPlayer.job.name] then Connected[xPlayer.job.name] = 0 end
Connected[xPlayer.job.name] = Connected[xPlayer.job.name] + 1
end
end
end
for k,v in pairs(JobTable) do
if not Connected[k] or Connected[k] < v then
Have = false
break
end
end
end
return Have
end
-- Harvesting Event
RegisterServerEvent('lab-fields:harvest')
AddEventHandler('lab-fields:harvest', function(Index)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.job.name == 'police' then
TriggerClientEvent('esx:showNotification', source, '警察禁止采集')
return
end
if xPlayer.job.name == 'offpolice' then
TriggerClientEvent('esx:showNotification', source, '警察禁止采集')
return
end
if xPlayer.job.name == 'ambulance' then
TriggerClientEvent('esx:showNotification', source, '医护禁止采集')
return
end
if xPlayer.job.name == 'offambulance' then
TriggerClientEvent('esx:showNotification', source, '医护禁止采集')
return
end

local Field = Config.Fields[Index]
if not xPlayer then return end
if (not Field.jobs) or (Field.jobs[xPlayer.job.name] and Field.jobs[xPlayer.job.name] <= xPlayer.job.grade) then
local IsThereEnoughJob = true
local xPlayers = ESX.GetExtendedPlayers('job', 'police')
local RequiredCopsWeed = #xPlayers

if Field.neededJobs then
IsThereEnoughJob = HaveEnough(Field.neededJobs)
end
if RequiredCopsWeed >= 0 then --警察数量设置
--if IsThereEnoughJob then
local GivenItemName = Field.itemName
math.randomseed(os.time() + math.random(os.time()) + math.random())
math.random(); math.random(); math.random();
local GivenItemCount = math.random(math.min(Field.amount.Min, Field.amount.Max),math.max(Field.amount.Min, Field.amount.Max))
local Label = Field.label or ESX.GetItemLabel(GivenItemName)
if xPlayer.canCarryItem(GivenItemName, GivenItemCount) then
xPlayer.addInventoryItem(GivenItemName, GivenItemCount)
showNotification(source, '你采集了' .. GivenItemCount .. '个' .. Label .. '!')
else
showNotification(source, '你的背包满了!')
end
else
showNotification(source, '没有足够的警察在线.')
end
else
showNotification(source, 'You cant dot this in this job you have.')
end
end)

-- Processing Event
RegisterServerEvent('lab-fields:process')
AddEventHandler('lab-fields:process', function(Index)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.job.name == 'police' then
TriggerClientEvent('esx:showNotification', source, '警察不能进行加工')
return
end
if xPlayer.job.name == 'offpolice' then
TriggerClientEvent('esx:showNotification', source, '警察不能进行加工')
return
end
if xPlayer.job.name == 'ambulance' then
TriggerClientEvent('esx:showNotification', source, '医护不能进行加工')
return
end
if xPlayer.job.name == 'offambulance' then
TriggerClientEvent('esx:showNotification', source, '医护不能进行加工')
return
end
local Lab = Config.Labs[Index]
if not xPlayer then return end
if (not Lab.jobs) or (Lab.jobs[xPlayer.job.name] and Lab.jobs[xPlayer.job.name] <= xPlayer.job.grade) then
local IsThereEnoughJob = true
local RequiredCopsWeed = 0
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers)
if xPlayer.job.name == 'police' then
RequiredCopsWeed = RequiredCopsWeed + 1
end
end
if Lab.neededJobs then
IsThereEnoughJob = HaveEnough(Lab.neededJobs)
end
--if IsThereEnoughJob then
if RequiredCopsWeed >= 0 then --警察数量设置
local givenItem = Lab.givenItem
math.randomseed(os.time() + math.random(os.time()) + math.random())
math.random(); math.random(); math.random();
local givenAmount = math.random(math.min(Lab.givenAmount.Min, Lab.givenAmount.Max),math.max(Lab.givenAmount.Min, Lab.givenAmount.Max))
local givenLabel = Lab.givenLabel or ESX.GetItemLabel(givenItem)
local neededItem = Lab.neededItem
local neededItem1 = Lab.neededItem1
local neededAmount = Lab.neededAmount
local neededLabel = Lab.neededLabel
local neededLabel1 = Lab.neededLabel1
if xPlayer.getInventoryItem(neededItem) and xPlayer.getInventoryItem(neededItem1) and xPlayer.getInventoryItem(neededItem).count and xPlayer.getInventoryItem(neededItem1).count >= neededAmount and ((xPlayer.canCarryItem and xPlayer.canCarryItem(givenItem, givenAmount)) or canCarryItem(source, givenItem, givenAmount)) then
xPlayer.removeInventoryItem(neededItem, neededAmount)
xPlayer.removeInventoryItem(neededItem1, neededAmount)
print(givenItem, givenAmount)
xPlayer.addInventoryItem(givenItem, givenAmount)
showNotification(source, '你把' .. neededAmount .. '个' .. neededLabel..'和'.. neededLabel1 .. ' 加工成' .. givenAmount .. '个' .. givenLabel ..'.')
-- TriggerClientEvent("pNotify:SendNotification", source, {text = '<b>毒品</b></br>你把' .. neededAmount .. '个' .. neededLabel..'和'.. neededLabel1 .. ' 加工成 ' .. givenAmount .. '个' .. givenLabel ..'.', timeout = 3000})
else
showNotification(source, '材料不足,无法加工!')
-- TriggerClientEvent("pNotify:SendNotification", source, {text = '<b>毒品</b></br>材料不足,无法加工!', timeout = 3000})
end
else
showNotification(source, '没有足够的警察在线.')
-- TriggerClientEvent("pNotify:SendNotification", source, {text = '<b>毒品</b></br>没有足够的警察在线!', timeout = 3000})
end
else
showNotification(source, 'You cant dot this in this job you have.')
end
end)
 
可以的話,發毒品的sever/client,因該是偵測的問題
local isPickingUp = false
local SpawningWay = false
ESX = exports["es_extended"]:getSharedObject()
--ESX = nil
PlayerData = {}
Citizen.CreateThread(function()
while ESX.GetPlayerData().job == nil do
Citizen.Wait(100)
end
Citizen.Wait(800)
PlayerData = ESX.GetPlayerData() -- Setting PlayerData vars
end)

RegisterNetEvent("esx:playerLoaded")
AddEventHandler("esx:playerLoaded", function(Player)
PlayerData = Player
end)
RegisterNetEvent("esx:setJob")
AddEventHandler("esx:setJob", function(Job)
PlayerData.job = Job -- Setting PlayerJob on change or player loaded
end)
function GenerateCords(Field, spawnedPlantsA, DrugPlants)
while true do
Citizen.Wait(100)
local CoordX, CoordY
math.randomseed(GetGameTimer() + math.random(GetGameTimer()) + math.random())
math.random(); math.random(); math.random();
local modX = math.random(-20, 20)
math.randomseed(GetGameTimer() + math.random(GetGameTimer()) + math.random())
math.random(); math.random(); math.random();
local modY = math.random(-20, 20)
CoordX = Field.x + modX
CoordY = Field.y + modY
CoordZ = Field.z
local coord = vector3(CoordX, CoordY, CoordZ)
if EnsureCoords(coord, Field, spawnedPlantsA, DrugPlants) then
return coord
end
end
end
function EnsureCoords(plantCoord, field, spawnedPlantsA, DrugPlants)
if spawnedPlantsA > 0 then
local Ensured = true
for k, v in pairs(DrugPlants) do
if #(plantCoord - GetEntityCoords(v)) < 5 then
Ensured = false
end
end
if #(plantCoord - field) > 50 then
Ensured = false
end
return Ensured
else
return true
end
end
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
for k, v in ipairs(Config.Fields) do
for k, v in pairs(v.DrugPlantsA) do
ESX.Game.DeleteObject(v)
end
end
end
end)
Citizen.CreateThread(function()
while true do
local Cooldown = 0
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local nearbyObject, nearbyID
for k, v in ipairs(Config.Fields) do
if #(coords - v.FieldCoords) < 50 then
Cooldown = 500
if v.spawnedPlants < 15 and not SpawningWay then
SpawningWay = true
while v.spawnedPlants < 15 do
Citizen.Wait(0)
v.DrugCoords = GenerateCords(v.FieldCoords, v.spawnedPlants, v.DrugPlantsA)
ESX.Game.SpawnLocalObject(
v.DrugProp,
v.DrugCoords,
function(obj)
PlaceObjectOnGroundProperly(obj)
FreezeEntityPosition(obj, true)
table.insert(v.DrugPlantsA, obj)
v.spawnedPlants = v.spawnedPlants + 1
end
)
end
SpawningWay = false
end
for i = 1, #v.DrugPlantsA, 1 do
if #(coords - GetEntityCoords(v.DrugPlantsA)) < 2 then
nearbyObject, nearbyID = v.DrugPlantsA, i
end
end
if nearbyObject and IsPedOnFoot(playerPed) then
if not isPickingUp then
Cooldown = 5
local plantcoords = GetEntityCoords(nearbyObject)
DrawText3Ds(plantcoords.x,plantcoords.y,plantcoords.z + 1.0,"[~HUD_COLOUR_CONTROLLER_MICHAEL~E~w~] 采集 " .. v.label .. ".")
end
if Config.PropOutline then
if #(coords - GetEntityCoords(nearbyObject)) < 1.8 then
SetEntityDrawOutline(nearbyObject, true)
SetEntityDrawOutlineColor(Config.OutlineColor.r, Config.OutlineColor.g, Config.OutlineColor.b,1)
else
SetEntityDrawOutline(nearbyObject, false)
end
end
if IsControlJustReleased(0, 38) and not isPickingUp then
local Job = 0
if v.jobs then
if PlayerData.job ~= nil and PlayerData.job.name and v.jobs[PlayerData.job.name] and v.jobs[PlayerData.job.name] <= PlayerData.job.grade then
isPickingUp = true
TriggerEvent("mythic_progbar:client:progress",
{
name = "harvesting",
duration = v.duration,
label = "采集中..",
useWhileDead = false,
canCancel = true,
controlDisables = {
disableMovement = true,
disableCarMovement = false,
disableMouse = false,
disableCombat = true
},
animation = {
animDict = v.animDict,
anim = v.anim
}
},
function(status)
if not status then
ClearPedTasks(PlayerPedId())
FreezeEntityPosition(PlayerPedId(), false)
ESX.Game.DeleteObject(nearbyObject)
table.remove(v.DrugPlantsA, nearbyID)
v.spawnedPlants = v.spawnedPlants - 1
TriggerServerEvent("lab-fields:harvest", k)
isPickingUp = false
end
end
)
else
ESX.ShowNotification("不允许你采集此物品.")
end
else
isPickingUp = true
TriggerEvent(
"mythic_progbar:client:progress",
{
name = "harvestheroin",
duration = v.duration,
label = "采集中..",
useWhileDead = false,
canCancel = true,
controlDisables = {
disableMovement = true,
disableCarMovement = false,
disableMouse = false,
disableCombat = true
},
animation = {
animDict = v.animDict,
anim = v.anim
}
},
function(status)
if not status then
ClearPedTasks(PlayerPedId())
FreezeEntityPosition(PlayerPedId(), false)
ESX.Game.DeleteObject(nearbyObject)
table.remove(v.DrugPlantsA, nearbyID)
v.spawnedPlants = v.spawnedPlants - 1
TriggerServerEvent("lab-fields:harvest", k)
isPickingUp = false
end
end
)
end
end
end
end
end
Citizen.Wait(Cooldown)
end
end)

function DrawText3Ds(x, y, z, text)
SetTextScale(0.45, 0.45)
SetTextFont(0)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
SetTextDropshadow(1, 1, 1, 1, 255)
AddTextComponentString(text)
SetDrawOrigin(x,y,z, 0)
DrawText(0.0, 0.0)
ClearDrawOrigin()
end
Citizen.CreateThread(function()
for k2, v in ipairs(Config.Fields) do
if v.blip then
local coords = v.FieldCoords
if v.blipRadius then
local k = AddBlipForRadius(coords, 150.0)
SetBlipHighDetail(k, true)
SetBlipColour(k, 1)
SetBlipAlpha (k, 128)
end
k = AddBlipForCoord(coords)
SetBlipHighDetail(k, true)
SetBlipSprite (k, v.blipSprite)
SetBlipScale (k, Config.BlipSize)
SetBlipColour (k, v.blipColour)
SetBlipAsShortRange(k, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(v.label .. ' 采集区')
EndTextCommandSetBlipName(k)
end
end
end)
 
后退
顶部