Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions SmartLaser/cl_smartlaser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions SmartLaser/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down