218 lines
7.7 KiB
Lua
218 lines
7.7 KiB
Lua
-- ======= DO NOT EDIT THIS FILE ======= --
|
|
TLS.Functions = {}
|
|
TLS.Camera = {
|
|
entity = nil,
|
|
position = vector3(0.0, 0.0, 0.0),
|
|
active = false,
|
|
updateRot = false,
|
|
updateZoom = false,
|
|
radius = 1.25,
|
|
radiusMax = 2.25,
|
|
radiusMin = 1,
|
|
angleX = 30,
|
|
angleY = 0,
|
|
angleYMax = 80,
|
|
angleYMin = -30,
|
|
mouseX = 0,
|
|
mouseY = 0
|
|
}
|
|
|
|
function TLS.Functions.RequestModel(model)
|
|
if not HasModelLoaded(model) then
|
|
RequestModel(model)
|
|
while not HasModelLoaded(model) do
|
|
Wait(0)
|
|
end
|
|
end
|
|
end
|
|
|
|
function TLS.Functions.RequestAnimDict(dict)
|
|
if not HasAnimDictLoaded(dict) then
|
|
RequestAnimDict(dict)
|
|
while not HasAnimDictLoaded(dict) do
|
|
Wait(0)
|
|
end
|
|
end
|
|
end
|
|
|
|
function TLS.Functions.ShowHelpAlert(text)
|
|
AddTextEntry('helpAlert', text)
|
|
BeginTextCommandDisplayHelp('helpAlert')
|
|
EndTextCommandDisplayHelp(0, false, true, -1)
|
|
end
|
|
|
|
function TLS.Functions.DeleteEntity(entity)
|
|
SetEntityAsMissionEntity(entity, true, true)
|
|
DeleteEntity(entity)
|
|
end
|
|
|
|
function TLS.Functions.GetPlayerGender(playerPed)
|
|
if IsPedMale(playerPed) then
|
|
return 'Male'
|
|
else
|
|
return 'Female'
|
|
end
|
|
end
|
|
|
|
function TLS.Functions.GetPlayerDrawable(playerPed, index, isProp)
|
|
if isProp then
|
|
return GetPedPropIndex(playerPed, index), GetPedPropTextureIndex(playerPed, index)
|
|
else
|
|
return GetPedDrawableVariation(playerPed, index), GetPedTextureVariation(playerPed, index)
|
|
end
|
|
end
|
|
|
|
function TLS.Functions.GetPlayerClosestVehicle(playerPed)
|
|
local playerCoords = GetEntityCoords(playerPed)
|
|
local vehicles = GetGamePool('CVehicle')
|
|
local closestVehicle, closestDistance = -1, -1
|
|
for k, v in ipairs(vehicles) do
|
|
local vehicleCoords = GetEntityCoords(v)
|
|
local distance = #(vehicleCoords - playerCoords)
|
|
if closestDistance == -1 or closestDistance > distance then
|
|
closestVehicle = v
|
|
closestDistance = distance
|
|
end
|
|
end
|
|
return closestVehicle
|
|
end
|
|
|
|
function TLS.Functions.ShowNotification(text)
|
|
BeginTextCommandThefeedPost('STRING')
|
|
AddTextComponentSubstringPlayerName(text)
|
|
EndTextCommandThefeedPostTicker(true, true)
|
|
end
|
|
|
|
function TLS.Functions.GetClosestPoliceVehicle(playerPed)
|
|
local closestPoliceVehicle, isNearTrunk = -1, false
|
|
local vehicle = TLS.Functions.GetPlayerClosestVehicle(playerPed)
|
|
if GetVehicleClass(vehicle) == 18 then
|
|
local playerCoords, trunkCoords = GetEntityCoords(playerPed), GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, 'boot'))
|
|
closestPoliceVehicle = vehicle
|
|
if #(playerCoords - trunkCoords) < 3 then
|
|
isNearTrunk = true
|
|
end
|
|
end
|
|
return closestPoliceVehicle, isNearTrunk
|
|
end
|
|
|
|
function TLS.Camera.Enable(view)
|
|
if not DoesCamExist(TLS.Camera.entity) then
|
|
TLS.Camera.entity = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)
|
|
end
|
|
local playerPed = PlayerPedId()
|
|
FreezePedCameraRotation(playerPed, true)
|
|
FreezeEntityPosition(playerPed, true)
|
|
TLS.Camera.SetView(view)
|
|
SetCamActive(TLS.Camera.entity, true)
|
|
RenderScriptCams(true, true, 500, true, true)
|
|
TLS.Camera.active = true
|
|
end
|
|
|
|
function TLS.Camera.Disable()
|
|
local playerPed = PlayerPedId()
|
|
SetCamActive(TLS.Camera.entity, false)
|
|
RenderScriptCams(false, true, 500, true, true)
|
|
FreezePedCameraRotation(playerPed, false)
|
|
FreezeEntityPosition(playerPed, false)
|
|
TLS.Camera.active = false
|
|
end
|
|
|
|
function TLS.Camera.SetView(view)
|
|
local boneIndex = 11816
|
|
local playerPed = PlayerPedId()
|
|
if view == 'helmet' then
|
|
boneIndex = 31086
|
|
TLS.Camera.radiusMin = 0.8
|
|
TLS.Camera.radiusMax = 1.0
|
|
TLS.Camera.angleYMin = 60.0
|
|
TLS.Camera.angleYMax = 70.0
|
|
elseif view == 'eupui' then
|
|
boneIndex = 11816
|
|
TLS.Camera.radiusMin = 1.0
|
|
TLS.Camera.radiusMax = 2.0
|
|
TLS.Camera.angleYMin = 0.0
|
|
TLS.Camera.angleYMax = 35.0
|
|
end
|
|
TLS.Camera.radius = TLS.Camera.radiusMin
|
|
TLS.Camera.angleY = TLS.Camera.angleYMin
|
|
TLS.Camera.angleX = GetEntityHeading(playerPed) + 90.0
|
|
TLS.Camera.position = TLS.Camera.CalculatePosition(false)
|
|
SetCamCoord(TLS.Camera.entity, TLS.Camera.position.x, TLS.Camera.position.y, TLS.Camera.position.z)
|
|
targetPos = GetPedBoneCoords(playerPed, boneIndex, 0.0, 0.0, 0.0)
|
|
PointCamAtCoord(TLS.Camera.entity, targetPos.x, targetPos.y, targetPos.z)
|
|
end
|
|
|
|
function TLS.Camera.CalculateMaxRadius()
|
|
if TLS.Camera.radius < TLS.Camera.radiusMin then
|
|
TLS.Camera.radius = TLS.Camera.radiusMin
|
|
elseif TLS.Camera.radius > TLS.Camera.radiusMax then
|
|
TLS.Camera.radius = TLS.Camera.radiusMax
|
|
end
|
|
local result = TLS.Camera.radius
|
|
local playerPed = PlayerPedId()
|
|
local playerCoords = GetEntityCoords(playerPed)
|
|
local behindX = playerCoords.x + ((Cos(TLS.Camera.angleX) * Cos(TLS.Camera.angleY)) + (Cos(TLS.Camera.angleY) * Cos(TLS.Camera.angleX))) / 2 * (TLS.Camera.radius + 0.5)
|
|
local behindY = playerCoords.x + ((Sin(TLS.Camera.angleX) * Cos(TLS.Camera.angleY)) + (Cos(TLS.Camera.angleY) * Sin(TLS.Camera.angleX))) / 2 * (TLS.Camera.radius + 0.5)
|
|
local behindZ = ((Sin(TLS.Camera.angleY))) * (TLS.Camera.radius + 0.5)
|
|
local testRay = StartShapeTestRay(playerCoords.x, playerCoords.y, playerCoords.z + 0.5, behindX, behindY, behindZ, -1, playerPed, 0)
|
|
local _, hit, hitCoords = GetShapeTestResult(testRay)
|
|
local hitDist = Vdist(playerCoords.x, playerCoords.y, playerCoords.z + 0.5, hitCoords)
|
|
if hit and hitDist < TLS.Camera.radius + 0.5 then
|
|
result = hitDist
|
|
end
|
|
return result
|
|
end
|
|
|
|
function TLS.Camera.CalculatePosition(adjustedAngle)
|
|
if adjustedAngle then
|
|
TLS.Camera.angleX = TLS.Camera.angleX - TLS.Camera.mouseX * 0.1
|
|
TLS.Camera.angleY = TLS.Camera.angleY + TLS.Camera.mouseY * 0.1
|
|
end
|
|
if TLS.Camera.angleY > TLS.Camera.angleYMax then
|
|
TLS.Camera.angleY = TLS.Camera.angleYMax
|
|
elseif TLS.Camera.angleY < TLS.Camera.angleYMin then
|
|
TLS.Camera.angleY = TLS.Camera.angleYMin
|
|
end
|
|
local radiusMax = TLS.Camera.CalculateMaxRadius()
|
|
local offsetX = ((Cos(TLS.Camera.angleX) * Cos(TLS.Camera.angleY)) + (Cos(TLS.Camera.angleY) * Cos(TLS.Camera.angleX))) / 2 * radiusMax
|
|
local offsetY = ((Sin(TLS.Camera.angleX) * Cos(TLS.Camera.angleY)) + (Cos(TLS.Camera.angleY) * Sin(TLS.Camera.angleX))) / 2 * radiusMax
|
|
local offsetZ = ((Sin(TLS.Camera.angleY))) * radiusMax
|
|
local playerCoords = GetEntityCoords(PlayerPedId())
|
|
return vector3(playerCoords.x + offsetX, playerCoords.y + offsetY, playerCoords.z + offsetZ)
|
|
end
|
|
|
|
RegisterNUICallback('updateCamRotation', function(data)
|
|
TLS.Camera.mouseX = tonumber(data.x)
|
|
TLS.Camera.mouseY = tonumber(data.y)
|
|
TLS.Camera.updateRot = true
|
|
end)
|
|
|
|
RegisterNUICallback('updateCamZoom', function(data)
|
|
TLS.Camera.radius = TLS.Camera.radius + (tonumber(data.zoom))
|
|
TLS.Camera.updateZoom = true
|
|
end)
|
|
|
|
CreateThread(function()
|
|
while true do
|
|
Wait(0)
|
|
local letSleep = true
|
|
if TLS.Camera.active then
|
|
letSleep = false
|
|
DisableFirstPersonCamThisFrame()
|
|
if TLS.Camera.updateRot then
|
|
SetCamCoord(TLS.Camera.entity, TLS.Camera.position.x, TLS.Camera.position.y, TLS.Camera.position.z)
|
|
TLS.Camera.position = TLS.Camera.CalculatePosition(true)
|
|
TLS.Camera.updateRot = false
|
|
end
|
|
if TLS.Camera.updateZoom then
|
|
local pos = TLS.Camera.CalculatePosition(false)
|
|
SetCamCoord(TLS.Camera.entity, pos.x, pos.y, pos.z)
|
|
TLS.Camera.updateZoom = false
|
|
end
|
|
end
|
|
if letSleep then
|
|
Wait(1000)
|
|
end
|
|
end
|
|
end) |