-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
653 lines (533 loc) · 27.9 KB
/
Copy pathserver.lua
File metadata and controls
653 lines (533 loc) · 27.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
local QBCore = exports['qb-core']:GetCoreObject()
-- Multi-source seed: wall time + high-res clock tick, then burn first 3 values
math.randomseed(os.time() + math.floor(os.clock() * 1e6))
math.random(); math.random(); math.random()
-- ─────────────────────────────────────────────────────────────────────────────
-- State
-- ─────────────────────────────────────────────────────────────────────────────
local activeRaffle = nil -- { name, prize, prizeType, prizeData, startedBy, startTime }
local enteredPlayers = {} -- [src] = playerName
local raffleHistory = {} -- array of completed raffle records
local activePresets = nil -- live-editable clone of Config.PresetPrizes
local cachedVehicleList = nil -- built once from QBCore.Shared.Vehicles
local cachedItemList = nil -- built once from ox_inventory:Items()
local winnerCooldowns = {} -- [citizenid] = rafflesRemaining (decremented each draw)
-- ─────────────────────────────────────────────────────────────────────────────
-- Helpers
-- ─────────────────────────────────────────────────────────────────────────────
local function HasAdminPermission(src)
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return false end
for _, group in ipairs(Config.AdminGroups) do
if QBCore.Functions.HasPermission(src, group) then return true end
end
return false
end
local function GetOnlinePlayers()
local players = {}
for _, src in ipairs(GetPlayers()) do
local id = tonumber(src)
if id then table.insert(players, id) end
end
return players
end
local function NotifyPlayer(src, msg, msgType)
TriggerClientEvent('dynamic-raffle:notify', src, msg, msgType or 'inform')
end
local function NotifyAll(msg, msgType)
TriggerClientEvent('dynamic-raffle:notify', -1, msg, msgType or 'inform')
end
local function SafeDate()
local t = os.date('*t')
local h = t.hour % 12
if h == 0 then h = 12 end
local ap = t.hour >= 12 and 'PM' or 'AM'
return string.format('%02d/%02d/%04d %02d:%02d %s', t.month, t.day, t.year, h, t.min, ap)
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Preset helpers
-- ─────────────────────────────────────────────────────────────────────────────
local function GetPresets()
if not activePresets then
activePresets = {}
for _, v in ipairs(Config.PresetPrizes) do
table.insert(activePresets, v)
end
end
return activePresets
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Vehicle list (built once from QBCore.Shared.Vehicles, then cached)
-- ─────────────────────────────────────────────────────────────────────────────
local function GetVehicleList()
if cachedVehicleList then return cachedVehicleList end
local list = {}
for model, data in pairs(QBCore.Shared.Vehicles) do
local brand = (data.brand and data.brand ~= '') and (data.brand .. ' ') or ''
local name = data.name or model
table.insert(list, { model = model, label = brand .. name })
end
table.sort(list, function(a, b) return a.label < b.label end)
cachedVehicleList = list
return list
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Item list (built once from ox_inventory, then cached)
-- ─────────────────────────────────────────────────────────────────────────────
local function GetItemList()
if cachedItemList then return cachedItemList end
local ok, items = pcall(function() return exports.ox_inventory:Items() end)
if not ok or not items then return {} end
local list = {}
for name, data in pairs(items) do
if type(data) == 'table' and data.label then
table.insert(list, { name = name, label = data.label })
end
end
table.sort(list, function(a, b) return a.label < b.label end)
cachedItemList = list
return list
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Human-readable prize label (stored on raffle + shown in notifications)
-- ─────────────────────────────────────────────────────────────────────────────
local function BuildPrizeLabel(prizeType, prizeData)
if prizeType == 'vehicle' then
local veh = QBCore.Shared.Vehicles[prizeData.model]
local brand = (veh and veh.brand and veh.brand ~= '') and (veh.brand .. ' ') or ''
local name = (veh and veh.name) or prizeData.model
return '🚗 ' .. brand .. name
elseif prizeType == 'cash' then
local acct = (prizeData.account == 'cash') and 'Cash' or 'Bank'
return string.format('💰 $%s (%s)', tostring(prizeData.amount), acct)
elseif prizeType == 'item' then
return string.format('📦 %s x%d', prizeData.name, prizeData.count or 1)
else -- 'custom'
return prizeData.description or '??? Mystery Prize'
end
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Prize delivery — called after winner is drawn
-- ─────────────────────────────────────────────────────────────────────────────
local function DeliverPrize(winnerSrc, prizeType, prizeData)
local Player = QBCore.Functions.GetPlayer(winnerSrc)
if not Player then
print('[dynamic-raffle] ERROR: Could not get player object for winner src=' .. tostring(winnerSrc))
return
end
-- ── Cash ────────────────────────────────────────────────────────────────
if prizeType == 'cash' then
local account = prizeData.account or Config.CashAccount
local amount = math.floor(tonumber(prizeData.amount) or 0)
Player.Functions.AddMoney(account, amount, 'raffle-prize')
NotifyPlayer(winnerSrc,
string.format(
'💰 $%d has been added to your %s! Congrats!',
amount,
account == 'bank' and 'bank account' or 'cash'
),
'success'
)
print(string.format('[dynamic-raffle] Delivered $%d (%s) to %s', amount, account, GetPlayerName(winnerSrc)))
-- ── Vehicle ─────────────────────────────────────────────────────────────
elseif prizeType == 'vehicle' then
local model = prizeData.model
local citizenid = Player.PlayerData.citizenid
local plate = QBCore.Functions.GeneratePlate()
local garage = Config.DefaultGarage
-- Insert directly into player_vehicles (same pattern as qb-garage)
MySQL.insert(
[[INSERT INTO player_vehicles
(citizenid, vehicle, hash, mods, plate, garage, fuel, engine, body, in_garage, garage_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]],
{
citizenid,
model,
GetHashKey(model),
'{}', -- empty mods, stock vehicle
plate,
garage,
100, -- fuel
1000, -- engine health
1000, -- body health
1, -- in_garage = true
garage, -- garage_id for jg-advancedgarages
}
)
-- Hand keys to winner so they can see it in qb-vehiclekeys
TriggerClientEvent('qb-vehiclekeys:client:AddKeys', winnerSrc, plate)
local veh = QBCore.Shared.Vehicles[model]
local brand = (veh and veh.brand and veh.brand ~= '') and (veh.brand .. ' ') or ''
local name = (veh and veh.name) or model
NotifyPlayer(winnerSrc,
string.format(
'🚗 Your prize vehicle %s%s has been added to %s garage!\n🔑 Plate: %s',
brand, name, garage, plate
),
'success'
)
print(string.format('[dynamic-raffle] Delivered vehicle %s (plate: %s, garage: %s) to %s', model, plate, garage, GetPlayerName(winnerSrc)))
-- ── Item ────────────────────────────────────────────────────────────────
elseif prizeType == 'item' then
local itemName = prizeData.name
local count = math.floor(tonumber(prizeData.count) or 1)
local added = exports.ox_inventory:AddItem(winnerSrc, itemName, count)
if added then
NotifyPlayer(winnerSrc,
string.format('📦 %dx %s has been added to your inventory!', count, itemName),
'success'
)
print(string.format('[dynamic-raffle] Delivered %dx %s to %s', count, itemName, GetPlayerName(winnerSrc)))
else
NotifyPlayer(winnerSrc,
'⚠️ Could not add your prize item — your inventory may be full. Please contact staff.',
'error'
)
print(string.format('[dynamic-raffle] WARN: Failed to add %dx %s to %s (inventory full?)', count, itemName, GetPlayerName(winnerSrc)))
end
-- ── Custom (no auto-delivery) ────────────────────────────────────────────
else
NotifyPlayer(winnerSrc,
'🎁 Your prize is ready — a staff member will deliver it to you shortly!',
'inform'
)
end
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Build manage data payload (sent to client for /rafflemanage)
-- ─────────────────────────────────────────────────────────────────────────────
local function BuildManageData()
local entries = {}
for _, name in pairs(enteredPlayers) do
table.insert(entries, name)
end
table.sort(entries)
-- Build a human-readable cooldown list for the manage menu
local cooldownList = {}
for cid, remaining in pairs(winnerCooldowns) do
-- Try to find the player's name from the online player list
local displayName = cid
for _, playerSrc in ipairs(GetPlayers()) do
local P = QBCore.Functions.GetPlayer(tonumber(playerSrc))
if P and P.PlayerData.citizenid == cid then
displayName = GetPlayerName(tonumber(playerSrc))
break
end
end
table.insert(cooldownList, { name = displayName, remaining = remaining })
end
table.sort(cooldownList, function(a, b) return a.name < b.name end)
return {
active = activeRaffle ~= nil,
raffle = activeRaffle,
entries = entries,
history = raffleHistory,
presets = GetPresets(),
cooldowns = cooldownList,
cooldownLimit = Config.WinnerCooldownRaffles or 0,
-- vehicle + item lists are NOT included here (too large).
-- They are sent separately via requestStartDialog.
}
end
-- ─────────────────────────────────────────────────────────────────────────────
-- Reminder broadcast
-- ─────────────────────────────────────────────────────────────────────────────
local function BroadcastReminder()
if not activeRaffle then return end
local count = 0
for _ in pairs(enteredPlayers) do count = count + 1 end
NotifyAll(
'🎰 RAFFLE REMINDER — ' .. activeRaffle.name ..
'\n🏆 Prize: ' .. activeRaffle.prize ..
'\n👥 Entries: ' .. count ..
'\nType /joinraffle in chat to enter!',
'inform'
)
end
local function ScheduleReminder(sessionName)
SetTimeout(Config.ReminderInterval, function()
if activeRaffle and activeRaffle.name == sessionName then
BroadcastReminder()
ScheduleReminder(sessionName)
end
end)
end
-- ─────────────────────────────────────────────────────────────────────────────
-- NET EVENTS
-- ─────────────────────────────────────────────────────────────────────────────
-- ── Start Raffle ─────────────────────────────────────────────────────────────
-- prizeType: 'custom' | 'vehicle' | 'cash' | 'item'
-- prizeData: type-specific table (see client.lua startRaffleFlow)
RegisterNetEvent('dynamic-raffle:server:startRaffle', function(raffleName, prizeType, prizeData)
local src = source
if not HasAdminPermission(src) then
NotifyPlayer(src, '🚫 You do not have permission to start a raffle.', 'error')
return
end
if activeRaffle then
NotifyPlayer(src, '⚠️ A raffle is already active: ' .. activeRaffle.name .. '. Use /endraffle first.', 'error')
return
end
if #GetOnlinePlayers() < Config.MinPlayers then
NotifyPlayer(src, '⚠️ Not enough players online (minimum: ' .. Config.MinPlayers .. ').', 'error')
return
end
prizeType = prizeType or 'custom'
prizeData = prizeData or { description = '??? Mystery Prize' }
raffleName = (raffleName and raffleName ~= '') and raffleName or 'Mystery Raffle'
enteredPlayers = {} -- clear any stale state
activeRaffle = {
name = raffleName,
prizeType = prizeType,
prizeData = prizeData,
prize = BuildPrizeLabel(prizeType, prizeData),
startedBy = GetPlayerName(src),
startTime = os.time(),
}
NotifyAll(
'🎉 RAFFLE STARTED — ' .. raffleName ..
'\n🏆 Prize: ' .. activeRaffle.prize ..
'\nType /joinraffle to enter! Good luck!',
'success'
)
ScheduleReminder(raffleName)
print(string.format('[dynamic-raffle] Started: "%s" | Type: %s | Prize: %s | By: %s',
raffleName, prizeType, activeRaffle.prize, GetPlayerName(src)))
end)
-- ── Join Raffle ───────────────────────────────────────────────────────────────
RegisterNetEvent('dynamic-raffle:server:joinRaffle', function()
local src = source
if not activeRaffle then
NotifyPlayer(src, '❌ No active raffle right now.', 'error')
return
end
if enteredPlayers[src] then
NotifyPlayer(src, '⚠️ You are already entered in this raffle!', 'error')
return
end
enteredPlayers[src] = GetPlayerName(src)
local count = 0
for _ in pairs(enteredPlayers) do count = count + 1 end
NotifyPlayer(src, '✅ You have entered the raffle! (' .. count .. ' total entries)', 'success')
print('[dynamic-raffle] ' .. GetPlayerName(src) .. ' (src:' .. src .. ') joined.')
end)
-- ── End Raffle ────────────────────────────────────────────────────────────────
RegisterNetEvent('dynamic-raffle:server:endRaffle', function()
local src = source
if not HasAdminPermission(src) then
NotifyPlayer(src, '🚫 You do not have permission to end a raffle.', 'error')
return
end
if not activeRaffle then
NotifyPlayer(src, '❌ No active raffle to end.', 'error')
return
end
-- Build online lookup
local onlineNow = {}
for _, id in ipairs(GetPlayers()) do
onlineNow[tonumber(id)] = true
end
-- Filter entries to players still in city
local eligiblePool = {}
for playerSrc in pairs(enteredPlayers) do
if onlineNow[playerSrc] then
table.insert(eligiblePool, playerSrc)
end
end
if #eligiblePool == 0 then
NotifyPlayer(src, '⚠️ No eligible players in city. Raffle cancelled.', 'error')
activeRaffle = nil
enteredPlayers = {}
return
end
-- ── Step 1: Session cooldown filter ─────────────────────────────────────────
-- Decrement all existing cooldowns once per draw, then exclude active ones.
for cid in pairs(winnerCooldowns) do
winnerCooldowns[cid] = winnerCooldowns[cid] - 1
if winnerCooldowns[cid] <= 0 then winnerCooldowns[cid] = nil end
end
local afterCooldownPool = {}
if Config.WinnerCooldownRaffles and Config.WinnerCooldownRaffles > 0 then
for _, playerSrc in ipairs(eligiblePool) do
local P = QBCore.Functions.GetPlayer(playerSrc)
local cid = P and P.PlayerData.citizenid
if not cid or not winnerCooldowns[cid] then
table.insert(afterCooldownPool, playerSrc)
end
end
if #afterCooldownPool == 0 then
afterCooldownPool = eligiblePool -- bypass: everyone is on session cooldown
print('[dynamic-raffle] Cooldown bypass: all entries on session cooldown, using full pool.')
end
else
afterCooldownPool = eligiblePool
end
-- ── Step 2: Persistent 7-day win limit (DB) ───────────────────────────────
-- Single query fetches all citizenids that have hit the cap this period.
local drawPool = afterCooldownPool
if Config.MaxWinsPerPeriod and Config.MaxWinsPerPeriod > 0 then
local overLimitRows = MySQL.query.await(
'SELECT citizenid FROM raffle_wins WHERE won_at > DATE_SUB(NOW(), INTERVAL ? DAY) GROUP BY citizenid HAVING COUNT(*) >= ?',
{ Config.WinPeriodDays, Config.MaxWinsPerPeriod }
)
local overLimit = {}
for _, row in ipairs(overLimitRows or {}) do
overLimit[row.citizenid] = true
end
if next(overLimit) then -- only filter if at least one player is over limit
local dbFiltered = {}
for _, playerSrc in ipairs(afterCooldownPool) do
local P = QBCore.Functions.GetPlayer(playerSrc)
local cid = P and P.PlayerData.citizenid
if not cid or not overLimit[cid] then
table.insert(dbFiltered, playerSrc)
end
end
if #dbFiltered > 0 then
drawPool = dbFiltered
else
-- Everyone in the pool has hit the 7-day cap — fall back gracefully
drawPool = afterCooldownPool
print('[dynamic-raffle] Win-limit bypass: all entries have hit the ' .. Config.WinPeriodDays .. '-day cap, using cooldown-filtered pool.')
end
end
end
-- ── Step 3: Fisher-Yates shuffle → pick first element ────────────────────
-- Shuffling first eliminates table-ordering bias that can come from
-- pairs() iteration order combined with a PRNG. Much more robust than
-- a direct random index into an unshuffled array.
math.randomseed(os.time() + math.floor(os.clock() * 1e6) + #drawPool)
math.random(); math.random()
local pool = {} -- shallow copy so we don't mutate the original
for i, v in ipairs(drawPool) do pool[i] = v end
for i = #pool, 2, -1 do
local j = math.random(1, i)
pool[i], pool[j] = pool[j], pool[i]
end
local winnerSrc = pool[1]
local winnerName = GetPlayerName(winnerSrc)
local raffleName = activeRaffle.name
local prizeLabel = activeRaffle.prize
local prizeType = activeRaffle.prizeType
local prizeData = activeRaffle.prizeData
-- Collect all entry names (sorted) for history
local allEntries = {}
for _, name in pairs(enteredPlayers) do table.insert(allEntries, name) end
table.sort(allEntries)
-- Push to session history
if #raffleHistory >= Config.MaxHistory then table.remove(raffleHistory, 1) end
table.insert(raffleHistory, {
name = raffleName,
prize = prizeLabel,
prizeType = prizeType,
winner = winnerName,
entries = allEntries,
date = SafeDate(),
})
-- Broadcast winner to everyone
TriggerClientEvent('dynamic-raffle:announce', -1, winnerName, prizeLabel, raffleName)
-- Special NUI screen for winner only
TriggerClientEvent('dynamic-raffle:youWon', winnerSrc, prizeLabel, raffleName)
-- Deliver the prize
DeliverPrize(winnerSrc, prizeType, prizeData)
-- Apply session cooldown to winner
if Config.WinnerCooldownRaffles and Config.WinnerCooldownRaffles > 0 then
local WP = QBCore.Functions.GetPlayer(winnerSrc)
if WP then winnerCooldowns[WP.PlayerData.citizenid] = Config.WinnerCooldownRaffles end
end
-- Record win in DB for the persistent 7-day limit
if Config.MaxWinsPerPeriod and Config.MaxWinsPerPeriod > 0 then
local WP = QBCore.Functions.GetPlayer(winnerSrc)
if WP then
MySQL.insert(
'INSERT INTO raffle_wins (citizenid, player_name, raffle_name, prize) VALUES (?, ?, ?, ?)',
{ WP.PlayerData.citizenid, winnerName, raffleName, prizeLabel }
)
end
end
print(string.format('[dynamic-raffle] "%s" ended. Winner: %s | Prize: %s | Pool size: %d/%d',
raffleName, winnerName, prizeLabel, #drawPool, #eligiblePool))
activeRaffle = nil
enteredPlayers = {}
end)
-- ── Status (admin quick-check) ───────────────────────────────────────────────
RegisterNetEvent('dynamic-raffle:server:status', function()
local src = source
if not HasAdminPermission(src) then return end
if not activeRaffle then
NotifyPlayer(src, 'ℹ️ No active raffle.', 'inform')
return
end
local count = 0
for _ in pairs(enteredPlayers) do count = count + 1 end
NotifyPlayer(src,
'📋 ' .. activeRaffle.name ..
'\n🏆 ' .. activeRaffle.prize ..
'\n👥 Entries: ' .. count ..
'\n🕐 By: ' .. activeRaffle.startedBy,
'inform'
)
end)
-- ── Manual reminder ping ─────────────────────────────────────────────────────
RegisterNetEvent('dynamic-raffle:server:ping', function()
local src = source
if not HasAdminPermission(src) then return end
if not activeRaffle then
NotifyPlayer(src, '❌ No active raffle to ping.', 'error')
return
end
BroadcastReminder()
NotifyPlayer(src, '📣 Reminder sent to all players.', 'success')
end)
-- ── Manage Menu — fetch data ─────────────────────────────────────────────────
RegisterNetEvent('dynamic-raffle:server:getManageData', function()
local src = source
if not HasAdminPermission(src) then return end
TriggerClientEvent('dynamic-raffle:client:openManage', src, BuildManageData())
end)
-- ── Start Dialog — fetch vehicle + item lists ─────────────────────────────────
-- Called before opening the start raffle flow so lists are always fresh
RegisterNetEvent('dynamic-raffle:server:requestStartDialog', function(raffleName)
local src = source
if not HasAdminPermission(src) then return end
TriggerClientEvent('dynamic-raffle:client:openStartDialog', src, {
raffleName = raffleName or 'Mystery Raffle',
vehicleList = GetVehicleList(),
itemList = GetItemList(),
presets = GetPresets(),
})
end)
-- ── Preset CRUD ───────────────────────────────────────────────────────────────
RegisterNetEvent('dynamic-raffle:server:editPreset', function(index, newValue)
local src = source
if not HasAdminPermission(src) then return end
local presets = GetPresets()
if not presets[index] then
NotifyPlayer(src, '❌ Invalid preset index.', 'error')
return
end
presets[index] = newValue
TriggerClientEvent('dynamic-raffle:client:openManage', src, BuildManageData())
end)
RegisterNetEvent('dynamic-raffle:server:addPreset', function(value)
local src = source
if not HasAdminPermission(src) then return end
local presets = GetPresets()
if #presets >= 10 then
NotifyPlayer(src, '⚠️ Maximum of 10 presets allowed.', 'error')
return
end
table.insert(presets, value)
TriggerClientEvent('dynamic-raffle:client:openManage', src, BuildManageData())
end)
RegisterNetEvent('dynamic-raffle:server:removePreset', function(index)
local src = source
if not HasAdminPermission(src) then return end
local presets = GetPresets()
if not presets[index] then
NotifyPlayer(src, '❌ Invalid preset index.', 'error')
return
end
table.remove(presets, index)
TriggerClientEvent('dynamic-raffle:client:openManage', src, BuildManageData())
end)