LaptopAdding devices

Adding devices

USB devices players plug into the Laptop, a key straight in a port or a box on a cable beside it.

On this page

Devices are items players plug into the laptop's two USB ports with the third eye. Register them from the server, the same way as apps:

server/main.lua
exports.tr_laptop:registerDevice({
    id = 'wifi_adapter',
    item = 'wifi_adapter',          -- the inventory item; it leaves the inventory while plugged in
    label = 'Wi-Fi adapter',
    kind = 'stick',
    model = 'my_wifi_adapter',      -- streamed by your resource
    icon = 'fas fa-wifi',           -- the third eye's icon
    text = { plug = 'Plug in Wi-Fi adapter', unplug = 'Pull out Wi-Fi adapter' },
})

The two kinds

  • stick goes straight into a port, like a USB key. Its model's origin is the plug's shoulder, with the plug along +Y.
  • cabled is a box that sits next to the laptop on the Laptop's own USB cable, like a card reader. Its model's origin is under its middle. It also needs size (its footprint and height, in metres) and cable (where the cable leaves it, in its own space; the cable goes off along its -X), and can have text.place (the prompt while putting it down).
server/main.lua
exports.tr_laptop:registerDevice({
    id = 'card_reader', item = 'card_reader', label = 'Card reader', kind = 'cabled',
    model = 'my_card_reader',
    size = vector3(0.20, 0.05, 0.06),
    cable = vector3(-0.10, 0.0, 0.012),
    text = { plug = 'Set up card reader', unplug = 'Pack up card reader', place = 'Put the card reader down' },
})

The player puts a cabled device down the same see-through way as the laptop, within the cable's reach, then plugs it in during a short close-up. The cable lies along the ground it's on. Pulling a device out gives the item back with its metadata.

Apps that list a device in devices only run while it's plugged in, and get onUnplug when it's pulled out.

Options on the box

exports.tr_laptop:addOption(option, 'card_reader') on the client puts your own third eye options on a cabled device's box. See Client exports.

Was this page helpful?

Still stuck? Open a ticket on Discord.Privacy