คู่มือ ZeroDev Sound
API สำหรับนักพัฒนาของ ZeroDev Sound
ZeroDev Sound มี API แบบเปิดสำหรับ resource อื่น: อ่านว่ากำลังเล่นอะไร สั่งระบบลำโพงหรือเครื่องเสียงรถของผู้เล่นจากเมนูของคุณเอง ติดตามการเปลี่ยนแปลง วางลำโพงและอู่ติดตั้งของคุณเอง และควบคุมไฟตามเบสจริง ทุกอย่างในหน้านี้มาจาก ZeroDev Sound 3.0.5 ไฟล์ API ไม่ได้ถูก escrow คุณอ่านสัญญาได้เอง: server/devapi.lua และ client/devapi.lua
ZeroDev Sound ตรวจสอบทุกค่าที่ได้รับ และทำงานต่อได้แม้ resource ของคุณหายไป หยุด หรือเสีย ชั่วโมงเงียบ การปิดเสียงโดยตำรวจ และเพดานระดับเสียงของเจ้าของ มีผลกับทุกอย่างที่เล่น
การหา resource
resource นี้มีเครื่องหมายใน manifest คือ audio_extensions 'v1' ให้หาด้วยเครื่องหมายนี้ ไม่ใช่ด้วยชื่อโฟลเดอร์ เพราะเซิร์ฟเวอร์อาจเปลี่ยนชื่อโฟลเดอร์:
local function soundResource()
for i = 0, GetNumResources() - 1 do
local res = GetResourceByFindIndex(i)
if res and GetResourceState(res) == 'started' and GetResourceMetadata(res, 'audio_extensions', 0) == 'v1' then return res end
end
endเรียกด้วย exports[res]:... ชื่อ event ขึ้นต้นด้วยชื่อ resource: res .. ':session'
session คือสตรีมเพลงหนึ่งสตรีม: กลุ่มลำโพงที่เชื่อมกันในโลก (kind = 'speakers') หรือเครื่องเสียงของรถหนึ่งคัน (kind = 'car', คีย์ car:<plate>) เพลงถูกเลือกด้วย reference: library:<n> (เพลงใน Config.Library), file:<name> (ไฟล์ใน web/library) หรือ request:<n> (คำขอเพลงที่เจ้าของเพิ่ม)
export ฝั่งเซิร์ฟเวอร์
| Export | ค่าที่คืน |
|---|---|
GetSessions() |
ทุก session บนเซิร์ฟเวอร์ |
GetSession(key) |
session เดียว หรือ nil |
GetCarSession(vehicle) |
session ของรถคันหนึ่ง (entity หรือข้อความป้ายทะเบียน) หรือ nil |
Targets(src) |
สิ่งที่ผู้เล่นคนนี้เรียกใช้ได้ในตอนนี้: { key, kind, label, canPlay, why } |
Control(src, key, action, data) |
ok, reason |
Ready() |
เป็น true เมื่อ Sound โหลดเสร็จแล้ว |
ApiVersion() |
2 |
Control สั่งการด้วยกฎเดียวกับรีโมตของ Sound เอง: ทุกคนในรถสั่งงานเครื่องเสียงของรถได้ ระบบที่วางไว้จะทำตามเจ้าของและการตั้งค่าปาร์ตี้หรือสาธารณะ และผู้เล่นต้องอยู่ในระยะ ส่ง src = 0 เพื่อสั่งด้วยสิทธิ์ของสคริปต์คุณเอง หลังจากสคริปต์ของคุณตัดสินแล้วว่าใครทำได้
| การกระทำ | ข้อมูล |
|---|---|
play |
{ text = reference } (ไม่มี text: เล่นต่อ) |
queue |
{ text = reference } |
resume, pause, next, previous, stop |
ไม่มี |
volume |
{ value = 0.0 - 1.0 } |
seek |
{ at = seconds } |
mode |
{ value = 'studio' } หรือ bass, club, vocal, concert, night, chipeo |
eq |
{ low, mid, high } หน่วย dB ตั้งแต่ -12 ถึง 12 |
repeatMode |
{ value = 'off' } หรือ one, all |
เมื่อ ok เป็น false ค่า reason จะเป็นหนึ่งใน no_session, bad_action, no_player, not_inside, out_of_range, not_allowed, mixer_alone, no_text, catalogue_only หรือ error
ตัวอย่าง: ลำโพงคลับเล่นเพลงเฮาส์เมื่อ DJ เข้างาน
RegisterNetEvent('myclub:clockIn', function()
local src = source
for _, t in ipairs(exports[res]:Targets(src)) do
if t.kind == 'speakers' then
exports[res]:Control(src, t.key, 'play', { text = 'library:3' })
exports[res]:Control(src, t.key, 'mode', { value = 'club' })
end
end
end)ลำโพงแบบตั้งตายตัวและอู่ติดตั้ง
สคริปต์ร้านค้า คลับ หรือโรงรถสามารถวางลำโพงของตัวเองและอู่ติดตั้งไว้ในอาคารได้ ลำโพงเหล่านี้ไม่มีเจ้าของและไม่มีไอเทม ไม่ถูกบันทึก และหายไปเมื่อ resource ของคุณหยุด ผู้เล่นย้ายหรือเก็บไม่ได้ ส่วนตำรวจยังปิดเสียงได้
local id, key = exports[res]:AddFixedSpeaker({
id = 'radio_1', -- yours to name; adding the same id again moves it
item = 'zds_room_ceiling', -- any placed Sound speaker item
coords = vector3(x, y, z), heading = 90.0,
pitch = -90.0, -- on a ceiling, grille down; 0 on a floor or wall
label = 'Store radio',
group = 'store', -- same group = one system
})
exports[res]:RemoveFixedSpeaker('radio_1')
exports[res]:GetFixedSpeakers() -- { { id, speaker, key } } of your resource
exports[res]:AddBay({ id = 'garage', label = 'Garage audio bay', coords = vector3(x, y, z), radius = 6.0, blip = true })
exports[res]:RemoveBay('garage') -- up to 8 bays per resource, radius 3 to 15 mเพิ่มตอน resource ของคุณเริ่มทำงาน และอีกครั้งที่ event <res>:ready เผื่อ Sound เริ่มหลังคุณ
event ฝั่งเซิร์ฟเวอร์
AddEventHandler(res .. ':session', function(key, session) end) -- any change: song, pause, volume, mode, queue
AddEventHandler(res .. ':songStarted', function(session) end) -- a different song started
AddEventHandler(res .. ':sessionRemoved', function(key) end) -- speakers packed up, a car session ended
AddEventHandler(res .. ':ready', function() end) -- Sound started and loadedevent เหล่านี้เป็น event ภายในเซิร์ฟเวอร์ ไม่เคยส่งมาจากไคลเอนต์ ไคลเอนต์จึงปลอมไม่ได้
export ฝั่งไคลเอนต์ (อ่านอย่างเดียว)
| Export | ค่าที่คืน |
|---|---|
GetSessions() |
session ที่ไคลเอนต์นี้รู้จัก: ที่อยู่ใกล้และของตัวเอง |
GetCarSession(vehicle) |
session ของรถ หรือ nil |
GetBass(key) |
0.0 ถึง 1.0: เบสของเพลงจริงในเฟรมนี้ เป็น 0 เมื่อเงียบ |
CarAudioState(vehicle) |
สถานะของเครื่องเล่นหน้ารถ สำหรับหน้าจอในรถ |
ตัวอย่าง: ไฟใต้ท้องรถที่กะพริบตามซับของรถ
CreateThread(function()
while true do
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
local s = veh ~= 0 and exports[res]:GetCarSession(veh)
if s and s.title and not s.paused then
SetVehicleNeonLightsColour(veh, 255, math.floor(40 + 200 * exports[res]:GetBass(s.key)), 255)
Wait(0)
else
Wait(500)
end
end
end)ตัวอย่าง config
การตั้งค่าอยู่ใน zerodev-sound/config/config.lua และทุกค่าเปลี่ยนได้ในเกมที่ /soundadmin
Config.Framework = 'auto' -- or 'esx', 'qb', 'qbox', 'standalone'
Config.Inventory = 'auto' -- or 'ox', 'qb', 'qs', 'codem', 'core', 'origen', 'tgiann', 'esx', 'none'
Config.MaxPlacedPerPlayer = 8
Config.QuietHours = { enabled = true, from = 23, to = 7, maxVolume = 0.35 }กฎสำหรับการเชื่อมต่อ
- อย่าแก้ไฟล์ของ ZeroDev Sound ให้ใช้ API แทน ไฟล์ที่ผ่าน escrow ถ้าถูกแก้ resource จะโหลดไม่ขึ้น
- ส่ง
sourceตัวจริงให้Controlหรือตรวจสิทธิ์เองก่อนใช้src = 0 - อ่าน
GetBassไม่เกินหนึ่งครั้งต่อเฟรม และพักการทำงานเมื่อไม่มีเพลงเล่น - API มีเวอร์ชัน (
audio_extensions 'v1',ApiVersion()2) การเปลี่ยนแปลงที่ทำให้ใช้งานร่วมกันไม่ได้จะได้เวอร์ชันใหม่และมีบรรทัดบันทึกใน changelog
คำถามที่พบบ่อย
หา ZeroDev Sound จากสคริปต์ของฉันอย่างไร
หา resource ที่ manifest มี audio_extensions 'v1' ตามตัวอย่างแรก บางเซิร์ฟเวอร์อาจตั้งชื่อโฟลเดอร์ต่างออกไป
สคริปต์ของฉันเล่นเพลงบนลำโพงของผู้เล่นได้หรือไม่
ได้ ด้วย Control(src, key, 'play', { text = 'library:1' }) ใช้กฎเดียวกับรีโมตของ Sound เอง: ผู้เล่นต้องมีสิทธิ์สั่งงานระบบนั้นและอยู่ในระยะ
ไฟหรือ prop ขยับตามเพลงได้หรือไม่
ได้ export ฝั่งไคลเอนต์ GetBass(key) ให้ค่าเบสของเพลงที่กำลังเล่นทุกเฟรม ตั้งแต่ 0 ถึง 1