Merge pull request #165 from TheOrderFivem/crowleys
This was crowleys commit and work - Refactor entity behaviors and imp…
This commit is contained in:
13 files changed
+71
-64
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ description 'A Universal Bridge for Our Community, created by a group of contrib
|
|||||||
version '0.13.0'
|
version '0.13.0'
|
||||||
|
|
||||||
shared_scripts {
|
shared_scripts {
|
||||||
'@ox_lib/init.lua',
|
-- '@ox_lib/init.lua',
|
||||||
'settings/sharedConfig.lua',
|
'settings/sharedConfig.lua',
|
||||||
'lib/init.lua',
|
'lib/init.lua',
|
||||||
'modules/locales/*.lua',
|
'modules/locales/*.lua',
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ local function UpdateEntity(_entityData)
|
|||||||
entityData.oldCoords = entityData.oldCoords and vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) or coords
|
entityData.oldCoords = entityData.oldCoords and vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) or coords
|
||||||
local dist = #(coords - entityData.oldCoords)
|
local dist = #(coords - entityData.oldCoords)
|
||||||
if entityData.oldCoords and dist > 0.5 then
|
if entityData.oldCoords and dist > 0.5 then
|
||||||
if entityData.spawned then
|
-- if entityData.spawned then
|
||||||
SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, false)
|
-- SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, false)
|
||||||
end
|
-- end
|
||||||
-- ClientEntity.UpdateCoords(entityData.id, entityData.coords)
|
-- ClientEntity.UpdateCoords(entityData.id, entityData.coords)
|
||||||
if entityData.OnMove then
|
if entityData.OnMove then
|
||||||
pcall(function (...)
|
pcall(function (...)
|
||||||
@@ -167,7 +167,20 @@ end
|
|||||||
function ClientEntity.Set(id, key, value)
|
function ClientEntity.Set(id, key, value)
|
||||||
local entityData = ClientEntity.Get(id)
|
local entityData = ClientEntity.Get(id)
|
||||||
if not entityData then return print(string.format("[ClientEntity] SetKey: Entity %s does not exist", id)) end
|
if not entityData then return print(string.format("[ClientEntity] SetKey: Entity %s does not exist", id)) end
|
||||||
entityData[key] = value
|
local oldData = entityData[key]
|
||||||
|
if oldData == value then return end
|
||||||
|
if entityData.OnSet then
|
||||||
|
pcall(function (...)
|
||||||
|
return entityData.OnSet(entityData, key, value, oldData)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
if value then
|
||||||
|
entityData[key] = value
|
||||||
|
Behaviors.Trigger("OnSet", entityData, key, value, oldData)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
Behaviors.Trigger("OnSet", entityData, key, value, oldData)
|
||||||
|
entityData[key] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function ClientEntity.Get(id)
|
function ClientEntity.Get(id)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
|
|||||||
for property, behavior in pairs(Behaviors.All[invoking] or {}) do
|
for property, behavior in pairs(Behaviors.All[invoking] or {}) do
|
||||||
local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property
|
local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property
|
||||||
if hasBehaviorArgs and behavior[actionName] then
|
if hasBehaviorArgs and behavior[actionName] then
|
||||||
local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...)
|
local success, result = pcall(behavior[actionName], clientEntityData, ...)
|
||||||
if not success then
|
if not success then
|
||||||
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
|
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
|
||||||
end
|
end
|
||||||
@@ -60,7 +60,7 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
|
|||||||
for property, behavior in pairs(Behaviors.All['community_bridge'] or {}) do
|
for property, behavior in pairs(Behaviors.All['community_bridge'] or {}) do
|
||||||
local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property
|
local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property
|
||||||
if hasBehaviorArgs and behavior[actionName] and not Behaviors.All[invoking]?[actionName] then
|
if hasBehaviorArgs and behavior[actionName] and not Behaviors.All[invoking]?[actionName] then
|
||||||
local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...)
|
local success, result = pcall(behavior[actionName], clientEntityData, ...)
|
||||||
if not success then
|
if not success then
|
||||||
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
|
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ local ParticlesBehaviors = {
|
|||||||
color = vector3(255, 255, 255),
|
color = vector3(255, 255, 255),
|
||||||
loopLength = 5000,
|
loopLength = 5000,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ParticlesBehaviors.Start(entityData)
|
function ParticlesBehaviors.Start(entityData)
|
||||||
@@ -76,5 +75,20 @@ function ParticlesBehaviors.OnMove(entityData)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ParticlesBehaviors.OnSet(entityData, key, value, oldValue)
|
||||||
|
if key ~= "particles" then return end
|
||||||
|
if oldValue then
|
||||||
|
ParticlesBehaviors.OnRemove(entityData)
|
||||||
|
end
|
||||||
|
if value then
|
||||||
|
if value.dict then -- single particle
|
||||||
|
entityData.particles = {value}
|
||||||
|
else
|
||||||
|
entityData.particles = value
|
||||||
|
end
|
||||||
|
ParticlesBehaviors.Start(entityData)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Bridge.Entity.RegisterBehavior("particles", ParticlesBehaviors)
|
Bridge.Entity.RegisterBehavior("particles", ParticlesBehaviors)
|
||||||
return ParticlesBehaviors
|
return ParticlesBehaviors
|
||||||
@@ -11,9 +11,6 @@ function Require(modulePath, resourceName)
|
|||||||
|
|
||||||
local id = resourceName .. ":" .. modulePath
|
local id = resourceName .. ":" .. modulePath
|
||||||
if loadedModules[id] then
|
if loadedModules[id] then
|
||||||
if BridgeSharedConfig.DebugLevel ~= 0 then
|
|
||||||
print("^2 Returning cached module [" .. id .. "] ^0")
|
|
||||||
end
|
|
||||||
return loadedModules[id]
|
return loadedModules[id]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,8 +42,6 @@ cLib = {
|
|||||||
Prints = Prints or Require("lib/utility/shared/prints.lua"),
|
Prints = Prints or Require("lib/utility/shared/prints.lua"),
|
||||||
Math = Math or Require("lib/utility/shared/math.lua"),
|
Math = Math or Require("lib/utility/shared/math.lua"),
|
||||||
LA = LA or Require("lib/utility/shared/la.lua")
|
LA = LA or Require("lib/utility/shared/la.lua")
|
||||||
-- Zones = Poly or Require("lib/zones/shared/zones.lua"),
|
|
||||||
-- Action = Action or Require("lib/entities/shared/actions.lua"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports('cLib', cLib)
|
exports('cLib', cLib)
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
Particles = {}
|
Particles = {}
|
||||||
Particle = {}
|
Particle = {}
|
||||||
|
|
||||||
---@diagnostic disable: duplicate-set-field
|
---@diagnostic disable: duplicate-set-field
|
||||||
Ids = Ids or Require("lib/utility/shared/ids.lua")
|
Ids = Ids or Require("lib/utility/shared/ids.lua")
|
||||||
local point = Require("lib/points/client/points.lua")
|
|
||||||
|
|
||||||
---Loads a ptfx asset into memory.
|
---Loads a ptfx asset into memory.
|
||||||
---@param dict string
|
---@param dict string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
@@ -26,7 +25,7 @@ end
|
|||||||
--- @param scale number
|
--- @param scale number
|
||||||
--- @param color vector3
|
--- @param color vector3
|
||||||
--- @param looped boolean
|
--- @param looped boolean
|
||||||
--- @param loopLength number|nil
|
--- @param removeAfter number|nil
|
||||||
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
|
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
|
||||||
function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, removeAfter)
|
function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, removeAfter)
|
||||||
LoadPtfxAsset(dict)
|
LoadPtfxAsset(dict)
|
||||||
@@ -93,8 +92,6 @@ function Particle.Stop(particle)
|
|||||||
Particles[tostring(particle)] = nil
|
Particles[tostring(particle)] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RegisterNetEvent("community_bridge:Client:Particle", function(data)
|
RegisterNetEvent("community_bridge:Client:Particle", function(data)
|
||||||
if not data then return end
|
if not data then return end
|
||||||
Particle.Create(data)
|
Particle.Create(data)
|
||||||
@@ -110,12 +107,12 @@ end)
|
|||||||
RegisterNetEvent("community_bridge:Client:ParticleRemove", function(id)
|
RegisterNetEvent("community_bridge:Client:ParticleRemove", function(id)
|
||||||
local particle = Particles[id]
|
local particle = Particles[id]
|
||||||
if not particle then return end
|
if not particle then return end
|
||||||
Particle.Remove(Drawing[id])
|
Particle.Stop(id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("community_bridge:Client:ParticleRemoveBulk", function(ids)
|
RegisterNetEvent("community_bridge:Client:ParticleRemoveBulk", function(ids)
|
||||||
for _, id in pairs(ids) do
|
for _, id in pairs(ids) do
|
||||||
Particle.Remove(id)
|
Particle.Stop(id)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
Placeable = Placeable or {}
|
Placeable = Placeable or {}
|
||||||
Utility = Utility or Require("lib/utility/client/utility.lua")
|
Utility = Utility or Require("lib/utility/client/utility.lua")
|
||||||
|
if not lib then Require('init.lua', 'ox_lib') end
|
||||||
|
|
||||||
local activePlacementProp = nil
|
local activePlacementProp = nil
|
||||||
lib.locale()
|
Language = Language or Require("modules/locales/shared.lua")
|
||||||
|
locale = Language.Locale
|
||||||
-- Object placer --
|
-- Object placer --
|
||||||
local placementText = {
|
local placementText = {
|
||||||
locale('placeable_object.place_object_place'),
|
locale('placeable_object.place_object_place'),
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
local GRIDE_SIZE_X = 8968.83
|
||||||
local GRIDE_SIZE_X = 8968.83
|
|
||||||
local GRIDE_SIZE_Y = 126200.40
|
local GRIDE_SIZE_Y = 126200.40
|
||||||
local CELL_SIZE = 500
|
local CELL_SIZE = 500
|
||||||
|
|
||||||
@@ -48,23 +47,11 @@ function Point.StartLoop()
|
|||||||
local coords = GetEntityCoords(playerPed)
|
local coords = GetEntityCoords(playerPed)
|
||||||
local cell = Grid.GetCellByCoords(coords)
|
local cell = Grid.GetCellByCoords(coords)
|
||||||
for _, point in pairs(cell or {}) do
|
for _, point in pairs(cell or {}) do
|
||||||
if point.isEntity then
|
local entity = point.target
|
||||||
local entity = point.target
|
local targetCoords = point.isEntity and DoesEntityExist(entity) and GetEntityCoords(entity) or point.coords
|
||||||
if DoesEntityExist(entity) then
|
if not point.disable and targetCoords then
|
||||||
local entityCoords = GetEntityCoords(entity)
|
targetCoords = vector3(targetCoords.x, targetCoords.y, targetCoords.z)
|
||||||
local distance = #(coords - entityCoords)
|
local distance = #(coords - targetCoords)
|
||||||
if distance < point.distance then
|
|
||||||
if not point.inside then
|
|
||||||
point.inside = true
|
|
||||||
point.args = point?.onEnter(point, point.args) or point.args
|
|
||||||
end
|
|
||||||
elseif point.inside then
|
|
||||||
point.inside = false
|
|
||||||
point.args = point?.onExit(point, point.args) or point.args
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local distance = #(vector3(coords.x, coords.y, coords.z) - vector3(point.coords.x, point.coords.y, point.coords.z))
|
|
||||||
if distance < point.distance then
|
if distance < point.distance then
|
||||||
if not point.inside then
|
if not point.inside then
|
||||||
point.inside = true
|
point.inside = true
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (c
|
|||||||
|
|
||||||
Input = {}
|
Input = {}
|
||||||
|
|
||||||
|
if not lib then Require('init.lua', 'ox_lib') end
|
||||||
|
|
||||||
function Input.Open(title, data, isQBFormat, submitText)
|
function Input.Open(title, data, isQBFormat, submitText)
|
||||||
local inputs = data.inputs
|
local inputs = data.inputs
|
||||||
if isQBFormat then
|
if isQBFormat then
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local configValue = BridgeClientConfig.MenuSystem
|
|||||||
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
|
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
|
||||||
Menus = Menus or {}
|
Menus = Menus or {}
|
||||||
|
|
||||||
lib = lib or Require("init.lua", "ox_lib")
|
if not lib then Require('init.lua', 'ox_lib') end
|
||||||
|
|
||||||
---Converts a QB menu to an Ox menu.
|
---Converts a QB menu to an Ox menu.
|
||||||
---@param id string The menu ID.
|
---@param id string The menu ID.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ end
|
|||||||
---@return number
|
---@return number
|
||||||
Skills.GetSkillLevel = function(skillName)
|
Skills.GetSkillLevel = function(skillName)
|
||||||
if not skillName then return 0 end
|
if not skillName then return 0 end
|
||||||
local plyrSkills = Framework.GetPlayerMetaData("community_bridge_skills")
|
local plyrSkills = Bridge.Framework.GetPlayerMetaData("community_bridge_skills")
|
||||||
if not plyrSkills or not plyrSkills[skillName] then return 1 end
|
if not plyrSkills or not plyrSkills[skillName] then return 1 end
|
||||||
return plyrSkills[skillName].level or 1
|
return plyrSkills[skillName].level or 1
|
||||||
end
|
end
|
||||||
@@ -57,7 +57,7 @@ end
|
|||||||
---@return number
|
---@return number
|
||||||
Skills.GetXP = function(skillName)
|
Skills.GetXP = function(skillName)
|
||||||
if not skillName then return 0 end
|
if not skillName then return 0 end
|
||||||
local plyrSkills = Framework.GetPlayerMetaData("community_bridge_skills")
|
local plyrSkills = Bridge.Framework.GetPlayerMetaData("community_bridge_skills")
|
||||||
if not plyrSkills or not plyrSkills[skillName] then return 1 end
|
if not plyrSkills or not plyrSkills[skillName] then return 1 end
|
||||||
return plyrSkills[skillName].currentXP or 1
|
return plyrSkills[skillName].currentXP or 1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -122,14 +122,14 @@ Target.AddModel = function(models, options)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Target.AddBoxZone = function(name, coords, size, heading, options)
|
Target.AddBoxZone = function(name, coords, size, heading, options)
|
||||||
local fixedOptions = Target.FixOptions(_options)
|
local fixedOptions = Target.FixOptions(options)
|
||||||
local id = Ids.RandomString()
|
local id = Ids.RandomString()
|
||||||
local title = Language.Locale("target.title")
|
local title = Bridge.Language.Locale("target.title")
|
||||||
local menuData = { id = id, title = title, options = {} }
|
local menuData = { id = id, title = title, options = {} }
|
||||||
for k, v in pairs(fixedOptions) do
|
for k, v in pairs(fixedOptions) do
|
||||||
table.insert(menuData.options, {
|
table.insert(menuData.options, {
|
||||||
title = title .. " " .. k,
|
title = title .. " " .. k,
|
||||||
description = Language.Locale("target.description"),
|
description = Bridge.Language.Locale("target.description"),
|
||||||
onSelect = function(selected, secondary, args)
|
onSelect = function(selected, secondary, args)
|
||||||
if v.onSelect then
|
if v.onSelect then
|
||||||
v.onSelect(selected, secondary, args)
|
v.onSelect(selected, secondary, args)
|
||||||
@@ -138,28 +138,26 @@ Target.AddBoxZone = function(name, coords, size, heading, options)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
local inZone = false
|
local inZone = false
|
||||||
local test = Language.Locale("target.interact")
|
Point.Register(id, coords, 5, nil,
|
||||||
Point.Register(id, coords, 5, nil, function()
|
function()
|
||||||
local sleep = 3000
|
local sleep = 3000
|
||||||
CreateThread(function()
|
while inZone do
|
||||||
while inZone do
|
Wait(sleep)
|
||||||
Wait(sleep)
|
local distance = #(coords - GetEntityCoords(PlayerPedId()))
|
||||||
local distance = #(coords - GetEntityCoords(PlayerPedId()))
|
if distance < 10 then
|
||||||
if distance < 2 then
|
sleep = 0
|
||||||
sleep = 0
|
Utility.Draw3DHelpText(coords, Bridge.Language.Locale("target.interact"), 0.35)
|
||||||
Utility.Draw3DHelpText(coords, test, 0.35)
|
if IsControlJustPressed(0, 38) then
|
||||||
if IsControlJustPressed(0, 38) then
|
Menu.Open(menuData, false)
|
||||||
Menu.Open(menuData, false)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
sleep = 1000
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
|
inZone = false
|
||||||
Point.Remove(id)
|
Point.Remove(id)
|
||||||
end, function()
|
end,
|
||||||
|
function()
|
||||||
--No need for this in this one
|
--No need for this in this one
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
---@diagnostic disable: duplicate-set-field
|
---@diagnostic disable: duplicate-set-field
|
||||||
local resourceName = "ox_lib"
|
local resourceName = "ox_lib"
|
||||||
if GetResourceState(resourceName) == 'missing' then return end
|
if GetResourceState(resourceName) == 'missing' then return end
|
||||||
lib = lib or Require("init.lua", "ox_lib")
|
if not lib then Require('init.lua', 'ox_lib') end
|
||||||
Ids = Ids or Require('lib/utility/shared/ids.lua')
|
Ids = Ids or Require('lib/utility/shared/ids.lua')
|
||||||
|
|
||||||
cZones = {} --conflict with ox
|
cZones = {} --conflict with ox
|
||||||
|
|||||||
Reference in new issue
Block a user