This commit is contained in:
Nordi98 2025-08-06 15:36:50 +02:00
parent 6d22d5f77c
commit 63fbc60a00
86 changed files with 8352 additions and 3428 deletions

View file

@ -0,0 +1,90 @@
-- A modified version of "VehicleDeformation" v1.0.1, by Kiminaze. Full credits go to him, so adibe by the license below.
-- Check out his other work: https://kiminazes-script-gems.tebex.io/
--
-- VehicleDeformation License:
--
-- Copyright (c) 2021 Philipp Decker /// FiveM: Kiminaze / Discord: Kiminaze#9097
-- By acquiring a copy of this code snippet for the "FiveM" modification for "Grand Theft
-- Auto V" you are granted permission to use and modify all of its parts.
-- You are allowed to (re-)distribute and sell resources that have been created with the
-- help of this code snippet. You have to include this license when doing so.
-- This code snippet is provided "as is" and the copyright holder of this code snippet can
-- not be held accountable for any damages occuring during the usage or modification of
-- this code snippet.
local MAX_DEFORM_ITERATIONS = 50 -- iterations for damage application
local DEFORMATION_DAMAGE_THRESHOLD = 0.05 -- the minimum damage value at a deformation point
function getVehicleDeformation(vehicle)
assert(vehicle ~= nil and DoesEntityExist(vehicle), "Parameter \"vehicle\" must be a valid vehicle entity!")
-- check vehicle size and pre-calc values for offsets
local min, max = GetModelDimensions(GetEntityModel(vehicle))
local X = (max.x - min.x) * 0.5
local Y = (max.y - min.y) * 0.5
local Z = (max.z - min.z) * 0.5
local halfY = Y * 0.5
-- offsets for deformation check
local positions = {vector3(-X, Y, 0.0), vector3(-X, Y, Z), vector3(0.0, Y, 0.0), vector3(0.0, Y, Z), vector3(X, Y, 0.0), vector3(X, Y, Z), vector3(-X, halfY, 0.0), vector3(-X, halfY, Z), vector3(0.0, halfY, 0.0), vector3(0.0, halfY, Z), vector3(X, halfY, 0.0), vector3(X, halfY, Z),
vector3(-X, 0.0, 0.0), vector3(-X, 0.0, Z), vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, Z), vector3(X, 0.0, 0.0), vector3(X, 0.0, Z), vector3(-X, -halfY, 0.0), vector3(-X, -halfY, Z), vector3(0.0, -halfY, 0.0), vector3(0.0, -halfY, Z), vector3(X, -halfY, 0.0),
vector3(X, -halfY, Z), vector3(-X, -Y, 0.0), vector3(-X, -Y, Z), vector3(0.0, -Y, 0.0), vector3(0.0, -Y, Z), vector3(X, -Y, 0.0), vector3(X, -Y, Z)}
-- get deformation from vehicle
local deformationPoints = {}
for i, pos in ipairs(positions) do
-- translate damage from vector3 to a float
local dmg = #(GetVehicleDeformationAtPos(vehicle, pos.x, pos.y, pos.z))
if (dmg > DEFORMATION_DAMAGE_THRESHOLD) then
table.insert(deformationPoints, {pos, dmg})
end
end
return {
deformation = deformationPoints,
dirt = GetVehicleDirtLevel(vehicle)
}
end
function setVehicleDeformation(vehicle, deformation)
assert(vehicle ~= nil and DoesEntityExist(vehicle), "Parameter \"vehicle\" must be a valid vehicle entity!")
assert(deformation ~= nil and type(deformation) == "table", "Parameter \"deformation\" must be a table!")
local deformationPoints = deformation.deformation
local dirt = deformation.dirt
CreateThread(function()
local handlingMult, damageMult = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fDeformationDamageMult"), 20.0
if handlingMult <= 0.55 then damageMult = 1000.0
elseif handlingMult <= 0.65 then damageMult = 400.0
elseif handlingMult <= 0.75 then damageMult = 200.0 end
for _, def in ipairs(deformationPoints) do
def[1] = vector3(def[1].x, def[1].y, def[1].z)
end
-- iterate over all deformation points and check if more than one application is necessary
-- looping is necessary for most vehicles that have a really bad damage model or take a lot of damage (e.g. neon, phantom3)
local deform = true
local iteration = 0
while deform and iteration < MAX_DEFORM_ITERATIONS do
if not DoesEntityExist(vehicle) then return end
deform = false
for _, def in ipairs(deformationPoints) do
if #(GetVehicleDeformationAtPos(vehicle, def[1].x, def[1].y, def[1].z)) < def[2] then
local offset = def[1] * 2.0
SetVehicleDamage(vehicle, offset.x, offset.y, offset.z, def[2] * damageMult, 1000.0, true)
deform = true
end
end
iteration = iteration + 1
Wait(100)
end
SetVehicleDirtLevel(vehicle, dirt)
end)
end

View file

