FiveMLuaParticle FXWeaponCombatTutorial
Particle Effects for Weapon Effects in FiveM
March 25, 2026
2 min read
5 views
Particle Effects for Weapon Effects in FiveM
Weapon visual effects greatly enhance the combat experience — learn how to create muzzle flash, impact effects, and weapon auras.
Events related to weapons
-- Shoot detection
AddEventHandler("weaponDamageEvent", function(
sourceEntity, targetEntity, weaponInfoHash,
baseDamage, isAimed, coordsX, coordsY, coordsZ, ...
)
-- Play impact effect at the hit point.
local hitCoords = vector3(coordsX, coordsY, coordsZ)
PlayImpactEffect(hitCoords, weaponInfoHash)
end)
-- Detect gunshots (client-side)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = PlayerPedId()
if IsPedShooting(ped) then
local weapon = GetSelectedPedWeapon(ped)
OnPlayerShoot(ped, weapon)
end
end
end)
Muzzle Flash Effect
local weaponEffects = {
-- pistol flash
[GetHashKey("WEAPON_PISTOL")] = {
dict = "core",
effect = "muz_pistol_b",
bone = "IK_R_Hand",
scale = 0.3
},
-- rifle flash
[GetHashKey("WEAPON_ASSAULTRIFLE")] = {
dict = "core",
effect = "muz_assault_rifle",
bone = "IK_R_Hand",
scale = 0.4
},
-- shotgun flash
[GetHashKey("WEAPON_SHOTGUN")] = {
dict = "core",
effect = "muz_shotgun",
bone = "IK_R_Hand",
scale = 0.6
}
}
local function PlayMuzzleFlash(ped, weaponHash)
local config = weaponEffects[weaponHash]
if not config then return end
if not SafeRequestPtfx(config.dict) then return end
local boneIndex = GetEntityBoneIndexByName(ped, config.bone)
UseParticleFxAssetNextCall(config.dict)
StartParticleFxNonLoopedOnEntityBone(
config.effect,
ped,
0.1, 0.0, 0.0, -- forward offset
0.0, 90.0, 0.0,
boneIndex,
config.scale,
false, false, false
)
end
Impact Effects by Surface
-- impact effects according to surface type
local impactEffects = {
concrete = {dict = "core", effect = "ent_sht_concrete"},
dirt = {dict = "core", effect = "ent_sht_dirt"},
metal = {dict = "core", effect = "ent_sht_metal"},
wood = {dict = "core", effect = "ent_sht_wood"},
water = {dict = "core", effect = "ent_sht_water"},
blood = {dict = "core", effect = "ent_sht_blood"},
}
local function PlayImpactEffect(coords, normal)
-- find the surface type
local material = GetGroundMaterialUnder(coords)
local config = impactEffects.concrete -- default
if material == "CONCRETE" then
config = impactEffects.concrete
elseif material == "DIRT" then
config = impactEffects.dirt
end
if not SafeRequestPtfx(config.dict) then return end
UseParticleFxAssetNextCall(config.dict)
StartParticleFxNonLoopedAtCoord(
config.effect,
coords.x, coords.y, coords.z,
0.0, 0.0, 0.0,
1.0,
false, false, false
)
end
Special Weapon Aura
local weaponAuraHandle = nil
local function StartWeaponAura(ped, color)
if not SafeRequestPtfx("scr_powerplay") then return end
local boneIndex = GetEntityBoneIndexByName(ped, "IK_R_Hand")
UseParticleFxAssetNextCall("scr_powerplay")
weaponAuraHandle = StartParticleFxLoopedOnEntityBone(
"scr_powerplay_overlay_electricity_chars",
ped,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
boneIndex,
0.4,
false, false, false
)
-- Set color
if color and weaponAuraHandle then
SetParticleFxLoopedColour(
weaponAuraHandle,
color.r, color.g, color.b,
false
)
end
end
local function StopWeaponAura()
if weaponAuraHandle then
StopParticleFxLooped(weaponAuraHandle, false)
weaponAuraHandle = nil
end
end
Trail Effect on bullets
-- Make a bullet trail with networked effect at spawn point
local function CreateBulletTrail(startCoords, endCoords)
if not SafeRequestPtfx("core") then return end
-- Calculate direction
local dir = endCoords - startCoords
local distance = #dir
local steps = math.floor(distance / 0.5)
for i = 0, steps do
local t = i / steps
local pos = startCoords + (dir * t)
UseParticleFxAssetNextCall("core")
StartParticleFxNonLoopedAtCoord(
"ent_sht_sparks_2",
pos.x, pos.y, pos.z,
0.0, 0.0, 0.0,
0.1,
false, false, false
)
end
end
Summary
Weapon effects greatly enhance combat scripts — try a combination of:
- Muzzle flash when shooting
- Impact effects according to surface
- Weapon aura for special abilities
- Bullet trail for visual feedback
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 จากผู้เล่นจริง