I need some help with custom traffic lights (YFT). When i put them into my server they are as weak as paper.
When you walk into them they fall over, is there any way i can make them indestructible? Or is it something i need to change inside of the XML?
Please let me know if there is a fix for this!
Greetings
PS: I saw some other topics about this but they didn’t really help me
Something like that would be achieved via adjusting the flags for those assets. If it’s a YMAP file that places the lights, use CodeWalker - that’ll be by far the most straight-forward method of adjusting flags.
These traffic lights replace the normal traffic lights spawned around the map. So they are not an YMAP.
Is it possible to add flags when replacing textures?
Off the top of my head, it should be flag “32” (that’s “static_prop” (?))
Can you send the file(s) that do that? I dont particularly understand the way you’re replacing them
Okay, this is a rather weird one, and I hate to say it but I have no idea how you’d fix that. There dont seem to be any natives that would explicitly add a specific flag to any entity (there is one for vehicles, if I understand it correctly, but there’s no way it can get used for this case)
I suppose that is a option yes, i then need to make a script that performs that function on all traffic lights. I will look into that. Thank you for the help!
local props = {
"prop_name1",
"prop_name2",
}
Citizen.CreateThread(function()
local propsHash = {}
for i=1,#props do
propsHash[GetHashKey(props[i])] = true
end
while true do
Citizen.Wait(500)
local objects = GetAllObjects()
for i=1,#objects do
if propsHash[GetEntityModel(objects[i])] then
FreezeEntityPosition(objects[i])
end
end
end
end)
Place your models in the table at top, tell me if i made misstake (not tested).
local entityEnumerator = {
__gc = function(enum)
if enum.destructor and enum.handle then
enum.destructor(enum.handle)
end
enum.destructor = nil
enum.handle = nil
end
}
local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
return coroutine.wrap(function()
local iter, id = initFunc()
if not id or id == 0 then
disposeFunc(iter)
return
end
local enum = {handle = iter, destructor = disposeFunc}
setmetatable(enum, entityEnumerator)
local next = true
repeat
coroutine.yield(id)
next, id = moveFunc(iter)
until not next
enum.destructor, enum.handle = nil, nil
disposeFunc(iter)
end)
end
function EnumerateObjects()
return EnumerateEntities(FindFirstObject, FindNextObject, EndFindObject)
end
local props = {
"prop_traffic_01a",
}
Citizen.CreateThread(function()
local propsHash = {}
for i=1,#props do
propsHash[GetHashKey(props[i])] = true
print (GetHashKey(props[i]))
end
while true do
Citizen.Wait(500)
for v in EnumerateObjects() do
if propsHash[GetEntityModel(v)] then
FreezeEntityPosition(v, true)
SetEntityCanBeDamaged(v, false)
end
end
end
end)
This work, i must use ESX functions enumerator for entities, dont known why GetAllObjects doesn’t work
But warning…
local entityEnumerator = {
__gc = function(enum)
if enum.destructor and enum.handle then
enum.destructor(enum.handle)
end
enum.destructor = nil
enum.handle = nil
end
}
local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
return coroutine.wrap(function()
local iter, id = initFunc()
if not id or id == 0 then
disposeFunc(iter)
return
end
local enum = {handle = iter, destructor = disposeFunc}
setmetatable(enum, entityEnumerator)
local next = true
repeat
coroutine.yield(id)
next, id = moveFunc(iter)
until not next
enum.destructor, enum.handle = nil, nil
disposeFunc(iter)
end)
end
function EnumerateObjects()
return EnumerateEntities(FindFirstObject, FindNextObject, EndFindObject)
end
local props = {
"prop_traffic_01a",
"prop_traffic_03a",
"prop_traffic_01b",
"prop_traffic_01d",
"prop_traffic_03b"
}
local enumeratedObjects = nil
local cachedPlayerCoords = vector3(0,0,0)
CreateThread(function()
local propsHash = {}
for i=1,#props do
propsHash[GetHashKey(props[i])] = true
-- print (GetHashKey(props[i]))
end
while true do
sleepThread = 500
local player = PlayerPedId()
local pCoords = GetEntityCoords(player)
local moveDst = #(pCoords - cachedPlayerCoords)
if moveDst >= 50.0 then
print("Triggerd")
cachedPlayerCoords = pCoords
for v in EnumerateObjects() do
if propsHash[GetEntityModel(v)] then
FreezeEntityPosition(v, true)
SetEntityCanBeDamaged(v, false)
end
end
end
Wait(sleepThread)
end
end)
It’s very performance heavy to check the close by objects every 500ms there for you should only check if the distance the player has moved is atleast above 50