mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
Some changes to the esx_sit resource
This commit is contained in:
+49
-12
@@ -1,5 +1,7 @@
|
||||
ESX = nil
|
||||
local debugProps, sitting, lastPos, currentSitCoords, currentScenario = {}
|
||||
local disableControls = false
|
||||
local currentObj = nil
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
@@ -53,17 +55,23 @@ Citizen.CreateThread(function()
|
||||
wakeup()
|
||||
end
|
||||
|
||||
-- Disable controls
|
||||
if disableControls then
|
||||
DisableControlAction(1, 37, true) -- Disables INPUT_SELECT_WEAPON (TAB)
|
||||
end
|
||||
|
||||
if IsControlJustPressed(0, 38) and IsControlPressed(0, 21) and IsInputDisabled(0) and IsPedOnFoot(playerPed) then
|
||||
if sitting then
|
||||
wakeup()
|
||||
else
|
||||
local object, distance = ESX.Game.GetClosestObject(Config.Interactables)
|
||||
local object, distance = GetNearChair()
|
||||
--local object, distance = ESX.Game.GetClosestObject(GetEntityCoords(GetPlayerPed(-1)), Config.Interactables)
|
||||
|
||||
if Config.Debug then
|
||||
table.insert(debugProps, object)
|
||||
end
|
||||
|
||||
if distance < 1.5 then
|
||||
if distance and distance < 1.5 then
|
||||
local hash = GetEntityModel(object)
|
||||
|
||||
for k,v in pairs(Config.Sitable) do
|
||||
@@ -78,37 +86,66 @@ Citizen.CreateThread(function()
|
||||
end
|
||||
end)
|
||||
|
||||
function GetNearChair()
|
||||
local object, distance
|
||||
local coords = GetEntityCoords(GetPlayerPed(-1))
|
||||
for i=1, #Config.Interactables do
|
||||
object = GetClosestObjectOfType(coords, 3.0, GetHashKey(Config.Interactables[i]), false, false, false)
|
||||
distance = #(coords - GetEntityCoords(object))
|
||||
if distance < 1.6 then
|
||||
return object, distance
|
||||
end
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function wakeup()
|
||||
local playerPed = PlayerPedId()
|
||||
local pos = GetEntityCoords(GetPlayerPed(-1))
|
||||
|
||||
-- non serve specificare x, y, z perchè si alza?
|
||||
TaskStartScenarioAtPosition(playerPed, currentScenario, 0.0, 0.0, 0.0, 180.0, 2, true, false)
|
||||
while IsPedUsingScenario(GetPlayerPed(-1), currentScenario) do
|
||||
Wait(100)
|
||||
end
|
||||
ClearPedTasks(playerPed)
|
||||
|
||||
sitting = false
|
||||
|
||||
SetEntityCoords(playerPed, lastPos)
|
||||
FreezeEntityPosition(playerPed, false)
|
||||
FreezeEntityPosition(currentObj, false)
|
||||
|
||||
TriggerServerEvent('esx_sit:leavePlace', currentSitCoords)
|
||||
currentSitCoords, currentScenario = nil, nil
|
||||
sitting = false
|
||||
disableControls = false
|
||||
end
|
||||
|
||||
function sit(object, modelName, data)
|
||||
disableControls = true
|
||||
currentObj = object
|
||||
FreezeEntityPosition(object, true)
|
||||
PlaceObjectOnGroundProperly(object)
|
||||
local pos = GetEntityCoords(object)
|
||||
local objectCoords = pos.x .. pos.y .. pos.z
|
||||
local objectCoords = string.sub(pos.x, 1, 9) .. string.sub(pos.y, 1, 9) .. string.sub(pos.z, 1, 9)
|
||||
|
||||
ESX.TriggerServerCallback('esx_sit:getPlace', function(occupied)
|
||||
if occupied then
|
||||
ESX.ShowNotification('Cette place est prise...')
|
||||
ESX.ShowNotification('Questo posto è occupato')
|
||||
else
|
||||
local playerPed = PlayerPedId()
|
||||
lastPos, currentSitCoords = GetEntityCoords(playerPed), objectCoords
|
||||
|
||||
TriggerServerEvent('esx_sit:takePlace', objectCoords)
|
||||
FreezeEntityPosition(object, true)
|
||||
|
||||
|
||||
currentScenario = data.scenario
|
||||
TaskStartScenarioAtPosition(playerPed, currentScenario, pos.x, pos.y, pos.z - data.verticalOffset, GetEntityHeading(object) + 180.0, 0, true, true)
|
||||
Citizen.Wait(1000)
|
||||
TaskStartScenarioAtPosition(playerPed, currentScenario, pos.x, pos.y, pos.z - data.verticalOffset, GetEntityHeading(object) + 180.0, 0, true, false)
|
||||
|
||||
Citizen.Wait(2500)
|
||||
if GetEntitySpeed(GetPlayerPed(-1)) > 0 then
|
||||
ClearPedTasks(GetPlayerPed(-1))
|
||||
TaskStartScenarioAtPosition(playerPed, currentScenario, pos.x, pos.y, pos.z - data.verticalOffset, GetEntityHeading(object) + 180.0, 0, true, true)
|
||||
end
|
||||
|
||||
sitting = true
|
||||
end
|
||||
end)
|
||||
end, objectCoords)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user