希望大佬能给看看
client代码:
server代码:
config代码:
client代码:
lua:
local delivering = false
local currentLocation = nil
local interactedWithBoss = false -- 用于判断是否与老板互动
-- 创建外卖老板 NPC
function CreateDeliveryBoss()
local model = GetHashKey(Config.DeliveryBoss.model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(500) -- 等待模型加载
end
deliveryBossPed = CreatePed(4, model, Config.DeliveryBoss.position.x, Config.DeliveryBoss.position.y, Config.DeliveryBoss.position.z, Config.DeliveryBoss.heading or 0.0, false, true)
SetEntityAsMissionEntity(deliveryBossPed, true, true)
SetEntityInvincible(deliveryBossPed, true) -- NPC 不会受到伤害
SetBlockingOfNonTemporaryEvents(deliveryBossPed, true) -- 防止 NPC 被推开
FreezeEntityPosition(deliveryBossPed, true) -- 冻结 NPC 位置使其不能移动
end
local npc = CreatePed(0, pedModel, Config.DeliveryBossNPC.x, Config.DeliveryBossNPC.y, Config.DeliveryBossNPC.z, 0.0, true, false)
SetEntityInvincible(npc, true)
SetBlockingOfNonTemporaryEvents(npc, true)
-- 使用 ox_target 为NPC添加交互
exports.ox_target:addLocalEntity(npc, {
{
name = "TalkToDeliveryBoss",
icon = "fas fa-comment-dots",
label = "与外卖老板交谈",
onSelect = function()
interactedWithBoss = true
TriggerServerEvent('delivery:startDelivery', GetPlayerServerId(PlayerId()))
end,
},
})
end
-- 接收送餐详情
RegisterNetEvent('delivery:sendDeliveryDetails')
AddEventHandler('delivery:sendDeliveryDetails', function(location)
currentLocation = location
currentItem = location.item -- 获取要送的物品
delivering = true
-- 告诉玩家送餐的信息
TriggerEvent('chat:addMessage', {
args = {"外卖老板", "请将 " .. currentItem .. " 送到指定地点!"}
})
SetNewWaypoint(location.x, location.y) -- 在地图上标记送餐地点
end)
-- 结束送餐
function EndDelivery()
if delivering then
delivering = false
TriggerServerEvent('delivery:endDelivery')
-- 这里可以添加逻辑来返回外卖老板的地点
end
end
-- 选择车辆(这里可以根据实际情况添加车辆选择界面)
function SelectVehicle()
-- 假设玩家选择了车辆
local selectedVehicle = Config.Vehicles[math.random(#Config.Vehicles)]
-- 加载并生成车辆
-- 这里可以添加生成车辆的逻辑
end
-- 显示通知函数
function ShowNotification(text)
BeginTextCommandThefeedPost("STRING")
AddTextComponentSubstringPlayerName(text)
EndTextCommandThefeedPostMessag(1, 1, 0, text)
end
-- 绑定按键
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed(1, 38) and interactedWithBoss then -- E键
TalkToDeliveryBoss()
end
if IsControlJustPressed(1, 20) then -- X键
EndDelivery()
end
end
end)
}
lua:
local deliveries = {}
RegisterServerEvent('delivery:startDelivery')
AddEventHandler('delivery:startDelivery', function()
local src = source
local randomIndex = math.random(#Config.DeliveryLocations) -- 随机选择一个送餐地点
local deliveryLocation = Config.DeliveryLocations[randomIndex] -- 获取随机送餐位置
-- 将物品添加到玩家的库存
exports.ox_inventory:AddItem(src, deliveryLocation.item, 1)
TriggerClientEvent('delivery:sendDeliveryLocation', src, deliveryLocation)
end)
RegisterServerEvent('delivery:endDelivery')
AddEventHandler('delivery:endDelivery', function()
local src = source
local deliveryLocation = deliveries
if deliveryLocation then
-- 从玩家库存中移除送餐物品
exports.ox_inventory:RemoveItem(src, deliveryLocation.item, 1)
-- 给予随机奖励
local reward = math.random(500, 1000) -- 随机生成500到1000的奖励
TriggerEvent('es:getPlayerFromId', src, function(user)
user.addMoney(reward) -- 假设有addMoney函数,可以加钱给玩家
end)
-- 通知玩家获得奖励
TriggerClientEvent('notification:addNotification', src, "你获得了 $" .. reward .. " 的奖励!")
deliveries = nil -- 清除该玩家的送餐任务
TriggerClientEvent('delivery:notifyEnd', src)
end
end)
lua:
Config = {}
-- 送餐地点配置及相应的物品
onfig.DeliveryLocations = {
{x = 200.0, y = -1000.0, z = 30.0, item = "pizza"}, -- 此处指定送餐物品
{x = 500.0, y = -1500.0, z = 30.0, item = "burger"},
{x = -400.0, y = -2000.0, z = 30.0, item = "drink"}
}
-- 可用车辆配置
Config.Vehicles = {
"pizza",
"bicycle",
"van"
}
-- 外卖老板NPC配置
Config.DeliveryBoss = {
model = "a_m_y_business_01", -- NPC模型名称
coords = {x = -314.0, y = -1035.21, z = 30.53}, -- NPC坐标
heading = 245.0 -- NPC朝向
}
Config.blips = {
{
text = '外卖老板',
sprite = 123,
color = 2,
scale = 1.0,
cords = {
{ x = -314.0, y = -1035.21, z = 30.53 },
},
},
由版主最后编辑: