Exports
Server exports of Yecoyz Jukebox for other resources.
Get yecoyz_jukeboxOther resources can play and stop music, read what a jukebox is playing and replace how song prices are charged. All exports are server-side. Call them with exports['yecoyz_jukebox']:name(...).
Server exports
| Export | Arguments | Returns | Description |
|---|---|---|---|
play |
id, song |
true or false |
Plays a song right away, skipping the queue. song is an index in the configured songs, or a table { url, title, artist }. |
stop |
id |
true or false |
Stops the jukebox and clears its queue. |
getState |
id |
State table, or nil |
What the jukebox is playing. See state format. |
setPaymentAdapter |
fn(playerId, amount) |
Nothing | Replaces how song prices are charged. Return true from fn when the player paid. |
lua
-- server: start the first configured song at a jukebox from config locations
exports['yecoyz_jukebox']:play('loc_vanilla', 1)
-- server: play a hosted file
exports['yecoyz_jukebox']:play('loc_vanilla', { url = 'https://example.com/song.mp3', title = 'Opening night', artist = 'DJ' })lua
-- server: charge songs from the bank instead of cash (in a resource that loads @yecoyz_core/import.lua)
exports['yecoyz_jukebox']:setPaymentAdapter(function(playerId, amount)
return Core.RemoveMoney(playerId, amount, 'bank', 'jukebox') == true
end)Jukebox ids
| Kind | Id | Example |
|---|---|---|
Config locations |
loc_<id> |
loc_vanilla |
| Placed with the editor | p… |
Saved in data/placed.json |
| Map jukeboxes | w<x>_<y>_<z> (position in decimetres) |
w19880_30519_462 |
NoteA map jukebox is registered the first time a player uses it, so
getStatereturnsnilfor it until then.
State format
| Field | Type | Description |
|---|---|---|
id |
String | The jukebox id. |
label |
String or nil |
Its name. |
kind |
String | 'location', 'placed' or 'world'. |
coords |
vector3 | Position. |
volume |
Number | Jukebox volume, 0–1. |
paused |
Boolean | Whether it's paused. |
elapsed |
Number | Milliseconds into the current song. |
current |
Table or nil |
{ title, artist, duration, by, index } of the song playing. by is the player name. |
queue |
List | { title, artist, by, index } for each song waiting. |
TipCheck that
yecoyz_jukeboxis started before you call its exports, for example withGetResourceState('yecoyz_jukebox') == 'started'.