SDK örnekleri
Sunasty SDK ile sık yapılan entegrasyonlar için kopyala-yapıştır örnekler.
Son güncelleme: 26 Eylül 2026
Aşağıdaki örneklerin hepsi sunucu tarafı (server.lua) içindir ve script'inin fxmanifest.lua dosyasında dependency 'sunasty-bridge' olduğunu varsayar.
Meslek bonusları (liste + anahtar–değer)#
lua
local SDK = exports['sunasty-bridge']
local cfg = {}
CreateThread(function()
SDK:registerModule({
name = 'Maaş Bonusları',
icon = 'briefcase',
settings = {
{ key = 'bonus_jobs', type = 'list', label = 'Bonus alan meslekler', default = { 'police', 'ambulance' } },
{ key = 'rates', type = 'keyvalue', label = 'Meslek başına çarpan', default = { { key = 'police', value = '1.5' } } },
},
})
cfg = SDK:getConfig()
end)
AddEventHandler('sunasty:configChanged:' .. GetCurrentResourceName(), function(c) cfg = c end)
local function rateFor(job)
for _, row in ipairs(cfg.rates or {}) do
if row.key == job then return tonumber(row.value) or 1 end
end
return 1
endYetkiye bağlı işlem#
Sadece Oyuncu parası iznine sahip ekip üyeleri çalıştırabilir:
lua
actions = {
{
key = 'refund',
label = 'Oyuncuya iade yap',
permission = 'players.money',
confirm = true,
params = {
{ key = 'citizenid', type = 'text', label = 'Karakter ID', required = true },
{ key = 'amount', type = 'number', label = 'Tutar', min = 1, max = 1000000 },
},
},
}
SDK:onAction('refund', function(p, actor)
local ok = myRefund(p.citizenid, p.amount)
if not ok then return { ok = false, message = 'Karakter bulunamadı' } end
SDK:log('iade', actor.name .. ' iade yaptı', { citizenid = p.citizenid, amount = p.amount })
return ('%s kişisine %d$ iade edildi'):format(p.citizenid, p.amount)
end)Veritabanından tablo (oxmysql)#
lua
tables = {
{ key = 'bans', label = 'Script yasakları', columns = {
{ key = 'name', label = 'Oyuncu' }, { key = 'reason', label = 'Sebep' }, { key = 'created', label = 'Tarih', type = 'date' },
} },
}
SDK:onTable('bans', function(q)
local like = '%' .. q.search .. '%'
local total = MySQL.scalar.await('SELECT COUNT(*) FROM my_bans WHERE name LIKE ?', { like })
local rows = MySQL.query.await(
'SELECT name, reason, UNIX_TIMESTAMP(created) AS created FROM my_bans WHERE name LIKE ? ORDER BY id DESC LIMIT ? OFFSET ?',
{ like, q.pageSize, (q.page - 1) * q.pageSize }
)
return { rows = rows, total = total }
end)Canlı istatistik#
lua
stats = { { key = 'online_cops', label = 'Görevdeki polis' } }
CreateThread(function()
while true do
SDK:setStat('online_cops', countCopsOnDuty())
Wait(30000)
end
end)Tam örnek#
Tüm özellikleri (ayar grupları, işlemler, tablo, istatistik, log) kullanan çalışır örnek köprü paketindedir:
sunasty-bridge/examples/sunasty-example-module/server.lua
Kendi sunucuna kopyala, server.cfg'ye ensure sunasty-example-module ekle ve panelde Eklentiler sayfasını aç.
Bu sayfa işine yaradı mı?