SAFScriptsDocs

Exports & events

On this page

Server exports

Lua
exports['saf-tv']:GetPlacedTvs()            -- every placed TV
exports['saf-tv']:RemovePlacedTv(uid, src)  -- remove one, optionally giving the item back to src

GetPlacedTvs returns a list with one entry per TV:

FieldWhat it is
uidId of the placed TV
itemItem it was placed from, e.g. 'tv_large'
modelProp model
coordsvector3 position
headingHeading in degrees
ownerCharacter id of the player who placed it
ownerNameTheir character name

RemovePlacedTv returns true when the TV existed and was removed. Leave src out to remove it without giving the item back.

Example: clear TVs from a property

Lua
-- in your own server resource
local function clearTvsNear(center, radius)
    for _, tv in ipairs(exports['saf-tv']:GetPlacedTvs()) do
        if #(tv.coords - center) < radius then
            exports['saf-tv']:RemovePlacedTv(tv.uid)
        end
    end
end

Item export

ox_inventory uses an item export to start placing a TV. The lines in install/ox_inventory.txt already set it:

Lua
['tv_large'] = {
    label = 'Big Screen TV',
    weight = 15000,
    stack = false,
    close = true,
    server = { export = 'saf-tv.useTvItem' },
},

Other inventories go through the framework's usable items, handled by Bridge.RegisterUsableItem.

SAF Scripts by San Andreas' Finest StoreDiscordsupprot@safrp.org

Not affiliated with or endorsed by Rockstar Games, Take-Two Interactive or Cfx.re.