forked from Simnation/Main
Merge branch 'master' of https://git.evolution-state-life.de/Evolution-State-Life/Main
This commit is contained in:
commit
1a8fefb2c8
5 changed files with 135 additions and 38 deletions
|
@ -741,6 +741,7 @@ end
|
|||
|
||||
RegisterNetEvent('mh_Parking:removeVehicle')
|
||||
AddEventHandler('mh_Parking:removeVehicle', function(plate)
|
||||
print("mh_parking: "..plate)
|
||||
vehicles[plate] = nil
|
||||
end)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ QBCore = exports['qb-core']:GetCoreObject()
|
|||
Player = nil
|
||||
local npcHandle = nil
|
||||
local isNPCSpawned = false
|
||||
CurrentZone = nil
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while Player == nil do
|
||||
|
@ -79,10 +80,12 @@ CreateThread(function()
|
|||
local spawnDistance = v.NPC.distance
|
||||
|
||||
if dist < spawnDistance and not isNPCSpawned then
|
||||
CurrentZone = v
|
||||
SpawnGuardNPC(v.NPC)
|
||||
Wait(300)
|
||||
AddTargetOptions(v)
|
||||
AddTargetOptions()
|
||||
elseif dist > spawnDistance and isNPCSpawned then
|
||||
CurrentZone = nil
|
||||
exports['qb-target']:RemoveTargetEntity(npcHandle)
|
||||
RemoveGuardNPC()
|
||||
end
|
||||
|
@ -92,7 +95,7 @@ CreateThread(function()
|
|||
end
|
||||
end)
|
||||
|
||||
function AddTargetOptions(zone)
|
||||
function AddTargetOptions()
|
||||
|
||||
local opt = {
|
||||
{
|
||||
|
@ -100,14 +103,12 @@ function AddTargetOptions(zone)
|
|||
event = "mh_garage:storeVehicle",
|
||||
icon = "fas fa-parking",
|
||||
label = "Fahrzeug einparken",
|
||||
args = zone
|
||||
},
|
||||
{
|
||||
type = "client",
|
||||
event = "mh_garage:retrieveVehicle",
|
||||
icon = "fas fa-car",
|
||||
label = "Fahrzeug ausparken",
|
||||
args = zone
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,9 +127,9 @@ function AddTargetOptions(zone)
|
|||
})
|
||||
end
|
||||
|
||||
function Notification(text, type, zone)
|
||||
function Notification(text, type)
|
||||
lib.notify({
|
||||
title = "Garage - "..zone,
|
||||
title = "Garage - "..CurrentZone.name,
|
||||
description = text,
|
||||
type = type,
|
||||
position = 'top',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
RegisterNetEvent('mh_garage:retrieveVehicle')
|
||||
AddEventHandler('mh_garage:retrieveVehicle', function(zone)
|
||||
AddEventHandler('mh_garage:retrieveVehicle', function()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local random = SelectName()
|
||||
|
@ -9,11 +9,13 @@ AddEventHandler('mh_garage:retrieveVehicle', function(zone)
|
|||
QBCore.Functions.TriggerCallback('mh_garage:CallVehicles', function(cb)
|
||||
Debug(json.encode(cb))
|
||||
for i = 1, #cb, 1 do
|
||||
local mods = json.decode(cb[i].mods)
|
||||
table.insert(opt, {
|
||||
title = cb[i].name,
|
||||
description = "Kennzeichen: "..cb[i].plate.."\nTankinhalt: "..cb[i].mods.fuelLevel.."%",
|
||||
description = "Kennzeichen: "..cb[i].plate.."\nTankinhalt: "..math.round(mods.fuelLevel, 2).."%",
|
||||
icon = "car",
|
||||
onSelect = function()
|
||||
cb[i].mods = mods
|
||||
SpawnThisVehicle(cb[i])
|
||||
end
|
||||
})
|
||||
|
@ -26,5 +28,82 @@ AddEventHandler('mh_garage:retrieveVehicle', function(zone)
|
|||
})
|
||||
|
||||
lib.showContext("retrieveVehicle")
|
||||
end, zone.name)
|
||||
end)
|
||||
end, CurrentZone.name)
|
||||
end)
|
||||
|
||||
function SpawnThisVehicle(vehicle)
|
||||
local spawnPoint = nil
|
||||
|
||||
-- Freien Spawnpunkt suchen
|
||||
for _, spot in pairs(CurrentZone.vehicle_spawn) do
|
||||
if not IsAnyVehicleNearPoint(spot.x, spot.y, spot.z, 3.0) then
|
||||
spawnPoint = spot
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if spawnPoint then
|
||||
QBCore.Functions.SpawnVehicle(vehicle.vehicle, function(veh)
|
||||
-- Fahrzeug ID für Server
|
||||
local netId = NetworkGetNetworkIdFromEntity(veh)
|
||||
|
||||
-- Grundeinstellungen
|
||||
SetVehicleNumberPlateText(veh, vehicle.plate)
|
||||
SetVehicleDoorsLocked(veh, 0)
|
||||
SetEntityHeading(veh, spawnPoint.w)
|
||||
|
||||
-- Motor aus
|
||||
SetVehicleEngineOn(veh, false, true, true)
|
||||
|
||||
-- Fahrzeug Eigenschaften
|
||||
local mods = type(vehicle.mods) == 'string' and json.decode(vehicle.mods) or vehicle.mods
|
||||
|
||||
-- Grundwerte setzen
|
||||
SetVehicleFuelLevel(veh, mods.fuelLevel)
|
||||
SetVehicleEngineHealth(veh, mods.engineHealth)
|
||||
SetVehicleBodyHealth(veh, mods.bodyHealth)
|
||||
SetVehicleDirtLevel(veh, mods.dirtLevel)
|
||||
|
||||
-- Türen Status
|
||||
if mods.doorStatus then
|
||||
for doorIndex = 0, 5 do
|
||||
if mods.doorStatus[tostring(doorIndex)] then
|
||||
SetVehicleDoorBroken(veh, doorIndex, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Fenster Status
|
||||
if mods.windowStatus then
|
||||
for windowIndex = 0, 7 do
|
||||
if not mods.windowStatus[tostring(windowIndex)] then
|
||||
SmashVehicleWindow(veh, windowIndex)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Alle Mods anwenden
|
||||
QBCore.Functions.SetVehicleProperties(veh, mods)
|
||||
|
||||
-- Fahrzeug auf den Boden setzen
|
||||
SetVehicleOnGroundProperly(veh)
|
||||
|
||||
-- Server über gespawntes Fahrzeug informieren
|
||||
TriggerServerEvent('mh_garage:spawnedVehicle', netId, vehicle.plate)
|
||||
|
||||
-- Optional: Erfolgsmeldung
|
||||
lib.notify({
|
||||
title = "Fahrzeug geparkt...",
|
||||
description = "Dein Fahrzeug steht auf Parkplatz "..math.random(1, 15),
|
||||
type = "success"
|
||||
})
|
||||
end, vector3(spawnPoint.x, spawnPoint.y, spawnPoint.z), true)
|
||||
else
|
||||
QBCore.Functions.Notify('Alle Parkplätze sind belegt!', 'error')
|
||||
lib.notify({
|
||||
title = "Fahrzeug nicht gefunden",
|
||||
description = "Alle Parkplätze sind belegt!",
|
||||
type = "success"
|
||||
})
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
RegisterNetEvent('mh_garage:storeVehicle')
|
||||
AddEventHandler('mh_garage:storeVehicle', function(zone)
|
||||
AddEventHandler('mh_garage:storeVehicle', function()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
|
@ -16,32 +16,34 @@ AddEventHandler('mh_garage:storeVehicle', function(zone)
|
|||
description = GetRandomCarDescription(),
|
||||
icon = "car",
|
||||
onSelect = function()
|
||||
print(zone.price)
|
||||
if zone.price ~= false then
|
||||
print(CurrentZone.price)
|
||||
if CurrentZone.price ~= false then
|
||||
lib.hideContext("StoredVehicles")
|
||||
|
||||
lib.registerContext({
|
||||
id = "thisVehicle",
|
||||
title = random.name,
|
||||
options = {
|
||||
{title = "Kosten: "..zone.price},
|
||||
{title = ""},
|
||||
{title = "Kosten: "..CurrentZone.price.."$"},
|
||||
{title = "", disabled = true},
|
||||
{
|
||||
title = "Akzeptieren",
|
||||
description = "Geld wird vom Bankkonto abgebucht!",
|
||||
icon = "check",
|
||||
onSelect = function()
|
||||
lib.hideContext("thisVehicle")
|
||||
QBCore.Functions.TriggerCallback('mh_garage:storedVehicle', function(cb)
|
||||
if cb.status then
|
||||
DeleteVehicle(vehicles[i])
|
||||
Notification(cb.text, cb.type, zone.name)
|
||||
TriggerServerEvent('mh_Parking:deleteVehicle', mods.plate, NetworkGetNetworkIdFromEntity(vehicles[i]))
|
||||
--DeleteVehicle(vehicles[i])
|
||||
Notification(cb.text, cb.type, CurrentZone.name)
|
||||
else
|
||||
if cb.police and Config.EnabledPolice then
|
||||
exports["roadphone"]:sendDispatch("Hier hat grade jemand versucht, ein Fahrzeug einzuparken.\nDas Zündschloss sah Beschädigt aus.\nKennzeichen: "..veh.plate, 'police', nil)
|
||||
end
|
||||
Notification(cb.text, cb.type)
|
||||
end
|
||||
end, veh, zone)
|
||||
end, mods, CurrentZone)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -57,7 +59,7 @@ AddEventHandler('mh_garage:storeVehicle', function(zone)
|
|||
|
||||
lib.showContext("thisVehicle")
|
||||
else
|
||||
StoredVehicle(vehicles[i], zone)
|
||||
StoredVehicle(vehicles[i], CurrentZone)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -3,16 +3,22 @@ local test_vari = {}
|
|||
|
||||
RegisterServerEvent('mh_garage:setMods')
|
||||
AddEventHandler('mh_garage:setMods', function(mods)
|
||||
print(mods.plate)
|
||||
if test_vari[mods.plate] == true then
|
||||
Print("Fahrzeug hat bereits ein Eintrag")
|
||||
|
||||
else
|
||||
MySQL.query("SELECT mods FROM player_vehicles WHERE plate = ?", {mods.plate}, function(rs)
|
||||
if rs[1].mods == nil then
|
||||
MySQL.query("UPDATE player_vehicles SET mods = ? WHERE plate = ?", {mods.plate})
|
||||
test_vari[mods.plate] = true
|
||||
else
|
||||
test_vari[mods.plate] = true
|
||||
-- Prüfen ob rs überhaupt Daten enthält
|
||||
if rs and rs[1] then
|
||||
-- Wenn mods ein String ist, konvertieren wir es zu einem Table
|
||||
local modsData = type(rs[1].mods) == "string" and json.decode(rs[1].mods) or rs[1].mods
|
||||
|
||||
if not modsData or next(modsData) == nil then
|
||||
-- Hier sollten Sie wahrscheinlich auch die mods-Daten übergeben, nicht nur plate
|
||||
MySQL.query("UPDATE player_vehicles SET mods = ? WHERE plate = ?", {json.encode(mods), mods.plate})
|
||||
test_vari[mods.plate] = true
|
||||
else
|
||||
test_vari[mods.plate] = true
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
@ -25,7 +31,7 @@ QBCore.Functions.CreateCallback('mh_garage:storedVehicle', function(source, cb,
|
|||
if Player.Functions.GetMoney('bank', zone.price) then
|
||||
MySQL.query("SELECT * FROM player_vehicles WHERE citizenid = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs)
|
||||
if rs[1] ~= nil then
|
||||
MySQL.query("UPDATE player_vehicles SET garage = ? AND parking = ? WHERE plate = ?", {zone.name, true, veh.plate})
|
||||
MySQL.query("UPDATE player_vehicles SET garage = ?, parking = ? WHERE plate = ?", {zone.name, true, veh.plate})
|
||||
DelVehParking(veh.plate)
|
||||
cb({
|
||||
status = true,
|
||||
|
@ -37,8 +43,9 @@ QBCore.Functions.CreateCallback('mh_garage:storedVehicle', function(source, cb,
|
|||
else
|
||||
MySQL.query("SELECT * FROM vehicle_keys WHERE owner = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs)
|
||||
if rs[1] ~= nil then
|
||||
MySQL.query("UPDATE player_vehicles SET garage = ? AND parking = ? WHERE plate = ?", {zone.name, true, veh.plate})
|
||||
DelVehParking(veh.plate)
|
||||
MySQL.query("UPDATE player_vehicles SET garage = ?, parking = ? WHERE plate = ?", {zone.name, true, veh.plate})
|
||||
--TriggerEvent('mh_Parking:removeVehicle', source, veh.plate)
|
||||
--DelVehParking(veh.plate)
|
||||
cb({
|
||||
status = true,
|
||||
text = "Fahrzeug erfolgreich eingeparkt!",
|
||||
|
@ -78,7 +85,7 @@ QBCore.Functions.CreateCallback('mh_garage:CallVehicles', function(source, cb, z
|
|||
|
||||
if Config.CallKeyVehicles then
|
||||
MySQL.query("SELECT plate FROM vehicle_keys WHERE owner = ?", {Player.PlayerData.citizenid}, function(rs)
|
||||
if rs[1] ~= nil then
|
||||
if rs and rs[1] then
|
||||
for k, v in pairs(rs) do
|
||||
table.insert(vehicle_keys, {plate = v.plate})
|
||||
end
|
||||
|
@ -90,19 +97,21 @@ QBCore.Functions.CreateCallback('mh_garage:CallVehicles', function(source, cb, z
|
|||
print(json.encode(vehicle_keys))
|
||||
for k, v in pairs(vehicle_keys) do
|
||||
MySQL.query("SELECT vehicle, plate, mods, name FROM player_vehicles WHERE plate = ?", {v.plate}, function(rs)
|
||||
table.insert(vehicles, {
|
||||
vehicle = rs[1].vehicle,
|
||||
mods = rs[1].mods,
|
||||
plate = rs[1].plate,
|
||||
name = rs[1].name
|
||||
})
|
||||
if rs and rs[1] then
|
||||
table.insert(vehicles, {
|
||||
vehicle = rs[1].vehicle,
|
||||
mods = rs[1].mods,
|
||||
plate = rs[1].plate,
|
||||
name = rs[1].name
|
||||
})
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
MySQL.query("SELECT vehicle, plate, mods FROM player_vehicles WHERE citizenid = ? AND garage = ?", {Player.PlayerData.citizenid, zone}, function(rs)
|
||||
if rs[1] ~= nil then
|
||||
if rs and rs[1] then
|
||||
for k, v in pairs(rs) do
|
||||
table.insert(vehicles, {
|
||||
vehicle = v.vehicle,
|
||||
|
@ -122,7 +131,7 @@ QBCore.Functions.CreateCallback('mh_garage:verwaltung', function(source, cb)
|
|||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
local vehicles = {}
|
||||
MySQL.query("SELECT * FROM player_vehicles WHERE citizenid = ?", {Player.PlayerData.citizenid}, function(rs)
|
||||
if rs[1] ~= nil then
|
||||
if rs and rs[1] then
|
||||
for k, v in pairs(rs) do
|
||||
table.insert(vehicles, {
|
||||
current_garage = v.garage,
|
||||
|
@ -134,4 +143,9 @@ QBCore.Functions.CreateCallback('mh_garage:verwaltung', function(source, cb)
|
|||
end
|
||||
end)
|
||||
return vehicles
|
||||
end)
|
||||
|
||||
RegisterServerEvent('mh_garage:spawnedVehicle')
|
||||
AddEventHandler('mh_garage:spawnedVehicle', function(netID, plate)
|
||||
MySQL.query("UPDATE player_vehicles SET parking = ? WHERE plate = ?", {0, plate})
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue