Skip to content

Commit

Permalink
feat: new example template
Browse files Browse the repository at this point in the history
  • Loading branch information
swkeep committed Nov 15, 2024
1 parent 3f01b18 commit e568396
Show file tree
Hide file tree
Showing 24 changed files with 2,566 additions and 1,432 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ interactionDUI/dui
interactionDUI/dui_source/node_modules
interactionDUI/watch.cjs
interactionMenu/.vscode
interactionMenu/watch.cjs
interactionMenu/watch.cjs
interactionMenu/.editorconfig
5 changes: 5 additions & 0 deletions interactionMenu/lua/client/drawIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ function UpdateNearbyObjects()
getNearbyObjects(isActive, currentMenu, playerPosition)
end

function CleanNearbyObjects()
nearby_objects = {}
nearby_objects_limited = {}
end

local function StartSpriteThread()
if isSpriteThreadRunning then return end
isSpriteThreadRunning = true
Expand Down
9 changes: 9 additions & 0 deletions interactionMenu/lua/client/extends/nested.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-- _
-- | |
-- _____ _| | _____ ___ _ __
-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \
-- \__ \\ V V /| < __/ __/ |_) |
-- |___/ \_/\_/ |_|\_\___|\___| .__/
-- | |
-- |_|
-- https://github.com/swkeep
local __export = exports['interactionMenu']
local refresh = __export.refresh
local NestedMenuBuilder = {}
Expand Down
9 changes: 9 additions & 0 deletions interactionMenu/lua/client/extends/pagination.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-- _
-- | |
-- _____ _| | _____ ___ _ __
-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \
-- \__ \\ V V /| < __/ __/ |_) |
-- |___/ \_/\_/ |_|\_\___|\___| .__/
-- | |
-- |_|
-- https://github.com/swkeep
local __export = exports['interactionMenu']
local refresh = __export.refresh
local PaginationBuilder = {}
Expand Down
22 changes: 21 additions & 1 deletion interactionMenu/lua/client/garbageCollector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ function Container.remove(id)
EntityDetector.unwatch(menuRef.entity.handle)
end

if menuRef.type == "bones" or menuRef.type == "entities" or menuRef.type == "zones" or menuRef.type == 'peds' then
if menuRef.type == 'bones' then
for index, value in ipairs(Container.indexes.globals['bones'][menuRef.bone]) do
if value == id then
table.remove(Container.indexes.globals['bones'][menuRef.bone], index)
CleanNearbyObjects()
break
end
end
else
for index, value in pairs(Container.indexes.globals[menuRef.type]) do
if value == id then
table.remove(Container.indexes.globals[menuRef.type], index)
CleanNearbyObjects()
break
end
end
end
end

menuRef.flags.deleted = true
menuRef.deletedAt = GetGameTimer() / 1000
Container.total = Container.total - 1
Expand All @@ -86,7 +106,7 @@ CreateThread(function()
Wait(COLLECTOR_CONFIG.INTERVAL)

local currentTime = GetGameTimer() / 1000
local chunkSize = 5000
local chunkSize = 500
local processed = 0

for key, value in pairs(Container.data) do
Expand Down
210 changes: 210 additions & 0 deletions interactionMenu/lua/examples/chairs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
-- _
-- | |
-- _____ _| | _____ ___ _ __
-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \
-- \__ \\ V V /| < __/ __/ |_) |
-- |___/ \_/\_/ |_|\_\___|\___| .__/
-- | |
-- |_|
-- https://github.com/swkeep
if not DEVMODE then return end
local positions = {
vector4(794.00, -2991.52, -70.0, 0),
vector4(796.50, -2991.52, -70.0, 0),
vector4(799.00, -2991.52, -70.0, 0),
vector4(801.50, -2991.52, -70.0, 0),
vector4(804.00, -2991.52, -70.0, 0),
vector4(806.50, -2991.52, -70.0, 0),
vector4(809.00, -2991.52, -70.0, 0),

vector4(794.00, -2997.10, -70.00, 180),
vector4(796.50, -2997.10, -70.00, 180),
vector4(799.00, -2997.10, -70.00, 180),
vector4(801.50, -2997.10, -70.00, 180),
vector4(804.00, -2997.10, -70.00, 180),
vector4(806.50, -2997.10, -70.00, 180),
vector4(809.00, -2997.10, -70.00, 180),

vector4(794.54, -3002.94, -70.00, 0),
vector4(798.54, -3002.94, -70.00, 0),
vector4(801.04, -3002.94, -70.00, 0),
vector4(803.54, -3002.94, -70.00, 0),
vector4(806.04, -3002.94, -70.00, 0),
vector4(808.54, -3002.94, -70.00, 0),

vector4(794.00, -3008.70, -70.00, 180),
vector4(796.50, -3008.70, -70.00, 180),
vector4(799.00, -3008.70, -70.00, 180),
vector4(801.50, -3008.70, -70.00, 180),
vector4(804.00, -3008.70, -70.00, 180),
vector4(806.50, -3008.70, -70.00, 180),
vector4(809.00, -3008.70, -70.00, 180),
}

