tengo la siguiente funcion
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 endSin embargo, la función funciona bien, en este momento debe presionar la tecla para alternar la identificación y luego presionarla nuevamente para desactivarla.
Necesito editar la función para mostrar la identificación al presionar el control solo durante 5 segundos y luego establecer showIDsAboveHead en falso.
También necesito agregar una animación dpemote al presionar el control. La animación se llama think3. Intenté hacerlo con RegisterCommand pero no funciona.
¿Alguien puede ayudar? ¡Gracias!
Tiene un nativo llamado IsControlJustPressed que es verdadero una vez cuando se presiona el control (y no continuamente verdadero como IsControlPressed )
Cambiar tu ciclo a esto debería funcionar
Citizen.CreateThread(function() while true do if IsControlJustPressed(0, keyToToggleIDs) then showIDsAboveHead = true Citizen.Wait(5000) showIDsAboveHead = false end Wait(50) end end)