whitespace, some documentation added
This commit is contained in:
1 parent
a3901481d4
commit
cad3604e4d
3 files changed
+51
-30
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
function CreateParticleFX(dict, ptfx, pos, rot, scale, color, looped, loopLength)
|
function CreateParticleFX(dict, ptfx, pos, rot, scale, color, looped, loopLength)
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local failed = 5
|
local failed = 5
|
||||||
@@ -45,8 +44,6 @@ function CreateParticleFXOnEntityBone(dict, ptfx, entity, bone, offset, rot, sc
|
|||||||
return bleh
|
return bleh
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function PlayParticleFX(dict, name, looped, x, y, z, rotX, rotY, rotZ, scale)
|
function PlayParticleFX(dict, name, looped, x, y, z, rotX, rotY, rotZ, scale)
|
||||||
RequestNamedPtfxAsset(dict)
|
RequestNamedPtfxAsset(dict)
|
||||||
while not HasNamedPtfxAssetLoaded(dict) do
|
while not HasNamedPtfxAssetLoaded(dict) do
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, sett
|
|||||||
{type = "SET_BACKGROUND_COLOUR"},
|
{type = "SET_BACKGROUND_COLOUR"},
|
||||||
})
|
})
|
||||||
local heading = -GetEntityHeading(PlayerPedId())
|
local heading = -GetEntityHeading(PlayerPedId())
|
||||||
|
|
||||||
local pos = PlaceableObject.Eyetrace(depth, disableSphere)
|
local pos = PlaceableObject.Eyetrace(depth, disableSphere)
|
||||||
if not data.spawned and model then
|
if not data.spawned and model then
|
||||||
--get player heading
|
--get player heading
|
||||||
@@ -81,7 +81,7 @@ function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, sett
|
|||||||
assert(data.spawned, "Failed to create object")
|
assert(data.spawned, "Failed to create object")
|
||||||
SetEntityCollision(data.spawned, false, false)
|
SetEntityCollision(data.spawned, false, false)
|
||||||
SetEntityAlpha(data.spawned, 150, false)
|
SetEntityAlpha(data.spawned, 150, false)
|
||||||
|
|
||||||
SetPedConfigFlag(PlayerPedId(), 146, true)
|
SetPedConfigFlag(PlayerPedId(), 146, true)
|
||||||
SetCanClimbOnEntity(data.spawned, false)
|
SetCanClimbOnEntity(data.spawned, false)
|
||||||
SetEntityCompletelyDisableCollision(data.spawned, true, false)
|
SetEntityCompletelyDisableCollision(data.spawned, true, false)
|
||||||
@@ -96,7 +96,7 @@ function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, sett
|
|||||||
inBounds = true
|
inBounds = true
|
||||||
SetEntityDrawOutlineColor(0, 255, 0, 255)
|
SetEntityDrawOutlineColor(0, 255, 0, 255)
|
||||||
SetEntityDrawOutline(data.spawned, true)
|
SetEntityDrawOutline(data.spawned, true)
|
||||||
end
|
end
|
||||||
elseif inBounds then
|
elseif inBounds then
|
||||||
inBounds = false
|
inBounds = false
|
||||||
SetEntityDrawOutline(data.spawned, false)
|
SetEntityDrawOutline(data.spawned, false)
|
||||||
@@ -113,7 +113,7 @@ function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, sett
|
|||||||
DisableControlAction(0, 24, true) -- Attack
|
DisableControlAction(0, 24, true) -- Attack
|
||||||
DisableControlAction(0, 25, true) -- Aim
|
DisableControlAction(0, 25, true) -- Aim
|
||||||
DisableControlAction(0, 36, true) -- INPUT_DUCK.
|
DisableControlAction(0, 36, true) -- INPUT_DUCK.
|
||||||
|
|
||||||
if IsDisabledControlJustPressed(0, 223) then -- left click
|
if IsDisabledControlJustPressed(0, 223) then -- left click
|
||||||
if not inBounds then
|
if not inBounds then
|
||||||
Notify.SendNotify("You can't place this object here", "error", 5000)
|
Notify.SendNotify("You can't place this object here", "error", 5000)
|
||||||
@@ -190,6 +190,4 @@ function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, sett
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return PlaceableObject
|
return PlaceableObject
|
||||||
|
|
||||||
|
|
||||||
+46
-20
@@ -11,52 +11,58 @@ local CELL_BUFFER = 1 -- Number of adjacent cells to check
|
|||||||
-- Consider adding these optimizations
|
-- Consider adding these optimizations
|
||||||
local ADAPTIVE_WAIT = true -- Adjust wait time based on player speed
|
local ADAPTIVE_WAIT = true -- Adjust wait time based on player speed
|
||||||
|
|
||||||
|
---This is an internal function, do not call this externally
|
||||||
function Point.GetCellKey(coords)
|
function Point.GetCellKey(coords)
|
||||||
local cellX = math.floor(coords.x / GRID_SIZE)
|
local cellX = math.floor(coords.x / GRID_SIZE)
|
||||||
local cellY = math.floor(coords.y / GRID_SIZE)
|
local cellY = math.floor(coords.y / GRID_SIZE)
|
||||||
return cellX .. ":" .. cellY
|
return cellX .. ":" .. cellY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This is an internal function, do not call this externally
|
||||||
function Point.RegisterInGrid(point)
|
function Point.RegisterInGrid(point)
|
||||||
local cellKey = Point.GetCellKey(point.coords)
|
local cellKey = Point.GetCellKey(point.coords)
|
||||||
|
|
||||||
-- Initialize cell if it doesn't exist
|
-- Initialize cell if it doesn't exist
|
||||||
GridCells[cellKey] = GridCells[cellKey] or {
|
GridCells[cellKey] = GridCells[cellKey] or {
|
||||||
points = {},
|
points = {},
|
||||||
count = 0
|
count = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Add point to cell
|
-- Add point to cell
|
||||||
GridCells[cellKey].points[point.id] = point
|
GridCells[cellKey].points[point.id] = point
|
||||||
GridCells[cellKey].count = GridCells[cellKey].count + 1
|
GridCells[cellKey].count = GridCells[cellKey].count + 1
|
||||||
|
|
||||||
-- Store cell reference in point
|
-- Store cell reference in point
|
||||||
point.cellKey = cellKey
|
point.cellKey = cellKey
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This is an internal function, do not call this externally
|
||||||
function Point.UpdateInGrid(point, oldCellKey)
|
function Point.UpdateInGrid(point, oldCellKey)
|
||||||
-- Remove from old cell if cell key changed
|
-- Remove from old cell if cell key changed
|
||||||
if oldCellKey and oldCellKey ~= point.cellKey then
|
if oldCellKey and oldCellKey ~= point.cellKey then
|
||||||
if GridCells[oldCellKey] and GridCells[oldCellKey].points[point.id] then
|
if GridCells[oldCellKey] and GridCells[oldCellKey].points[point.id] then
|
||||||
GridCells[oldCellKey].points[point.id] = nil
|
GridCells[oldCellKey].points[point.id] = nil
|
||||||
GridCells[oldCellKey].count = GridCells[oldCellKey].count - 1
|
GridCells[oldCellKey].count = GridCells[oldCellKey].count - 1
|
||||||
|
|
||||||
-- Clean up empty cells
|
-- Clean up empty cells
|
||||||
if GridCells[oldCellKey].count <= 0 then
|
if GridCells[oldCellKey].count <= 0 then
|
||||||
GridCells[oldCellKey] = nil
|
GridCells[oldCellKey] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add to new cell
|
-- Add to new cell
|
||||||
Point.RegisterInGrid(point)
|
Point.RegisterInGrid(point)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Gets nearby cells based on the coords
|
||||||
|
---@param coords table
|
||||||
|
---@return table
|
||||||
function Point.GetNearbyCells(coords)
|
function Point.GetNearbyCells(coords)
|
||||||
local cellX = math.floor(coords.x / GRID_SIZE)
|
local cellX = math.floor(coords.x / GRID_SIZE)
|
||||||
local cellY = math.floor(coords.y / GRID_SIZE)
|
local cellY = math.floor(coords.y / GRID_SIZE)
|
||||||
local nearbyCells = {}
|
local nearbyCells = {}
|
||||||
|
|
||||||
-- Get current and adjacent cells
|
-- Get current and adjacent cells
|
||||||
for x = cellX - CELL_BUFFER, cellX + CELL_BUFFER do
|
for x = cellX - CELL_BUFFER, cellX + CELL_BUFFER do
|
||||||
for y = cellY - CELL_BUFFER, cellY + CELL_BUFFER do
|
for y = cellY - CELL_BUFFER, cellY + CELL_BUFFER do
|
||||||
@@ -66,14 +72,18 @@ function Point.GetNearbyCells(coords)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nearbyCells
|
return nearbyCells
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Returns all points in the same cell as the given point
|
||||||
|
---This will require you to pass the point object
|
||||||
|
---@param point table
|
||||||
|
---@return table
|
||||||
function Point.CheckPointsInSameCell(point)
|
function Point.CheckPointsInSameCell(point)
|
||||||
local cellKey = point.cellKey
|
local cellKey = point.cellKey
|
||||||
if not GridCells[cellKey] then return {} end
|
if not GridCells[cellKey] then return {} end
|
||||||
|
|
||||||
local nearbyPoints = {}
|
local nearbyPoints = {}
|
||||||
for id, otherPoint in pairs(GridCells[cellKey].points) do
|
for id, otherPoint in pairs(GridCells[cellKey].points) do
|
||||||
if id ~= point.id then
|
if id ~= point.id then
|
||||||
@@ -83,14 +93,15 @@ function Point.CheckPointsInSameCell(point)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nearbyPoints
|
return nearbyPoints
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Internal function that starts the loop. Do not call this function directly.
|
||||||
function Point.StartLoop()
|
function Point.StartLoop()
|
||||||
if LoopStarted then return false end
|
if LoopStarted then return false end
|
||||||
LoopStarted = true
|
LoopStarted = true
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while LoopStarted do
|
while LoopStarted do
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
@@ -102,7 +113,7 @@ function Point.StartLoop()
|
|||||||
local targetsExist = false
|
local targetsExist = false
|
||||||
local playerCellKey = Point.GetCellKey(playerCoords)
|
local playerCellKey = Point.GetCellKey(playerCoords)
|
||||||
local nearbyCells = Point.GetNearbyCells(playerCoords)
|
local nearbyCells = Point.GetNearbyCells(playerCoords)
|
||||||
|
|
||||||
local playerSpeed = GetEntitySpeed(playerPed)
|
local playerSpeed = GetEntitySpeed(playerPed)
|
||||||
local maxWeight = 1000
|
local maxWeight = 1000
|
||||||
local waitTime = ADAPTIVE_WAIT and math.max(maxWeight/10, maxWeight - playerSpeed * maxWeight/10) or maxWeight
|
local waitTime = ADAPTIVE_WAIT and math.max(maxWeight/10, maxWeight - playerSpeed * maxWeight/10) or maxWeight
|
||||||
@@ -111,7 +122,7 @@ function Point.StartLoop()
|
|||||||
if GridCells[cellKey] then
|
if GridCells[cellKey] then
|
||||||
for id, point in pairs(GridCells[cellKey].points) do
|
for id, point in pairs(GridCells[cellKey].points) do
|
||||||
targetsExist = true
|
targetsExist = true
|
||||||
|
|
||||||
-- Update entity position if needed
|
-- Update entity position if needed
|
||||||
local oldCellKey = point.cellKey
|
local oldCellKey = point.cellKey
|
||||||
if point.isEntity then
|
if point.isEntity then
|
||||||
@@ -119,9 +130,9 @@ function Point.StartLoop()
|
|||||||
point.cellKey = Point.GetCellKey(point.coords)
|
point.cellKey = Point.GetCellKey(point.coords)
|
||||||
Point.UpdateInGrid(point, oldCellKey)
|
Point.UpdateInGrid(point, oldCellKey)
|
||||||
end
|
end
|
||||||
|
|
||||||
local distance = #(playerCoords - point.coords)
|
local distance = #(playerCoords - point.coords)
|
||||||
|
|
||||||
-- Check if player entered/exited the point
|
-- Check if player entered/exited the point
|
||||||
if distance < point.distance then
|
if distance < point.distance then
|
||||||
if not point.inside then
|
if not point.inside then
|
||||||
@@ -134,7 +145,7 @@ function Point.StartLoop()
|
|||||||
point.inside = false
|
point.inside = false
|
||||||
point.onExit(point)
|
point.onExit(point)
|
||||||
end
|
end
|
||||||
if point.onNearby then
|
if point.onNearby then
|
||||||
point.onNearby(GridCells[cellKey]?.points, waitTime)
|
point.onNearby(GridCells[cellKey]?.points, waitTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -152,8 +163,16 @@ function Point.StartLoop()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Create a point based on a vector or entityID
|
||||||
|
---@param id string
|
||||||
|
---@param target number || vector3
|
||||||
|
---@param distance number
|
||||||
|
---@param _onEnter function
|
||||||
|
---@param _onExit function
|
||||||
|
---@param _onNearby function
|
||||||
|
---@param data self
|
||||||
|
---@return table
|
||||||
function Point.Register(id, target, distance, _onEnter, _onExit, _onNearby, data)
|
function Point.Register(id, target, distance, _onEnter, _onExit, _onNearby, data)
|
||||||
|
|
||||||
local isEntity = type(target) == "number"
|
local isEntity = type(target) == "number"
|
||||||
local coords = isEntity and GetEntityCoords(target) or target
|
local coords = isEntity and GetEntityCoords(target) or target
|
||||||
|
|
||||||
@@ -174,6 +193,8 @@ function Point.Register(id, target, distance, _onEnter, _onExit, _onNearby, data
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Remove an exsisting point by its id
|
||||||
|
---@param id string
|
||||||
function Point.Remove(id)
|
function Point.Remove(id)
|
||||||
local point = ActivePoints[id]
|
local point = ActivePoints[id]
|
||||||
if point then
|
if point then
|
||||||
@@ -181,25 +202,31 @@ function Point.Remove(id)
|
|||||||
if GridCells[cellKey] and GridCells[cellKey].points[id] then
|
if GridCells[cellKey] and GridCells[cellKey].points[id] then
|
||||||
GridCells[cellKey].points[id] = nil
|
GridCells[cellKey].points[id] = nil
|
||||||
GridCells[cellKey].count = GridCells[cellKey].count - 1
|
GridCells[cellKey].count = GridCells[cellKey].count - 1
|
||||||
|
|
||||||
if GridCells[cellKey].count <= 0 then
|
if GridCells[cellKey].count <= 0 then
|
||||||
GridCells[cellKey] = nil
|
GridCells[cellKey] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ActivePoints[id] = nil
|
ActivePoints[id] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Returnes a point by its id
|
||||||
|
---@param id string
|
||||||
|
---@return table
|
||||||
function Point.Get(id)
|
function Point.Get(id)
|
||||||
return ActivePoints[id]
|
return ActivePoints[id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Returns all points
|
||||||
|
---@return table
|
||||||
function Point.GetAll()
|
function Point.GetAll()
|
||||||
return ActivePoints
|
return ActivePoints
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Usage example for checking nearby points
|
-- Usage example for checking nearby points
|
||||||
|
-- This is fucking hot. +20 points for crowley
|
||||||
--[[
|
--[[
|
||||||
Point.Register("point1", vector3(100, 100, 30), 5.0,
|
Point.Register("point1", vector3(100, 100, 30), 5.0,
|
||||||
function(point)
|
function(point)
|
||||||
@@ -217,5 +244,4 @@ Point.Register("point1", vector3(100, 100, 30), 5.0,
|
|||||||
)
|
)
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
return Point
|
return Point
|
||||||
|
|
||||||
Reference in new issue
Block a user