教程
在 FiveM 制作一项单检查点任务

本页目录
在私有 FiveM 测试服务器上选定一个要到达的位置。客户端会在地图上显示标记,并在完成或取消时移除它。把下面的 Lua 示例加到自己测试资源的客户端脚本文件中。
local phase = 'idle'
local target, blip
local radius = 2.5
local function clearBlip()
if blip then
RemoveBlip(blip)
blip = nil
end
end
local function position()
return GetEntityCoords(PlayerPedId())
end
RegisterCommand('mission_demo', function(_, args)
local action = args[1]
if action == 'reset' then
clearBlip()
phase = 'idle'
print('Mission reset.')
elseif action == 'set' and phase == 'idle' then
target = position()
print('Checkpoint saved.')
elseif action == 'start' and phase == 'idle' and target then
if #(position() - target) <= radius then
print('Move away from the checkpoint first.')
return
end
blip = AddBlipForCoord(target.x, target.y, target.z)
phase = 'active'
print('Go to the checkpoint.')
else
print('Use mission_demo set, start or reset.')
end
end, false)
CreateThread(function()
while true do
if phase == 'active' and #(position() - target) <= radius then
phase = 'completed'
clearBlip()
print('Checkpoint reached.')
end
Wait(100)
end
end)
AddEventHandler('onClientResourceStop', function(resource)
if resource == GetCurrentResourceName() then
clearBlip()
end
end)
验证开始、完成和重置
- 站在空旷处,在 F8 控制台输入
mission_demo set,把当前位置存为目标点。走开几步,再输入mission_demo start。地图上应当出现一个标记。 - 向目标走回去。距离缩短到 2.5 个游戏单位以内时,控制台应当只显示一次
Checkpoint reached.,地图标记随即消失。 - 输入
mission_demo reset重置本次任务,目标点仍会保留。走到半径之外重新开始,在到达目标前重置。确认标记已经消失,回到目标点也不会再触发完成。
由 RP 服务器确认任务进度
这个练习中的任务状态、提示和地图标记都由客户端管理。涉及奖励或共享进度时,由服务器保存每名玩家的任务状态。在确认完成之前,服务器用自己的数据检查任务是否仍在进行、玩家是否到达目标附近,以及这次任务是否已结算。






评论0