FiveMLuaParticle FXEnvironmentAtmosphereZone
Particle Effects for Environmental Effects in FiveM
March 25, 2026
3 min read
6 views
Particle Effects for Environmental Effects
Environmental effects create atmosphere and immersion for servers — from gas zones, checkpoint effects, to weather hazards.
Zone Marker with Particle FX
local zoneEffects = {}
local function CreateZoneEffect(zoneId, center, radius, effectConfig)
if not SafeRequestPtfx(effectConfig.dict) then return end
-- Create a ring of effects around the zone
local numPoints = math.floor(radius * 4)
zoneEffects[zoneId] = {}
for i = 1, numPoints do
local angle = (i / numPoints) * math.pi * 2
local x = center.x + math.cos(angle) * radius
local y = center.y + math.sin(angle) * radius
local z = center.z
UseParticleFxAssetNextCall(effectConfig.dict)
local handle = StartParticleFxLoopedAtCoord(
effectConfig.effect,
x, y, z,
0.0, 0.0, 0.0,
effectConfig.scale or 0.5,
false, false, false, false
)
table.insert(zoneEffects[zoneId], handle)
end
end
local function RemoveZoneEffect(zoneId)
if zoneEffects[zoneId] then
for _, handle in ipairs(zoneEffects[zoneId]) do
StopParticleFxLooped(handle, false)
end
zoneEffects[zoneId] = nil
end
end
-- Use: Create a green gas zone.
CreateZoneEffect("drugzone_1", vector3(100, 200, 30), 10.0, {
dict = "core",
effect = "ent_amb_smoke_car",
scale = 0.8
})
Ambient Smoke Area
local function SpawnAmbientSmoke(center, width, height, density)
density = density or 10
local handles = {}
RequestNamedPtfxAsset("core")
while not HasNamedPtfxAssetLoaded("core") do
Citizen.Wait(0)
end
for i = 1, density do
local x = center.x + (math.random() - 0.5) * width
local y = center.y + (math.random() - 0.5) * width
local z = center.z + math.random() * height
UseParticleFxAssetNextCall("core")
local handle = StartParticleFxLoopedAtCoord(
"ent_amb_smoke_car",
x, y, z,
0.0, 0.0, 0.0,
math.random() + 0.5, -- random scale 0.5-1.5
false, false, false, false
)
-- light gray
SetParticleFxLoopedColour(handle, 0.8, 0.8, 0.8, false)
table.insert(handles, handle)
end
return handles
end
Fire Hazard Area
local function CreateFireArea(center, size, intensity)
local fireHandles = {}
if not SafeRequestPtfx("core") then return {} end
local numFires = math.floor(size * intensity)
for i = 1, numFires do
local x = center.x + (math.random() - 0.5) * size
local y = center.y + (math.random() - 0.5) * size
local z = center.z
UseParticleFxAssetNextCall("core")
local handle = StartParticleFxLoopedAtCoord(
"ent_veh_engine_fire",
x, y, z,
0.0, 0.0, 0.0,
math.random() * 0.8 + 0.3,
false, false, false, false
)
table.insert(fireHandles, handle)
-- add smoke as well
UseParticleFxAssetNextCall("core")
local smokeHandle = StartParticleFxLoopedAtCoord(
"ent_amb_smoke_car",
x, y, z + 0.5,
0.0, 0.0, 0.0,
1.2,
false, false, false, false
)
table.insert(fireHandles, smokeHandle)
end
return fireHandles
end
Water/Liquid Drip Effects
local function CreateLeakEffect(coords, isWater)
local config = isWater
and {dict = "core", effect = "ent_sht_water"}
or {dict = "core", effect = "ent_sht_oil"}
if not SafeRequestPtfx(config.dict) then return end
-- Drip effect every 500ms
Citizen.CreateThread(function()
local active = true
while active do
UseParticleFxAssetNextCall(config.dict)
StartParticleFxNonLoopedAtCoord(
config.effect,
coords.x, coords.y, coords.z,
0.0, 0.0, 0.0,
0.5,
false, false, false
)
Citizen.Wait(500)
end
end)
end
Drug/Toxic Zone
local function CreateToxicZone(coords, radius)
if not SafeRequestPtfx("scr_rcbarry1") then return end
local handles = {}
-- Toxic gas effect around zone
UseParticleFxAssetNextCall("scr_rcbarry1")
local mainHandle = StartParticleFxLoopedAtCoord(
"scr_amb_electric_arc",
coords.x, coords.y, coords.z,
0.0, 0.0, 0.0,
radius * 0.3,
false, false, false, false
)
-- poisonous green
SetParticleFxLoopedColour(mainHandle, 0.1, 1.0, 0.2, false)
table.insert(handles, mainHandle)
return handles
end
Summary
Environmental effects must be carefully managed lifecycle:
- Created when zone active
- Destroyed when player exits or zone closes
- cleanup in onResourceStop always
These effects can be combined to create an impressive atmosphere.
Related Articles
วิธีจัดการ Version และ Update Script ในเซิร์ฟเวอร์ FiveM อย่างมืออาชีพ
อัพเดท script บน production โดยไม่ให้เซิร์ฟเวอร์ down — เรียนรู้ระบบจัดการ version, Git workflow, และกลยุทธ์ deploy ที่ลดความเสี่ยง
หลักการ Clean Code สำหรับ FiveM Script Developer
โค้ดที่ทำงานได้กับโค้ดที่ดีไม่ใช่สิ่งเดียวกัน — เรียนรู้หลักการ clean code ที่ทำให้ FiveM script ของคุณอ่านง่าย, แก้ง่าย และขยายได้
วิธีทดสอบ FiveM Script ก่อน Deploy ขึ้น Production Server
อย่า deploy script ที่ยังไม่ผ่านการทดสอบลงบน production — เรียนรู้วิธีสร้าง testing workflow สำหรับ FiveM ที่ลด downtime และป้องกัน bug จากผู้เล่นจริง