97 lines
2.7 KiB
Lua
97 lines
2.7 KiB
Lua
local activeEscapes = {}
|
|
local toiletModel = joaat('prompt_prison_toilet_withscrew')
|
|
|
|
local function getEscapeBySource(src)
|
|
return activeEscapes[src]
|
|
end
|
|
|
|
local function cleanupEscape(src)
|
|
local escapeData = activeEscapes[src]
|
|
if not escapeData then return end
|
|
|
|
if escapeData.entity and DoesEntityExist(escapeData.entity) then
|
|
DeleteEntity(escapeData.entity)
|
|
end
|
|
|
|
TriggerClientEvent('prompt_prison_escape:toggleToiletVisibility', -1, true, escapeData.coords, escapeData.id)
|
|
|
|
activeEscapes[src] = nil
|
|
end
|
|
|
|
lib.callback.register('prompt_prison_escape:createToiletObject', function(source, coords)
|
|
if activeEscapes[source] then
|
|
cleanupEscape(source)
|
|
end
|
|
|
|
local escapeId = 'prison_toilet_' .. source
|
|
|
|
local entity = CreateObjectNoOffset(toiletModel, coords.x, coords.y, coords.z, true, true, false)
|
|
|
|
local timeout = 0
|
|
while not DoesEntityExist(entity) and timeout < 100 do
|
|
timeout = timeout + 1
|
|
Wait(10)
|
|
end
|
|
|
|
if not DoesEntityExist(entity) then
|
|
return nil
|
|
end
|
|
|
|
SetEntityHeading(entity, coords.w)
|
|
SetEntityRotation(entity, 0.0, 0.0, coords.w, 2, true)
|
|
FreezeEntityPosition(entity, true)
|
|
|
|
activeEscapes[source] = {
|
|
entity = entity,
|
|
coords = vec3(coords.x, coords.y, coords.z),
|
|
heading = coords.w,
|
|
id = escapeId,
|
|
unscrewed = {}
|
|
}
|
|
|
|
TriggerClientEvent('prompt_prison_escape:toggleToiletVisibility', -1, false, vec3(coords.x, coords.y, coords.z), escapeId)
|
|
|
|
return NetworkGetNetworkIdFromEntity(entity)
|
|
end)
|
|
|
|
lib.callback.register('prompt_prison_escape:getUnscrewedState', function(source)
|
|
local escape = getEscapeBySource(source)
|
|
if not escape then return {} end
|
|
return escape.unscrewed or {}
|
|
end)
|
|
|
|
lib.callback.register('prompt_prison_escape:unscrewProgress', function(source, screwIndex)
|
|
local escape = getEscapeBySource(source)
|
|
if not escape then return false end
|
|
|
|
table.insert(escape.unscrewed, screwIndex)
|
|
return true
|
|
end)
|
|
|
|
lib.callback.register('prompt_prison_escape:stopSitting', function(source)
|
|
cleanupEscape(source)
|
|
return true
|
|
end)
|
|
|
|
lib.callback.register('prompt_prison_escape:completeEscape', function(source)
|
|
local escape = getEscapeBySource(source)
|
|
if not escape then return false end
|
|
|
|
local ped = GetPlayerPed(source)
|
|
local heading = escape.heading
|
|
|
|
local distance = 2.5
|
|
local exitX = escape.coords.x - (math.sin(math.rad(heading)) * distance)
|
|
local exitY = escape.coords.y + (math.cos(math.rad(heading)) * distance)
|
|
|
|
SetEntityCoords(ped, exitX, exitY, escape.coords.z - 1.0, false, false, false, false)
|
|
|
|
cleanupEscape(source)
|
|
|
|
return true
|
|
end)
|
|
|
|
AddEventHandler('playerDropped', function()
|
|
cleanupEscape(source)
|
|
end)
|