local chairs = {
"prop_table_02_chr",
"prop_table_03_chr",
"prop_table_03b_chr",
"prop_table_04_chr",
"apa_mp_h_stn_chairarm_01",
"apa_mp_h_stn_chairarm_02",
"apa_mp_h_stn_chairarm_03",
"apa_mp_h_stn_chairarm_11",
"apa_mp_h_stn_chairarm_12",
"apa_mp_h_stn_chairarm_13",
"apa_mp_h_stn_chairarm_23",
"apa_mp_h_stn_chairarm_24",
"apa_mp_h_stn_chairarm_25",
"apa_mp_h_yacht_strip_chair_01",
"bkr_prop_biker_boardchair01",
"bkr_prop_biker_chair_01",
"bkr_prop_clubhouse_armchair_01a",
"bkr_prop_clubhouse_chair_01",
"bkr_prop_clubhouse_offchair_01a",
"bkr_prop_weed_chair_01a",
"ex_mp_h_din_chair_04",
"ex_mp_h_din_chair_08",
"ex_mp_h_din_chair_09",
"ex_mp_h_din_chair_12",
"ex_prop_offchair_exec_01",
"ex_prop_offchair_exec_02",
"ex_prop_offchair_exec_03",
"ex_prop_offchair_exec_04",
"gr_prop_gr_chair02_ped",
"gr_prop_gr_offchair_01a",
"gr_prop_highendchair_gr_01a",
"hei_heist_din_chair_01",
"hei_heist_stn_chairarm_06",
"hei_prop_hei_skid_chair",
"imp_prop_impexp_offchair_01a",
"p_armchair_01_s",
"p_clb_officechair_s",
"p_ilev_p_easychair_s",
"p_soloffchair_s",
"p_yacht_chair_01_s",
"prop_armchair_01",
"prop_chateau_chair_01",
"prop_clown_chair",
"prop_cs_office_chair",
"prop_gc_chair02",
"prop_old_deck_chair",
"prop_old_wood_chair",
"prop_old_wood_chair_lod",
"prop_rock_chair_01",
"prop_skid_chair_01",
"prop_skid_chair_02",
"prop_skid_chair_03",
"prop_sol_chair",
"prop_wheelchair_01",
}
local menus = {}
local spawned_models = {}
local entities = {}
local sitting = false
local current_chair = nil

local function stand_up()
if not sitting then return end

local playerPed = PlayerPedId()
ClearPedTasks(playerPed)
TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_STAND_IDLE", 0, true)
FreezeEntityPosition(current_chair, true)
Wait(500)
sitting = false
current_chair = nil
end

local function sit(entity)
if sitting then return end
sitting = true
current_chair = entity
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local entityCoords = GetEntityCoords(entity)
local heading = GetEntityHeading(entity) + 180.0

FreezeEntityPosition(entity, true)
TaskStartScenarioAtPosition(playerPed, "PROP_HUMAN_SEAT_BENCH", entityCoords.x, entityCoords.y, playerCoords.z - 0.5, heading, 0, true, true)
end

local function DrawText3D(x, y, z, text)
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
if not onScreen then return end
local camCoords = GetGameplayCamCoord()
local scale = 150 / (GetGameplayCamFov() * #(camCoords - vec3(x, y, z)))
SetTextScale(scale or 0.35, scale or 0.35)
SetTextFont(4)
SetTextEntry("STRING")
SetTextCentre(true)

AddTextComponentString(text)
DrawText(_x, _y)
end

local function init()
for _, value in ipairs(positions) do
local index = #entities + 1
local model = chairs[math.random(1, #chairs)]
entities[index] = Util.spawnObject(joaat(model), value)
spawned_models[index] = { model, value }

menus[#menus + 1] = exports['interactionMenu']:Create {
tracker = 'boundingBox',
entity = entities[index],
dimensions = {
vec3(-1, -1.5, -0.3),
vec3(1, 1.5, 2)
},
options = {
{
label = 'Sit',
action = function()
sit(entities[index])
end,
canInteract = function()
return not sitting
end
},
{
label = 'Stand Up',
action = stand_up,
canInteract = function()
return sitting
end
},
}
}
Wait(30)
end

CreateThread(function()
while #spawned_models > 0 do
for _, value in ipairs(spawned_models) do
DrawText3D(value[2].x, value[2].y, value[2].z + 0.5, value[1])
end
Wait(0)
end
end)
end

local function cleanup()
stand_up()

for _, menu_id in ipairs(menus) do
exports['interactionMenu']:remove(menu_id)
end
for _, entity in ipairs(entities) do
if DoesEntityExist(entity) then
DeleteEntity(entity)
end
end

entities = {}
menus = {}
spawned_models = {}
end

CreateThread(function()
InternalRegisterTest(init, cleanup, "chair_test", "Lots of Chairs", "fa-solid fa-chair")
end)
21 changes: 21 additions & 0 deletions interactionMenu/lua/examples/empty.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- _
-- | |
-- _____ _| | _____ ___ _ __
-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \
-- \__ \\ V V /| < __/ __/ |_) |
-- |___/ \_/\_/ |_|\_\___|\___| .__/
-- | |
-- |_|
-- https://github.com/swkeep

local function init()

end

local function cleanup()

end

CreateThread(function()
InternalRegisterTest(init, cleanup, "1", "! Empty", "fa-solid fa-warehouse")
end)
Loading

0 comments on commit e568396

Please sign in to comment.