refactor(resource/interface): keymapping and multi-prop support

Prop data should support a single table or an array for multiple
props.
This commit is contained in:
Linden
2022-04-14 13:47:56 +00:00
parent aaab5798c0
commit 9a3b17029f

View File

@@ -9,6 +9,14 @@ local disableKeys = {
combat = {25} combat = {25}
} }
local function createProp(prop)
lib.requestModel(prop.model)
local coords = GetEntityCoords(cache.ped)
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, true, true, true)
AttachEntityToEntity(object, cache.ped, GetPedBoneIndex(cache.ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 0, true)
return object
end
local function startProgress(data) local function startProgress(data)
progress = data progress = data
@@ -24,16 +32,15 @@ local function startProgress(data)
end end
if data.prop then if data.prop then
for i = 1, #data.prop do if data.prop.model then
local prop = data.prop[i] data.prop1 = createProp(data.prop)
else
for i = 1, #data.prop do
local prop = data.prop[i]
if prop then if prop then
lib.requestModel(prop.model) data['prop'..i] = createProp(prop)
end
local coords = GetEntityCoords(cache.ped)
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, true, true, true)
AttachEntityToEntity(object, cache.ped, GetPedBoneIndex(cache.ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 0, true)
data['prop'..i] = object
end end
end end
end end
@@ -78,7 +85,8 @@ local function startProgress(data)
end end
if data.prop then if data.prop then
for i = 1, #data.prop do local n = #data.prop
for i = 1, n > 0 and n or 1 do
local prop = data['prop'..i] local prop = data['prop'..i]
if prop then if prop then
@@ -154,3 +162,5 @@ end)
RegisterCommand('cancelprogress', function() RegisterCommand('cancelprogress', function()
if progress?.canCancel then progress = false end if progress?.canCancel then progress = false end
end) end)
RegisterKeyMapping('cancelprogress', 'Cancel current progress bar', 'keyboard', 'x')