-- ============================================================================ -- M-Addon :: tablet NPC(s). -- Spawned once on start, never in a loop. -- ============================================================================ local peds = {} local blips = {} local function createBlip(coords, data) if not data or not data.enabled then return end local blip = AddBlipForCoord(coords.x, coords.y, coords.z) SetBlipSprite(blip, data.sprite) SetBlipColour(blip, data.color or data.colour or 5) SetBlipScale(blip, data.scale) SetBlipAsShortRange(blip, true) BeginTextCommandSetBlipName('STRING') AddTextComponentSubstringPlayerName(data.label) -- Slovenian, from config EndTextCommandSetBlipName(blip) blips[#blips + 1] = blip end local function spawnNPC(data, i) local hash = joaat(data.model) if not IsModelValid(hash) then return print(('[M-Addon] CONFIG ERROR: ped model "%s" does not exist.'):format(data.model)) end lib.requestModel(hash, 10000) local ped = CreatePed(4, hash, data.coords.x, data.coords.y, data.coords.z - 1.0, data.coords.w, false, false) SetEntityAsMissionEntity(ped, true, true) SetBlockingOfNonTemporaryEvents(ped, true) SetPedDiesWhenInjured(ped, false) SetPedCanRagdollFromPlayerImpact(ped, false) if data.invincible then SetEntityInvincible(ped, true) end if data.frozen then FreezeEntityPosition(ped, true) end if data.scenario then TaskStartScenarioInPlace(ped, data.scenario, 0, true) end SetModelAsNoLongerNeeded(hash) exports.ox_target:addLocalEntity(ped, { { name = 'maddon_tablet_' .. i, icon = 'fa-solid fa-tablet-screen-button', label = locale('target_npc'), distance = 2.0, onSelect = function() OpenTablet() end } }) peds[#peds + 1] = ped createBlip(data.coords, data.blip) end AddEventHandler('onClientResourceStart', function(resourceName) if resourceName ~= GetCurrentResourceName() then return end while not ESX.IsPlayerLoaded() do Wait(500) end for i, data in ipairs(Config.NPCs) do spawnNPC(data, i) end end) AddEventHandler('onResourceStop', function(resourceName) if resourceName ~= GetCurrentResourceName() then return end for _, ped in ipairs(peds) do if DoesEntityExist(ped) then exports.ox_target:removeLocalEntity(ped) DeletePed(ped) end end for _, blip in ipairs(blips) do if DoesBlipExist(blip) then RemoveBlip(blip) end end end)