Fivem 脚本 - 切换头顶ID,在 5 秒后设置为 false

我有以下的函数

 disPlayerNames = 10 -- 你能看到 ID 的距离
keyToToggleIDs = 20 -- 默认为左 Alt

playerDistances = {}
showIDsAboveHead = false
Citizen.CreateThread(function()
    while true do
        if IsControlPressed(0, keyToToggleIDs) then
            showIDsAboveHead = not showIDsAboveHead
            print("更改")
            Wait(0)
        end
        Wait(50)
    end
end)

Citizen.CreateThread(function()
    while true do
        for id = 0, 255 do
            if GetPlayerPed(id) ~= GetPlayerPed(-1) then
                x1, y1, z1 = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
                x2, y2, z2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true))
                distance = math.floor(GetDistanceBetweenCoords(x1,  y1,  z1,  x2,  y2,  z2,  true))
                playerDistances[id] = distance
            end
        end
        Citizen.Wait(1000)
    end
end)

Citizen.CreateThread(function()
    while true do
        if showIDsAboveHead then
            for id = 0, 255 do
                if NetworkIsPlayerActive(id) then
                    if GetPlayerPed(id) ~= GetPlayerPed(-1) then
                        if (playerDistances[id] < disPlayerNames) then
                            x2, y2, z2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true))
                            if NetworkIsPlayerTalking(id) then
                                DrawText3D(x2, y2, z2+1, GetPlayerServerId(id), 247,124,24)
                            else
                                DrawText3D(x2, y2, z2+1, GetPlayerServerId(id), 255,255,255)
                            end
                        end
                    end
                end
            end
        end
        Citizen.Wait(0)
    end
end)

function DrawText3D(x,y,z, text, r,g,b)
    local onScreen,_x,_y=World3dToScreen2d(x,y,z)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)

    local scale = (1/dist)*2
    local fov = (1/GetGameplayCamFov())*100
    local scale = scale*fov

    if onScreen then
        SetTextScale(0.0*scale, 0.55*scale)
        SetTextFont(0)
        SetTextProportional(1)
        SetTextColour(r, g, b, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
        DrawText(_x,_y)
    end
end

这个函数工作良好,但现在需要按下按键切换 ID,然后再次按下才能关闭。

我需要编辑函数,使其在按下控件时显示 ID,仅显示 5 秒,然后将 showIDsAboveHead 设置为 false。

我还需要在按下控制时添加 dpemote 动画。该动画称为 think3。 我尝试过使用 RegisterCommand,但它不能正常工作。

有谁可以帮忙吗?谢谢!

原文链接 https://stackoverflow.com/questions/69588774

点赞
stackoverflow用户17023303
stackoverflow用户17023303

你有一个本地调用 IsControlJustPressed,当按下控制键时为 true(不像 IsControlPressed 那样一直为 true)。

将你的循环改成这样就可以了

Citizen.CreateThread(function()
    while true do
        if IsControlJustPressed(0, keyToToggleIDs) then
            showIDsAboveHead = true
            Citizen.Wait(5000)
            showIDsAboveHead = false
        end
        Wait(50)
    end
end)
2021-10-18 09:09:42