[Standalone] Laser sight script

I made some thing like this using bone with C++ on GTA V :

but i did delete the project, i can’t remember which native i was using to make it, if i remember i will send you.

Alright, thanks for supporting! :heart:

1 Like
local enabled = false
local timer_opti = 1000

RegisterCommand('+taser_toggle', function()
	local ped = PlayerPedId()
	if GetSelectedPedWeapon(ped) == GetHashKey("WEAPON_STUNGUN") then
		if enabled then
			enabled = false
			displaytext("Laser has been ~r~Disabled")
			timer_opti = 1000
		else
			displaytext("Laser has been ~g~Enabled")
			Citizen.CreateThread(function()
				enabled = true
				while enabled do 
					timer_opti = 1000
					local camview = GetFollowPedCamViewMode()
					local crouch = GetPedStealthMovement(ped)
					if IsPlayerFreeAiming(PlayerId()) then
						if GetSelectedPedWeapon(ped) == GetHashKey("WEAPON_STUNGUN") then
							timer_opti = 0
							local weapon = GetCurrentPedWeaponEntityIndex(ped)
							local offset = GetOffsetFromEntityInWorldCoords(weapon, 0, 0, -0.01)
							local hit, coords = RayCastPed(offset, 15000, ped)
							
							if hit ~= 0 then
								DrawLine(offset.x, offset.y, offset.z, coords.x, coords.y, coords.z, config.LaserColorR, config.LaserColorG, config.LaserColorB, config.LaserColorA)
								DrawSphere2(coords, 0.01, config.LaserColorR, config.LaserColorG, config.LaserColorB, config.LaserColorA)
							end
						end
					end
					Citizen.Wait(timer_opti)
				end
			end)
		end
	end
end, false)

RegisterCommand('-taser_toggle', function() end, false)
RegisterKeyMapping('+taser_toggle', 'Toggle Taser Laser', 'keyboard', config.default_key)

function RotationToDirection(rotation)
	local adjustedRotation = 
	{ 
		x = (math.pi / 180) * rotation.x, 
		y = (math.pi / 180) * rotation.y, 
		z = (math.pi / 180) * rotation.z 
	}
	local direction = 
	{
		x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), 
		y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), 
		z = math.sin(adjustedRotation.x)
	}
	return direction
end

function RayCastPed(pos,distance,ped)
    local cameraRotation = GetGameplayCamRot()
	local direction = RotationToDirection(cameraRotation)
	local destination = 
	{ 
		x = pos.x + direction.x * distance, 
		y = pos.y + direction.y * distance, 
		z = pos.z + direction.z * distance 
	}

	local a, b, c, d, e = GetShapeTestResult(StartShapeTestRay(pos.x, pos.y, pos.z, destination.x, destination.y, destination.z, -1, ped, 1))
    return b, c
end


function displaytext(string)
	BeginTextCommandThefeedPost("STRING")
	AddTextComponentSubstringPlayerName(string)
	EndTextCommandThefeedPostMpticker(true, true)
end

function DrawSphere2(pos, radius, r, g, b, a)
	DrawMarker(28, pos.x, pos.y, pos.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, radius, radius, radius, r, g, b, a, false, false, 2, nil, nil, false)
end

You can push this version, You now have a cleanest code and you don’t use bone anymore but the offset of the weapon ajusted.

E.g :




1 Like

I’ll take a look right now. Thanks for contributing man means a lot! Developers helping developers!

Alright I updated my github thanks again @Ninja_force

1 Like

where do you place the folder?

it’s just a normal server resource. Drag and drop into your resource folder and start in server.cfg.

1 Like

so its now server sided?

It’s always been server sides. I just meant it was a client script. I couldn’t edit the post.

How do install it ?

Gonna try learn to make this server sided. Any pointers on how to start?

Have you made a server-side file for this script yet?

This looks really cool, does it work in first person view?

i love this script but for some reason the closer the target i aim for the more off centered the laser will be, is there a way to fix this?