@ -0,0 +1,186 @@
local GARAGE_ZONE_Z_DIST = 4.0
local inVehicle, blips, zones, peds = nil, {}, {}, {}
local cachedGarageLocations
function getAvailableGarageLocations()
if not cachedGarageLocations then
cachedGarageLocations = lib.callback.await("jg-advancedgarages:server:get-available-garage-locations", false)
end
return cachedGarageLocations or {}
end
---@param coords vector3
---@param marker table
function drawMarkerOnFrame(coords, marker)
---@diagnostic disable-next-line: missing-parameter
DrawMarker(marker.id, coords.x, coords.y, coords.z, 0, 0, 0, 0, 0, 0, marker.size.x, marker.size.y, marker.size.z, marker.color.r, marker.color.g, marker.color.b, marker.color.a, marker.bobUpAndDown, marker.faceCamera, 0, marker.rotate, marker.drawOnEnts)
end
---@param name string
---@param coords vector3
---@param blipId integer
---@param blipColour integer
---@param blipScale number
local function createBlip(name, coords, blipId, blipColour, blipScale)
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, blipId)
SetBlipColour(blip, blipColour)
SetBlipScale(blip, blipScale)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(name)
EndTextCommandSetBlipName(blip)
return blip
end
---@param garageId string
---@param coords vector3|vector4
---@param dist number
---@param marker? table | false | nil
---@param onEnter? function
---@param onExit? function
---@param inside? function
local function createLocation(garageId, coords, dist, marker, onEnter, onExit, inside)
local point = lib.zones.box({
coords = coords,
size = vector3(dist, dist, GARAGE_ZONE_Z_DIST),
rotation = coords.w or 0,
garageId = garageId,
onEnter = onEnter,
onExit = onExit,
inside = inside
})
zones[#zones+1] = point
local markerPoint = lib.points.new({
coords = coords,
distance = dist * 4,
garageId = garageId
})
if not marker then return end
function markerPoint:nearby()
drawMarkerOnFrame(coords, marker)
end
zones[#zones+1] = markerPoint
end
---Runs on tick while ped is in a garage zone
---@param garageId string
---@param garageType "car"|"sea"|"air"
---@param isImpound boolean
local function pedIsInGarageZone(garageId, garageType, isImpound)
local pedIsInVehicle = cache.vehicle and GetPedInVehicleSeat(cache.vehicle, -1) == cache.ped
local prompt = isImpound and Config.OpenImpoundPrompt or (pedIsInVehicle and Config.InsertVehiclePrompt or Config.OpenGaragePrompt)
local action = function()
if pedIsInVehicle then
TriggerEvent("jg-advancedgarages:client:store-vehicle", garageId, garageType, false)
else
TriggerEvent("jg-advancedgarages:client:open-garage", garageId, garageType, false)
end
end
if inVehicle ~= pedIsInVehicle then
if Config.UseRadialMenu then
Framework.Client.RadialMenuAdd(garageId, prompt, action)
else
Framework.Client.ShowTextUI(prompt)
end
inVehicle = pedIsInVehicle
end
if Config.UseRadialMenu then return end
if IsControlJustPressed(0, isImpound and Config.OpenImpoundKeyBind or (pedIsInVehicle and Config.InsertVehicleKeyBind or Config.OpenGarageKeyBind)) then
action()
end
end
---@param garages table
local function createTargetZones(garages)
for _, ped in ipairs(peds) do
Framework.Client.RemoveTarget(ped)
end
for garageId, garage in pairs(garages) do
for _, zone in ipairs(zones) do zone:remove() end -- Remove existing zones
entity = Framework.Client.RegisterTarget(false, garage.coords, garageId, garage.type, garage.garageType)
peds[#peds+1] = entity
end
end
---@param garages table
local function createZones(garages)
for _, zone in ipairs(zones) do zone:remove() end -- Remove existing zones
for garageId, garage in pairs(garages) do
if garage then
-- Zone
createLocation(
garageId,
garage.coords,
garage.distance,
not garage.hideMarkers and garage.markers or false,
nil,
function()
if Config.UseRadialMenu then
Framework.Client.RadialMenuRemove(garageId)
else
Framework.Client.HideTextUI()
end
inVehicle = nil
end,
function()
pedIsInGarageZone(garageId, garage.type, garage.garageType == "impound")
end
)
end
end
end
local function createGarageZonesAndBlips()
for _, blip in ipairs(blips) do RemoveBlip(blip) end -- Remove existing blips
local garages = getAvailableGarageLocations()
if Config.UseTarget then
createTargetZones(garages)
else
createZones(garages)
end
for garageId, garage in pairs(garages) do
if garage then
-- Blip
if not garage.hideBlip then
local blipName = garage.garageType == "impound" and Locale.impound or garage.garageType == "job" and Locale.jobGarage or garage.garageType == "gang" and Locale.gangGarage or Locale.garage
if garage.uniqueBlips then blipName = blipName .. ": " .. garageId end
local blip = createBlip(blipName, garage.coords, garage.blip.id, garage.blip.color, garage.blip.scale)
blips[#blips + 1] = blip
end
end
end
end
RegisterNetEvent("jg-advancedgarages:client:update-blips-text-uis", function()
cachedGarageLocations = lib.callback.await("jg-advancedgarages:server:get-available-garage-locations", false)
createGarageZonesAndBlips()
end)
CreateThread(function()
Wait(2500)
createGarageZonesAndBlips()
end)
-- Delete peds in case the script restarts
AddEventHandler("onResourceStop", function(resourceName)
if (GetCurrentResourceName() == resourceName) then
for _, ped in ipairs(peds) do DeleteEntity(ped) end
end
end)