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')
|
RegisterNetEvent('mh_Parking:removeVehicle')
|
||||||
AddEventHandler('mh_Parking:removeVehicle', function(plate)
|
AddEventHandler('mh_Parking:removeVehicle', function(plate)
|
||||||
|
print("mh_parking: "..plate)
|
||||||
vehicles[plate] = nil
|
vehicles[plate] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ QBCore = exports['qb-core']:GetCoreObject()
|
||||||
Player = nil
|
Player = nil
|
||||||
local npcHandle = nil
|
local npcHandle = nil
|
||||||
local isNPCSpawned = false
|
local isNPCSpawned = false
|
||||||
|
CurrentZone = nil
|
||||||
|
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while Player == nil do
|
while Player == nil do
|
||||||
|
@ -79,10 +80,12 @@ CreateThread(function()
|
||||||
local spawnDistance = v.NPC.distance
|
local spawnDistance = v.NPC.distance
|
||||||
|
|
||||||
if dist < spawnDistance and not isNPCSpawned then
|
if dist < spawnDistance and not isNPCSpawned then
|
||||||
|
CurrentZone = v
|
||||||
SpawnGuardNPC(v.NPC)
|
SpawnGuardNPC(v.NPC)
|
||||||
Wait(300)
|
Wait(300)
|
||||||
AddTargetOptions(v)
|
AddTargetOptions()
|
||||||
elseif dist > spawnDistance and isNPCSpawned then
|
elseif dist > spawnDistance and isNPCSpawned then
|
||||||
|
CurrentZone = nil
|
||||||
exports['qb-target']:RemoveTargetEntity(npcHandle)
|
exports['qb-target']:RemoveTargetEntity(npcHandle)
|
||||||
RemoveGuardNPC()
|
RemoveGuardNPC()
|
||||||
end
|
end
|
||||||
|
@ -92,7 +95,7 @@ CreateThread(function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function AddTargetOptions(zone)
|
function AddTargetOptions()
|
||||||
|
|
||||||
local opt = {
|
local opt = {
|
||||||
{
|
{
|
||||||
|
@ -100,14 +103,12 @@ function AddTargetOptions(zone)
|
||||||
event = "mh_garage:storeVehicle",
|
event = "mh_garage:storeVehicle",
|
||||||
icon = "fas fa-parking",
|
icon = "fas fa-parking",
|
||||||
label = "Fahrzeug einparken",
|
label = "Fahrzeug einparken",
|
||||||
args = zone
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "client",
|
type = "client",
|
||||||
event = "mh_garage:retrieveVehicle",
|
event = "mh_garage:retrieveVehicle",
|
||||||
icon = "fas fa-car",
|
icon = "fas fa-car",
|
||||||
label = "Fahrzeug ausparken",
|
label = "Fahrzeug ausparken",
|
||||||
args = zone
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,9 +127,9 @@ function AddTargetOptions(zone)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function Notification(text, type, zone)
|
function Notification(text, type)
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = "Garage - "..zone,
|
title = "Garage - "..CurrentZone.name,
|
||||||
description = text,
|
description = text,
|
||||||
type = type,
|
type = type,
|
||||||
position = 'top',
|
position = 'top',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
RegisterNetEvent('mh_garage:retrieveVehicle')
|
RegisterNetEvent('mh_garage:retrieveVehicle')
|
||||||
AddEventHandler('mh_garage:retrieveVehicle', function(zone)
|
AddEventHandler('mh_garage:retrieveVehicle', function()
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
local coords = GetEntityCoords(ped)
|
local coords = GetEntityCoords(ped)
|
||||||
local random = SelectName()
|
local random = SelectName()
|
||||||
|
@ -9,11 +9,13 @@ AddEventHandler('mh_garage:retrieveVehicle', function(zone)
|
||||||
QBCore.Functions.TriggerCallback('mh_garage:CallVehicles', function(cb)
|
QBCore.Functions.TriggerCallback('mh_garage:CallVehicles', function(cb)
|
||||||
Debug(json.encode(cb))
|
Debug(json.encode(cb))
|
||||||
for i = 1, #cb, 1 do
|
for i = 1, #cb, 1 do
|
||||||
|
local mods = json.decode(cb[i].mods)
|
||||||
table.insert(opt, {
|
table.insert(opt, {
|
||||||
title = cb[i].name,
|
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",
|
icon = "car",
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
|
cb[i].mods = mods
|
||||||
SpawnThisVehicle(cb[i])
|
SpawnThisVehicle(cb[i])
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -26,5 +28,82 @@ AddEventHandler('mh_garage:retrieveVehicle', function(zone)
|
||||||
})
|
})
|
||||||
|
|
||||||
lib.showContext("retrieveVehicle")
|
lib.showContext("retrieveVehicle")
|
||||||
end, zone.name)
|
end, CurrentZone.name)
|
||||||
end)
|
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')
|
RegisterNetEvent('mh_garage:storeVehicle')
|
||||||
AddEventHandler('mh_garage:storeVehicle', function(zone)
|
AddEventHandler('mh_garage:storeVehicle', function()
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
local coords = GetEntityCoords(ped)
|
local coords = GetEntityCoords(ped)
|
||||||
local vehicles = GetGamePool('CVehicle')
|
local vehicles = GetGamePool('CVehicle')
|
||||||
|
@ -16,32 +16,34 @@ AddEventHandler('mh_garage:storeVehicle', function(zone)
|
||||||
description = GetRandomCarDescription(),
|
description = GetRandomCarDescription(),
|
||||||
icon = "car",
|
icon = "car",
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
print(zone.price)
|
print(CurrentZone.price)
|
||||||
if zone.price ~= false then
|
if CurrentZone.price ~= false then
|
||||||
lib.hideContext("StoredVehicles")
|
lib.hideContext("StoredVehicles")
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = "thisVehicle",
|
id = "thisVehicle",
|
||||||
title = random.name,
|
title = random.name,
|
||||||
options = {
|
options = {
|
||||||
{title = "Kosten: "..zone.price},
|
{title = "Kosten: "..CurrentZone.price.."$"},
|
||||||
{title = ""},
|
{title = "", disabled = true},
|
||||||
{
|
{
|
||||||
title = "Akzeptieren",
|
title = "Akzeptieren",
|
||||||
description = "Geld wird vom Bankkonto abgebucht!",
|
description = "Geld wird vom Bankkonto abgebucht!",
|
||||||
|
icon = "check",
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
lib.hideContext("thisVehicle")
|
lib.hideContext("thisVehicle")
|
||||||
QBCore.Functions.TriggerCallback('mh_garage:storedVehicle', function(cb)
|
QBCore.Functions.TriggerCallback('mh_garage:storedVehicle', function(cb)
|
||||||
if cb.status then
|
if cb.status then
|
||||||
DeleteVehicle(vehicles[i])
|
TriggerServerEvent('mh_Parking:deleteVehicle', mods.plate, NetworkGetNetworkIdFromEntity(vehicles[i]))
|
||||||
Notification(cb.text, cb.type, zone.name)
|
--DeleteVehicle(vehicles[i])
|
||||||
|
Notification(cb.text, cb.type, CurrentZone.name)
|
||||||
else
|
else
|
||||||
if cb.police and Config.EnabledPolice then
|
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)
|
exports["roadphone"]:sendDispatch("Hier hat grade jemand versucht, ein Fahrzeug einzuparken.\nDas Zündschloss sah Beschädigt aus.\nKennzeichen: "..veh.plate, 'police', nil)
|
||||||
end
|
end
|
||||||
Notification(cb.text, cb.type)
|
Notification(cb.text, cb.type)
|
||||||
end
|
end
|
||||||
end, veh, zone)
|
end, mods, CurrentZone)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -57,7 +59,7 @@ AddEventHandler('mh_garage:storeVehicle', function(zone)
|
||||||
|
|
||||||
lib.showContext("thisVehicle")
|
lib.showContext("thisVehicle")
|
||||||
else
|
else
|
||||||
StoredVehicle(vehicles[i], zone)
|
StoredVehicle(vehicles[i], CurrentZone)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,16 +3,22 @@ local test_vari = {}
|
||||||
|
|
||||||
RegisterServerEvent('mh_garage:setMods')
|
RegisterServerEvent('mh_garage:setMods')
|
||||||
AddEventHandler('mh_garage:setMods', function(mods)
|
AddEventHandler('mh_garage:setMods', function(mods)
|
||||||
print(mods.plate)
|
|
||||||
if test_vari[mods.plate] == true then
|
if test_vari[mods.plate] == true then
|
||||||
Print("Fahrzeug hat bereits ein Eintrag")
|
|
||||||
else
|
else
|
||||||
MySQL.query("SELECT mods FROM player_vehicles WHERE plate = ?", {mods.plate}, function(rs)
|
MySQL.query("SELECT mods FROM player_vehicles WHERE plate = ?", {mods.plate}, function(rs)
|
||||||
if rs[1].mods == nil then
|
-- Prüfen ob rs überhaupt Daten enthält
|
||||||
MySQL.query("UPDATE player_vehicles SET mods = ? WHERE plate = ?", {mods.plate})
|
if rs and rs[1] then
|
||||||
test_vari[mods.plate] = true
|
-- Wenn mods ein String ist, konvertieren wir es zu einem Table
|
||||||
else
|
local modsData = type(rs[1].mods) == "string" and json.decode(rs[1].mods) or rs[1].mods
|
||||||
test_vari[mods.plate] = true
|
|
||||||
|
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)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -25,7 +31,7 @@ QBCore.Functions.CreateCallback('mh_garage:storedVehicle', function(source, cb,
|
||||||
if Player.Functions.GetMoney('bank', zone.price) then
|
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)
|
MySQL.query("SELECT * FROM player_vehicles WHERE citizenid = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs)
|
||||||
if rs[1] ~= nil then
|
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)
|
DelVehParking(veh.plate)
|
||||||
cb({
|
cb({
|
||||||
status = true,
|
status = true,
|
||||||
|
@ -37,8 +43,9 @@ QBCore.Functions.CreateCallback('mh_garage:storedVehicle', function(source, cb,
|
||||||
else
|
else
|
||||||
MySQL.query("SELECT * FROM vehicle_keys WHERE owner = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs)
|
MySQL.query("SELECT * FROM vehicle_keys WHERE owner = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs)
|
||||||
if rs[1] ~= nil then
|
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)
|
--TriggerEvent('mh_Parking:removeVehicle', source, veh.plate)
|
||||||
|
--DelVehParking(veh.plate)
|
||||||
cb({
|
cb({
|
||||||
status = true,
|
status = true,
|
||||||
text = "Fahrzeug erfolgreich eingeparkt!",
|
text = "Fahrzeug erfolgreich eingeparkt!",
|
||||||
|
@ -78,7 +85,7 @@ QBCore.Functions.CreateCallback('mh_garage:CallVehicles', function(source, cb, z
|
||||||
|
|
||||||
if Config.CallKeyVehicles then
|
if Config.CallKeyVehicles then
|
||||||
MySQL.query("SELECT plate FROM vehicle_keys WHERE owner = ?", {Player.PlayerData.citizenid}, function(rs)
|
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
|
for k, v in pairs(rs) do
|
||||||
table.insert(vehicle_keys, {plate = v.plate})
|
table.insert(vehicle_keys, {plate = v.plate})
|
||||||
end
|
end
|
||||||
|
@ -90,19 +97,21 @@ QBCore.Functions.CreateCallback('mh_garage:CallVehicles', function(source, cb, z
|
||||||
print(json.encode(vehicle_keys))
|
print(json.encode(vehicle_keys))
|
||||||
for k, v in pairs(vehicle_keys) do
|
for k, v in pairs(vehicle_keys) do
|
||||||
MySQL.query("SELECT vehicle, plate, mods, name FROM player_vehicles WHERE plate = ?", {v.plate}, function(rs)
|
MySQL.query("SELECT vehicle, plate, mods, name FROM player_vehicles WHERE plate = ?", {v.plate}, function(rs)
|
||||||
table.insert(vehicles, {
|
if rs and rs[1] then
|
||||||
vehicle = rs[1].vehicle,
|
table.insert(vehicles, {
|
||||||
mods = rs[1].mods,
|
vehicle = rs[1].vehicle,
|
||||||
plate = rs[1].plate,
|
mods = rs[1].mods,
|
||||||
name = rs[1].name
|
plate = rs[1].plate,
|
||||||
})
|
name = rs[1].name
|
||||||
|
})
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
MySQL.query("SELECT vehicle, plate, mods FROM player_vehicles WHERE citizenid = ? AND garage = ?", {Player.PlayerData.citizenid, zone}, function(rs)
|
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
|
for k, v in pairs(rs) do
|
||||||
table.insert(vehicles, {
|
table.insert(vehicles, {
|
||||||
vehicle = v.vehicle,
|
vehicle = v.vehicle,
|
||||||
|
@ -122,7 +131,7 @@ QBCore.Functions.CreateCallback('mh_garage:verwaltung', function(source, cb)
|
||||||
local Player = QBCore.Functions.GetPlayer(source)
|
local Player = QBCore.Functions.GetPlayer(source)
|
||||||
local vehicles = {}
|
local vehicles = {}
|
||||||
MySQL.query("SELECT * FROM player_vehicles WHERE citizenid = ?", {Player.PlayerData.citizenid}, function(rs)
|
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
|
for k, v in pairs(rs) do
|
||||||
table.insert(vehicles, {
|
table.insert(vehicles, {
|
||||||
current_garage = v.garage,
|
current_garage = v.garage,
|
||||||
|
@ -134,4 +143,9 @@ QBCore.Functions.CreateCallback('mh_garage:verwaltung', function(source, cb)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
return vehicles
|
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)
|
end)
|
Loading…
Add table
Add a link
Reference in a new issue