diff --git a/SmartLaser/cl_smartlaser.lua b/SmartLaser/cl_smartlaser.lua index 91144bf..00dda15 100644 --- a/SmartLaser/cl_smartlaser.lua +++ b/SmartLaser/cl_smartlaser.lua @@ -24,8 +24,10 @@ RegisterCommand(config.commandName, function(source, args, raw) laserSight = false TriggerServerEvent("LSLaser:Set", false) else - laserSight = true - TriggerServerEvent("LSLaser:Set", true) + if not config.supportedWeapons.checkcomponent or hasFlashlightComponent(ped, pedWeapon) then + laserSight = true + TriggerServerEvent("LSLaser:Set", true) + end end end end) @@ -78,13 +80,22 @@ Citizen.CreateThread(function() if laserSight then local laserOn = LocalPlayer.state.laserOn + local pedWeapon = GetSelectedPedWeapon(ped) if IsPlayerFreeAiming(PlayerId()) then - if not laserOn then - LocalPlayer.state:set('laserOn', true, true) + if config.supportedWeapons.checkcomponent and not hasFlashlightComponent(ped, pedWeapon) then + laserSight = false + if laserOn then + LocalPlayer.state:set('laserOn', false, true) + end + TriggerServerEvent("LSLaser:Set", false) + else + if not laserOn then + LocalPlayer.state:set('laserOn', true, true) + end + local rotation = GetGameplayCamRot() + directionMain = RotationToDirection(rotation) + LocalPlayer.state:set('direction', directionMain, true) end - local rotation = GetGameplayCamRot() - directionMain = RotationToDirection(rotation) - LocalPlayer.state:set('direction', directionMain, true) else if laserOn then LocalPlayer.state:set('laserOn', false, true) @@ -131,3 +142,10 @@ function RotationToDirection(rotation) math.sin(adjustedRotation.x)) return direction end + +function hasFlashlightComponent(ped, weapon) + local piAttached = HasPedGotWeaponComponent(ped, weapon, `COMPONENT_AT_PI_FLSH`) + local arAttached = HasPedGotWeaponComponent(ped, weapon, `COMPONENT_AT_PI_FLSH`) + + return piAttached or arAttached +end \ No newline at end of file diff --git a/SmartLaser/config.lua b/SmartLaser/config.lua index 3158eac..6f5874d 100644 --- a/SmartLaser/config.lua +++ b/SmartLaser/config.lua @@ -23,6 +23,7 @@ config = { } config.supportedWeapons = { + checkcomponent = true, -- If true, the script will check if the weapon has the flashlight component before applying the laser [`WEAPON_PISTOL`] = { -- If these values aren't set, the default value will be used offSet = {0.0, 0.00, 0.025}, -- Laser offSet from gun