0

我有以下功能

 disPlayerNames = 10 --distance you see IDs at 
keyToToggleIDs = 20 --left alt by default

playerDistances = {}
showIDsAboveHead = false
Citizen.CreateThread(function()
    while true do 
        if IsControlPressed(0, keyToToggleIDs) then
            showIDsAboveHead = not showIDsAboveHead
            print("changed")
            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 ,然后再次按下它以关闭。

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

按下控件时,我还需要添加一个 dpemote 动画。该动画称为think3。我试图用 RegisterCommand 来做,但它不起作用。

任何人都可以帮忙吗?谢谢!

4

1 回答 1

0

您有一个本地调用IsControlJustPressed,当控件被按下时它是 true (而不是持续 true as IsControlPressed

将循环更改为此应该可以

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-18T09:09:42.723 回答