local deliveryNPC = Config.NPCPosition
local currentJob = nil -- 当前送餐任务
-- 创建NPC
Citizen.CreateThread(function()
RequestModel("a_m_m_business_01") -- NPC模型
while not HasModelLoaded("a_m_m_business_01") do
Wait(500)
end
local npc = CreatePed(4, "a_m_m_business_01", deliveryNPC, false, true)
SetEntityAsMissionEntity(npc, true, true)
-- 添加目标
exports.ox_target:addLocalEntity(npc, {
{
name = 'talk_to_boss',
label = '与老板交谈',
icon = 'fas fa-comments',
action = function()
openDialog()
end,
},
})
end)
-- 打开对话框
function openDialog()
local choice = exports.ox_lib:Prompt("选择选项", Config.DialogueOptions)
if choice == 1 then
startDeliveryJob() -- 接收任务
elseif choice == 2 then
showTaskItemsInfo() -- 显示可送物品的信息
end
end
-- 展示任务物品信息
function showTaskItemsInfo()
local items = ""
for item, detail in pairs(Config.TaskItemsDetails) do
items = items .. item .. ": " .. detail .. "\n"
end
exports.ox_lib:Notify("可送物品及其信息:\n" .. items)
openDialog() -- 结束后返回对话框
end
-- 接受送餐任务
function startDeliveryJob()
local vehicleOptions = {}
for i, v in ipairs(Config.VehicleChoices) do
table.insert(vehicleOptions, v.label)
end
local selectedVehicleIndex = exports.ox_lib:Prompt("选择车辆", vehicleOptions)
if not selectedVehicleIndex then return end
local selectedItemIndex = exports.ox_lib:Prompt("选择送餐物品", Config.TaskItems) -- 选择送餐物品
if not selectedItemIndex then return end
local vehicleModel = Config.VehicleChoices[selectedVehicleIndex].model
currentJob = {
item = Config.TaskItems[selectedItemIndex],
vehicle = vehicleModel,
reward = math.random(Config.MinReward, Config.MaxReward)
}
spawnDeliveryVehicle(vehicleModel)
displayCurrentJobDetails() -- 显示当前任务详情
end
-- 生成送货车辆
function spawnDeliveryVehicle(model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(500)
end
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local vehicle = CreateVehicle(model, playerCoords.x + 2, playerCoords.y + 2, playerCoords.z, GetEntityHeading(playerPed), true, false)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
end
-- 完成送餐任务并给予奖励
function completeDeliveryJob()
if currentJob then
TriggerServerEvent('delivery:giveReward', currentJob.reward) -- 发送奖励给服务端处理
currentJob = nil -- 重置当前任务
end
end
-- 绘制送餐任务详情
function displayCurrentJobDetails()
Citizen.CreateThread(function()
while currentJob do
Wait(0)
DrawText(0.05, 0.5, "当前送餐任务:", 0.4)
DrawText(0.05, 0.55, "物品: " .. currentJob.item, 0.4)
DrawText(0.05, 0.6, "车辆: " .. currentJob.vehicle, 0.4)
DrawText(0.05, 0.65, "奖励: $" .. currentJob.reward, 0.4)
end
end)
end
-- 绘制文本的函数
function DrawText(x, y, text, scale)
local font = 4
SetTextFont(font)
SetTextScale(scale, scale)
SetTextColour(255, 255, 255, 255) -- 白色
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x, y)
local factor = (string.len(text)) / 370
DrawRect(x + 0.01, y + 0.015, 0.015 + factor, 0.03, 0, 0, 0, 150) -- 半透明背景
end