forked from Simnation/Main
ed
This commit is contained in:
parent
6d22d5f77c
commit
63fbc60a00
86 changed files with 8352 additions and 3428 deletions
180
resources/[Developer]/mh_garage/client/main.lua
Normal file
180
resources/[Developer]/mh_garage/client/main.lua
Normal file
|
@ -0,0 +1,180 @@
|
|||
QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
Player = nil
|
||||
npcHandle = nil
|
||||
isNPCSpawned = false
|
||||
CurrentZone = nil
|
||||
|
||||
CurrentActionData = {}
|
||||
hasAlreadyEnteredMarker = false
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while Player == nil do
|
||||
Player = exports['qb-core']:GetPlayerData()
|
||||
Wait(0)
|
||||
end
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Wait(15000)
|
||||
local ped = PlayerPedId()
|
||||
|
||||
if IsPedInAnyVehicle(ped, false) then
|
||||
local veh = GetVehiclePedIsIn(ped, false)
|
||||
local mods = QBCore.Functions.GetVehicleProperties(veh)
|
||||
print("Triggert setMods: "..json.encode(mods))
|
||||
TriggerServerEvent('mh_garage:setMods', mods)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Funktion zum Spawnen des NPCs
|
||||
function SpawnGuardNPC(npc)
|
||||
-- Ped Model laden
|
||||
RequestModel(npc.model)
|
||||
local timeout = 0
|
||||
while not HasModelLoaded(npc.model) and timeout < 100 do
|
||||
timeout = timeout + 1
|
||||
Wait(100)
|
||||
end
|
||||
|
||||
if not HasModelLoaded(npc.model) then
|
||||
return
|
||||
end
|
||||
|
||||
-- NPC erstellen
|
||||
npcHandle = CreatePed(4, npc.model, npc.spawn.x, npc.spawn.y, npc.spawn.z, npc.spawn.w, false, true)
|
||||
if not DoesEntityExist(npcHandle) then
|
||||
return
|
||||
end
|
||||
|
||||
-- NPC Eigenschaften setzen
|
||||
SetEntityAsMissionEntity(npcHandle, true, true)
|
||||
SetBlockingOfNonTemporaryEvents(npcHandle, true)
|
||||
SetPedDiesWhenInjured(npcHandle, false)
|
||||
SetPedCanPlayAmbientAnims(npcHandle, true)
|
||||
SetPedCanRagdollFromPlayerImpact(npcHandle, false)
|
||||
SetEntityInvincible(npcHandle, true)
|
||||
FreezeEntityPosition(npcHandle, true)
|
||||
|
||||
-- Optional: Animation für den NPC
|
||||
TaskStartScenarioInPlace(npcHandle, "WORLD_HUMAN_GUARD_STAND", 0, true)
|
||||
|
||||
isNPCSpawned = true
|
||||
end
|
||||
|
||||
-- Funktion zum Entfernen des NPCs
|
||||
function RemoveGuardNPC()
|
||||
if DoesEntityExist(npcHandle) then
|
||||
DeleteEntity(npcHandle)
|
||||
isNPCSpawned = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Hauptthread zum Überprüfen der Spieler-Position
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(0)
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
|
||||
local isInMarker = false
|
||||
|
||||
for k, v in pairs(Config.Zonen) do
|
||||
local dist = #(coords - vector3(v.NPC.spawn.x, v.NPC.spawn.y, v.NPC.spawn.z))
|
||||
local spawnDistance = v.NPC.distance
|
||||
|
||||
if dist <= spawnDistance then
|
||||
isInMarker = true
|
||||
CurrentZone = v
|
||||
end
|
||||
end
|
||||
|
||||
if isInMarker and not hasAlreadyEnteredMarker then
|
||||
hasAlreadyEnteredMarker = true
|
||||
SpawnGuardNPC(CurrentZone.NPC)
|
||||
AddTargetOptions()
|
||||
end
|
||||
|
||||
if not isInMarker and hasAlreadyEnteredMarker then
|
||||
hasAlreadyEnteredMarker = false
|
||||
CurrentZone = nil
|
||||
exports['qb-target']:RemoveTargetEntity(npcHandle)
|
||||
RemoveGuardNPC()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function AddTargetOptions()
|
||||
|
||||
local opt = {
|
||||
{
|
||||
type = "client",
|
||||
event = "mh_garage:storeVehicle",
|
||||
icon = "fas fa-parking",
|
||||
label = "Fahrzeug einparken",
|
||||
},
|
||||
{
|
||||
type = "client",
|
||||
event = "mh_garage:retrieveOwnerVehicle",
|
||||
icon = "fas fa-car",
|
||||
label = "Eigene Fahrzeug ausparken",
|
||||
},
|
||||
{
|
||||
type = "client",
|
||||
event = "mh_garage:retrieveVehicle",
|
||||
icon = "key",
|
||||
label = "Schlüssel Fahrzeug ausparken",
|
||||
}
|
||||
}
|
||||
|
||||
if Config.Verwaltung.garage then
|
||||
table.insert(opt, {
|
||||
type = "client",
|
||||
event = "mh_garage:verwaltungVeh",
|
||||
icon = "hand",
|
||||
label = "Fahrzeuge Verwalten",
|
||||
})
|
||||
end
|
||||
|
||||
exports['qb-target']:AddTargetEntity(npcHandle, {
|
||||
options = opt,
|
||||
distance = 2.5
|
||||
})
|
||||
end
|
||||
|
||||
function Notification(text, type)
|
||||
lib.notify({
|
||||
title = "Garage - "..CurrentZone.name,
|
||||
description = text,
|
||||
type = type,
|
||||
position = 'top',
|
||||
})
|
||||
end
|
||||
|
||||
---------------------------- NetEvents
|
||||
RegisterNetEvent('mh_jobgarage:notify')
|
||||
AddEventHandler('mh_jobgarage:notify', function(title, text, type)
|
||||
Notification(text, type)
|
||||
end)
|
||||
|
||||
function GetVehicleDamagePercentage(vehicle)
|
||||
if not vehicle then return 0 end
|
||||
|
||||
-- Hole die verschiedenen Gesundheitswerte
|
||||
local engineHealth = GetVehicleEngineHealth(vehicle)
|
||||
local bodyHealth = GetVehicleBodyHealth(vehicle)
|
||||
local tankHealth = GetVehiclePetrolTankHealth(vehicle)
|
||||
|
||||
-- Normalisiere die Werte (Standard-Maximalwerte: 1000.0)
|
||||
local enginePercent = (engineHealth / 1000.0) * 100
|
||||
local bodyPercent = (bodyHealth / 1000.0) * 100
|
||||
local tankPercent = (tankHealth / 1000.0) * 100
|
||||
|
||||
-- Berechne Durchschnitt als Gesamtzustand
|
||||
local totalHealth = (enginePercent + bodyPercent + tankPercent) / 3
|
||||
|
||||
-- Runde auf ganze Zahlen
|
||||
return math.floor(totalHealth)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue