Auto-sync 2026-04-15 23:35
This commit is contained in:
parent
43a039d098
commit
f14cfef22f
@ -223,7 +223,7 @@ end)
|
||||
|
||||
-- ── Fahrrad spawnen ────────────────────────────────────────────
|
||||
|
||||
RegisterNetEvent('mercyv-bike:doSpawn', function(bikeModel, spawnData)
|
||||
RegisterNetEvent('mercyv-bike:doSpawn', function(bikeModel, spawnData, plate)
|
||||
print('[mercyv-bike] Spawne Fahrrad: ' .. tostring(bikeModel))
|
||||
|
||||
local model = GetHashKey(bikeModel)
|
||||
@ -272,10 +272,15 @@ RegisterNetEvent('mercyv-bike:doSpawn', function(bikeModel, spawnData)
|
||||
if DoesEntityExist(bike) then
|
||||
SetEntityAsMissionEntity(bike, true, true)
|
||||
SetVehicleEngineOn(bike, true, true, false)
|
||||
-- Kennzeichen setzen falls vom Server übergeben
|
||||
if plate and plate ~= '' then
|
||||
SetVehicleNumberPlateText(bike, plate)
|
||||
end
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
TriggerServerEvent('vehicles_keys:selfGiveVehicleKeys', GetVehicleNumberPlateText(bike))
|
||||
local finalPlate = plate or GetVehicleNumberPlateText(bike)
|
||||
TriggerServerEvent('vehicles_keys:selfGiveVehicleKeys', finalPlate)
|
||||
Notify("Fahrrad erhalten! Viel Spaß!", "success")
|
||||
print('[mercyv-bike] Fahrrad erfolgreich gespawnt.')
|
||||
print('[mercyv-bike] Fahrrad gespawnt mit Kennzeichen: ' .. tostring(finalPlate))
|
||||
else
|
||||
Notify("Fahrrad konnte nicht gespawnt werden.", "error")
|
||||
end
|
||||
|
||||
@ -15,6 +15,21 @@ local function GetIdentifier(src)
|
||||
return xp and xp.identifier or nil
|
||||
end
|
||||
|
||||
-- Fahrzeug-Tabelle (ESX)
|
||||
local function vT() return "owned_vehicles" end
|
||||
local function oC() return "owner" end
|
||||
local function pC() return "vehicle" end
|
||||
|
||||
-- Zufälliges Kennzeichen generieren
|
||||
local function GeneratePlate()
|
||||
local chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ'
|
||||
local plate = ''
|
||||
for i = 1, 3 do plate = plate .. chars:sub(math.random(1,#chars),math.random(1,#chars)):sub(1,1) end
|
||||
plate = plate .. ' '
|
||||
for i = 1, 3 do plate = plate .. tostring(math.random(0,9)) end
|
||||
return plate
|
||||
end
|
||||
|
||||
local function IsAdmin(src)
|
||||
if IsPlayerAceAllowed(src, Config.AdminAce) then return true end
|
||||
if ESX then
|
||||
@ -66,6 +81,16 @@ AddEventHandler('onResourceStart', function(res)
|
||||
`spawn_heading` FLOAT DEFAULT 0
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
]])
|
||||
|
||||
-- Migration: Spalten hinzufügen falls noch nicht vorhanden
|
||||
for _, col in ipairs({'spawn_x','spawn_y','spawn_z','spawn_heading'}) do
|
||||
local exists = MySQL.query.await(string.format(
|
||||
"SELECT COUNT(*) AS cnt FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='mercyv_bike_npc' AND COLUMN_NAME='%s'", col))
|
||||
if exists and exists[1] and exists[1].cnt == 0 then
|
||||
MySQL.query.await(string.format("ALTER TABLE `mercyv_bike_npc` ADD COLUMN `%s` FLOAT DEFAULT 0", col))
|
||||
print('[mercyv-bike] Spalte ' .. col .. ' hinzugefügt.')
|
||||
end
|
||||
end
|
||||
-- Dann lesen
|
||||
local r = MySQL.query.await("SELECT * FROM mercyv_bike_npc LIMIT 1")
|
||||
if r and r[1] then
|
||||
@ -118,16 +143,29 @@ RegisterNetEvent('mercyv-bike:claim', function(bikeModel)
|
||||
return
|
||||
end
|
||||
|
||||
-- Eintragen
|
||||
-- Zufälliges Kennzeichen
|
||||
local plate = GeneratePlate()
|
||||
|
||||
-- Als eigenes Fahrzeug in owned_vehicles eintragen
|
||||
local tbl = vT(); local owner = oC(); local props = pC()
|
||||
local modelHash = joaat and joaat(bikeModel) or 0
|
||||
local skinData = json.encode({ model = GetHashKey(bikeModel), plate = plate })
|
||||
|
||||
MySQL.insert(
|
||||
string.format("INSERT INTO `%s` (plate, `%s`, `%s`, stored, parking, job, veh_class) VALUES (?, ?, ?, 1, 'Garage A', '', 13)", tbl, owner, props),
|
||||
{ plate, identifier, skinData }
|
||||
)
|
||||
|
||||
-- Claim eintragen
|
||||
MySQL.insert(
|
||||
'INSERT INTO mercyv_bike_claims (identifier, bike_model) VALUES (?, ?)',
|
||||
{ identifier, bikeModel }
|
||||
)
|
||||
|
||||
-- Spawn-Signal
|
||||
TriggerClientEvent('mercyv-bike:doSpawn', src, bikeModel, SpawnData)
|
||||
-- Spawn-Signal mit Kennzeichen
|
||||
TriggerClientEvent('mercyv-bike:doSpawn', src, bikeModel, SpawnData, plate)
|
||||
Config.ServerNotification(src, Config.Notify.CLAIMED, "success")
|
||||
print(string.format('[mercyv-bike] %s hat %s erhalten.', identifier, bikeModel))
|
||||
print(string.format('[mercyv-bike] %s hat %s erhalten (Kennzeichen: %s).', identifier, bikeModel, plate))
|
||||
end)
|
||||
|
||||
-- ── Prüfen ob Spieler bereits eines hat ───────────────────────
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user