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'
|
||||
|
||||
shared_scripts {
|
||||
'@ox_lib/init.lua',
|
||||
-- '@ox_lib/init.lua',
|
||||
'settings/sharedConfig.lua',
|
||||
'lib/init.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
|
||||
local dist = #(coords - entityData.oldCoords)
|
||||
if entityData.oldCoords and dist > 0.5 then
|
||||
if entityData.spawned then
|
||||
SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
end
|
||||
-- if entityData.spawned then
|
||||
-- SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
-- end
|
||||
-- ClientEntity.UpdateCoords(entityData.id, entityData.coords)
|
||||
if entityData.OnMove then
|
||||
pcall(function (...)
|
||||
@@ -167,7 +167,20 @@ end
|
||||
function ClientEntity.Set(id, key, value)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
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
|
||||
|
||||
function ClientEntity.Get(id)
|
||||
|
||||
@@ -51,7 +51,7 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
|
||||
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
|
||||
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
|
||||
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
|
||||
end
|
||||
@@ -60,7 +60,7 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
|
||||
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
|
||||
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
|
||||
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
|
||||
end
|
||||
|
||||
@@ -11,7 +11,6 @@ local ParticlesBehaviors = {
|
||||
color = vector3(255, 255, 255),
|
||||
loopLength = 5000,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ParticlesBehaviors.Start(entityData)
|
||||
@@ -76,5 +75,20 @@ function ParticlesBehaviors.OnMove(entityData)
|
||||
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)
|
||||
return ParticlesBehaviors
|
||||
@@ -11,9 +11,6 @@ function Require(modulePath, resourceName)
|
||||
|
||||
local id = resourceName .. ":" .. modulePath
|
||||
if loadedModules[id] then
|
||||
if BridgeSharedConfig.DebugLevel ~= 0 then
|
||||
print("^2 Returning cached module [" .. id .. "] ^0")
|
||||
end
|
||||
return loadedModules[id]
|
||||
end
|
||||
|
||||
@@ -45,8 +42,6 @@ cLib = {
|
||||
Prints = Prints or Require("lib/utility/shared/prints.lua"),
|
||||
Math = Math or Require("lib/utility/shared/math.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)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
Particles = {}
|
||||
Particle = {}
|
||||
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
Ids = Ids or Require("lib/utility/shared/ids.lua")
|
||||
local point = Require("lib/points/client/points.lua")
|
||||
|
||||
---Loads a ptfx asset into memory.
|
||||
---@param dict string
|
||||
---@return boolean
|
||||
@@ -26,7 +25,7 @@ end
|
||||
--- @param scale number
|
||||
--- @param color vector3
|
||||
--- @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.
|
||||
function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, removeAfter)
|
||||
LoadPtfxAsset(dict)
|
||||
@@ -93,8 +92,6 @@ function Particle.Stop(particle)
|
||||
Particles[tostring(particle)] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:Particle", function(data)
|
||||
if not data then return end
|
||||
Particle.Create(data)
|
||||
@@ -110,12 +107,12 @@ end)
|
||||
RegisterNetEvent("community_bridge:Client:ParticleRemove", function(id)
|
||||
local particle = Particles[id]
|
||||
if not particle then return end
|
||||
Particle.Remove(Drawing[id])
|
||||
Particle.Stop(id)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:ParticleRemoveBulk", function(ids)
|
||||
for _, id in pairs(ids) do
|
||||
Particle.Remove(id)
|
||||
Particle.Stop(id)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
Placeable = Placeable or {}
|
||||
Utility = Utility or Require("lib/utility/client/utility.lua")
|
||||
if not lib then Require('init.lua', 'ox_lib') end
|
||||
|
||||
local activePlacementProp = nil
|
||||
lib.locale()
|
||||
|
||||
Language = Language or Require("modules/locales/shared.lua")
|
||||
locale = Language.Locale
|
||||
-- Object placer --
|
||||
local placementText = {
|
||||
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 CELL_SIZE = 500
|
||||
|
||||
@@ -48,23 +47,11 @@ function Point.StartLoop()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
local cell = Grid.GetCellByCoords(coords)
|
||||
for _, point in pairs(cell or {}) do
|
||||
if point.isEntity then
|
||||
local entity = point.target
|
||||
if DoesEntityExist(entity) then
|
||||
local entityCoords = GetEntityCoords(entity)
|
||||
local distance = #(coords - entityCoords)
|
||||
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))
|
||||
local entity = point.target
|
||||
local targetCoords = point.isEntity and DoesEntityExist(entity) and GetEntityCoords(entity) or point.coords
|
||||
if not point.disable and targetCoords then
|
||||
targetCoords = vector3(targetCoords.x, targetCoords.y, targetCoords.z)
|
||||
local distance = #(coords - targetCoords)
|
||||
if distance < point.distance then
|
||||
if not point.inside then
|
||||
point.inside = true
|
||||
|
||||
@@ -5,6 +5,8 @@ if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (c
|
||||
|
||||
Input = {}
|
||||
|
||||
if not lib then Require('init.lua', 'ox_lib') end
|
||||
|
||||
function Input.Open(title, data, isQBFormat, submitText)
|
||||
local inputs = data.inputs
|
||||
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
|
||||
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.
|
||||
---@param id string The menu ID.
|
||||
|
||||
@@ -47,7 +47,7 @@ end
|
||||
---@return number
|
||||
Skills.GetSkillLevel = function(skillName)
|
||||
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
|
||||
return plyrSkills[skillName].level or 1
|
||||
end
|
||||
@@ -57,7 +57,7 @@ end
|
||||
---@return number
|
||||
Skills.GetXP = function(skillName)
|
||||
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
|
||||
return plyrSkills[skillName].currentXP or 1
|
||||
end
|
||||
|
||||
@@ -122,14 +122,14 @@ Target.AddModel = function(models, options)
|
||||
end
|
||||
|
||||
Target.AddBoxZone = function(name, coords, size, heading, options)
|
||||
local fixedOptions = Target.FixOptions(_options)
|
||||
local fixedOptions = Target.FixOptions(options)
|
||||
local id = Ids.RandomString()
|
||||
local title = Language.Locale("target.title")
|
||||
local title = Bridge.Language.Locale("target.title")
|
||||
local menuData = { id = id, title = title, options = {} }
|
||||
for k, v in pairs(fixedOptions) do
|
||||
table.insert(menuData.options, {
|
||||
title = title .. " " .. k,
|
||||
description = Language.Locale("target.description"),
|
||||
description = Bridge.Language.Locale("target.description"),
|
||||
onSelect = function(selected, secondary, args)
|
||||
if v.onSelect then
|
||||
v.onSelect(selected, secondary, args)
|
||||
@@ -138,28 +138,26 @@ Target.AddBoxZone = function(name, coords, size, heading, options)
|
||||
})
|
||||
end
|
||||
local inZone = false
|
||||
local test = Language.Locale("target.interact")
|
||||
Point.Register(id, coords, 5, nil, function()
|
||||
Point.Register(id, coords, 5, nil,
|
||||
function()
|
||||
local sleep = 3000
|
||||
CreateThread(function()
|
||||
while inZone do
|
||||
Wait(sleep)
|
||||
local distance = #(coords - GetEntityCoords(PlayerPedId()))
|
||||
if distance < 2 then
|
||||
sleep = 0
|
||||
Utility.Draw3DHelpText(coords, test, 0.35)
|
||||
if IsControlJustPressed(0, 38) then
|
||||
Menu.Open(menuData, false)
|
||||
end
|
||||
else
|
||||
sleep = 1000
|
||||
while inZone do
|
||||
Wait(sleep)
|
||||
local distance = #(coords - GetEntityCoords(PlayerPedId()))
|
||||
if distance < 10 then
|
||||
sleep = 0
|
||||
Utility.Draw3DHelpText(coords, Bridge.Language.Locale("target.interact"), 0.35)
|
||||
if IsControlJustPressed(0, 38) then
|
||||
Menu.Open(menuData, false)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end,
|
||||
function()
|
||||
inZone = false
|
||||
Point.Remove(id)
|
||||
end, function()
|
||||
end,
|
||||
function()
|
||||
--No need for this in this one
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
local resourceName = "ox_lib"
|
||||
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')
|
||||
|
||||
cZones = {} --conflict with ox
|
||||
|
||||
Reference in new issue
Block a user