local PlayerPedId = PlayerPedId
local IsPedActiveInScenario = IsPedActiveInScenario
local IsPedStill = IsPedStill
local Wait = Wait
local IsControlPressed = IsControlPressed
local ClearPedTasks = ClearPedTasks
local TaskStartScenarioInPlace = TaskStartScenarioInPlace
local idle = false
local lastMovement = GetGameTimer()
local idleCheckTime = 3000 -- 3秒
local currentAction = 0
local actionScenarios = {
"WORLD_HUMAN_CHEERING", -- 双手摆手
"PROP_HUMAN_BUM_BIN", -- 双手摸头
"WORLD_HUMAN_STAND_MOBILE" -- 双手摸脸
}
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
local playerPed = PlayerPedId()
-- 检查玩家是否在移动
if IsPedOnFoot(playerPed) and not IsPedStill(playerPed) then
lastMovement = GetGameTimer()
if idle then
idle = false
ClearPedTasks(playerPed)
currentAction = 0
end
end
-- 检查是否达到闲置时间
if not idle and GetGameTimer() - lastMovement > idleCheckTime then
idle = true
end
-- 如果闲置,播放动作
if idle and not IsPedActiveInScenario(playerPed) then
currentAction = currentAction + 1
if currentAction > #actionScenarios then
currentAction = 1
end
TaskStartScenarioInPlace(playerPed, actionScenarios[currentAction], 0, true)
end
end
end)
-- 如果玩家按任何键,重置闲置计时器
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
for i = 0, 350 do
if IsControlPressed(0, i) then
lastMovement = GetGameTimer()
if idle then
idle = false
ClearPedTasks(PlayerPedId())
currentAction = 0
end
break
end
end
end
end)