[Free] [Snippet] Let There Be Light

Simple snippet / client side script that allows you to define a specified prop and light source / coordinate during a city blackout. I use this in a survival server type environment.

(GitHub - FiveMLuxe/LightByCoord: Allows you to define light sources at specific locations during a city blackout.)

6 Likes

wow nice! i was trying to make this but then with a radius so that you dont have to set a prop for the greenzone. do you now how to get that to work?

hello I didn’t understand if the generator prop must already be in the map or is it put when you put the coordinates nice client?

I mean you can place a prop with some other code, or just use it for lamp posts already in the city etc.

Just use any random prop inside your safe zone or place a tiny prop in the middle of your safe zone and increase the radius in my snippet

local propModel = “prop_name” – Replace with the actual prop model name or hash
local x, y, z = 123.45, 67.89, 100.0 – Replace with the desired coordinates

local prop = CreateObject(GetHashKey(propModel), x, y, z, true, true, true)

SetEntityAsMissionEntity(prop, true, true)
SetEntityDynamic(prop, true)

use this to create prop

I tried to add the piece to insert the prop but it doesn’t work…

show what you did

local excludedProps = {
{
hash = GetHashKey(“prop_generator_03b”),
coords = vector3(1990.11, 3065.89, 47.03),
},

}
function ApplyBlackoutExceptForProps()
Citizen.CreateThread(function()
while true do
for i = 1, #excludedProps do
local propInfo = excludedProps[i]
local hash = propInfo.hash
local coords = propInfo.coords
local lightEntity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 30.0, hash, false, false, false)
if DoesEntityExist(lightEntity) then
local forwardVector = GetEntityForwardVector(lightEntity)
DrawSpotLightWithShadow(
coords.x, coords.y, coords.z,
forwardVector.x, forwardVector.y, forwardVector.z,
255, 255, 190, 12.0, 1.0, 0.0, 80.0, 10.0
)
DrawLightWithRange(
coords.x, coords.y, coords.z,
255, 255, 190, 0.1, 20.0
)
end
end
Citizen.Wait(0)
end
end)
end
ApplyBlackoutExceptForProps()

local propModel = “prop_generator_03b” –- Replace with the actual prop model name or hash
local x, y, z = 1990.11, 3065.89, 47.03 –- Replace with the desired coordinates

local prop = CreateObject(GetHashKey(propModel), x, y, z, true, true, true)

SetEntityAsMissionEntity(prop, true, true)
SetEntityDynamic(prop, true)

Here, use this taken direct from my server:


local propModel = "prop_tool_bench02_ld"
local propCoords = vector3(1451.5715332031,6359.8071289063,22.843645095825)

-- Spawn the prop
Citizen.CreateThread(function()
    local prop = CreateObject(GetHashKey(propModel), propCoords.x, propCoords.y, propCoords.z, true, true, true)
    SetEntityAsMissionEntity(prop, true, true)
    SetEntityHeading(prop, 0.0)
    FreezeEntityPosition(prop, true)
end)

ok but with this piece and that’s it, does the light come on during the blackout?

Using this but changing the coordinates to fit your needs will make the prop spawn and create light.

local propModel = "prop_generator_03b"
local propCoords = vector3(1451.5715332031,6359.8071289063,22.843645095825)

-- Spawn the prop
Citizen.CreateThread(function()
    local prop = CreateObject(GetHashKey(propModel), propCoords.x, propCoords.y, propCoords.z, true, true, true)
    SetEntityAsMissionEntity(prop, true, true)
    SetEntityHeading(prop, 0.0)
    FreezeEntityPosition(prop, true)
end)



local excludedProps = {
{
hash = GetHashKey(“prop_generator_03b”),
coords = vector3(1990.11, 3065.89, 47.03),
},

}
function ApplyBlackoutExceptForProps()
Citizen.CreateThread(function()
while true do
for i = 1, #excludedProps do
local propInfo = excludedProps[i]
local hash = propInfo.hash
local coords = propInfo.coords
local lightEntity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 30.0, hash, false, false, false)
if DoesEntityExist(lightEntity) then
local forwardVector = GetEntityForwardVector(lightEntity)
DrawSpotLightWithShadow(
coords.x, coords.y, coords.z,
forwardVector.x, forwardVector.y, forwardVector.z,
255, 255, 190, 12.0, 1.0, 0.0, 80.0, 10.0
)
DrawLightWithRange(
coords.x, coords.y, coords.z,
255, 255, 190, 0.1, 20.0
)
end
end
Citizen.Wait(0)
end
end)
end
ApplyBlackoutExceptForProps()

Doesn’t work

doesnt work for me

used the basic script with the yellowjack pole but it doesn’t work—

local excludedProps = {
{
hash = GetHashKey(“prop_oldlight_01a”),
coords = vector3(1995.47, 3067.93, 47.21),
},

}
function ApplyBlackoutExceptForProps()
Citizen.CreateThread(function()
while true do
for i = 1, #excludedProps do
local propInfo = excludedProps[i]
local hash = propInfo.hash
local coords = propInfo.coords
local lightEntity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 30.0, hash, false, false, false)
if DoesEntityExist(lightEntity) then
local forwardVector = GetEntityForwardVector(lightEntity)
DrawSpotLightWithShadow(
coords.x, coords.y, coords.z,
forwardVector.x, forwardVector.y, forwardVector.z,
255, 255, 190, 12.0, 1.0, 0.0, 80.0, 10.0
)
DrawLightWithRange(
coords.x, coords.y, coords.z,
255, 255, 190, 0.1, 20.0
)
end
end
Citizen.Wait(0)
end
end)
end
ApplyBlackoutExceptForProps()

Hi, with the creator’s permission, if it doesn’t work for you, try that, just add the fxmanifest…

LightByCoord-main.zip (807 Bytes)

Yeah this isn’t a script, its a snippet to place inside an existing client file.

1 Like

yes yes but the problem is that you can’t rotate the light and then even putting a prop… the light doesn’t turn on in the prop… but it only beams with the lamp off