ray = {}
addEventHandler( "onClientPlayerWeaponFire", getRootElement(), function( _, tAmmo, cAmmo, hX, hY, hZ, hElement, sX, sY, sZ )
local rx, ry, rz = getElementRotation( source )
local muzzleX, muzzleY, muzzleZ = getPedWeaponMuzzlePosition( source )
local muzzle_eX, muzzle_eY, muzzle_eZ = getPedTargetEnd( source )
if not getPedTargetCollision( source ) then
local offset = math.rad( rz + 90 )
local l_sX, l_sY, l_sZ = muzzleX, muzzleY, muzzleZ
local l_eX, l_eY, l_eZ = ( muzzle_eX + 50 * math.cos( offset ) ), ( muzzle_eY + 50 * math.sin( offset ) ), muzzle_eZ
table.insert( ray, { l_sX, l_sY, l_sZ, l_eX, l_eY, l_eZ } )
else
local l_sX, l_sY, l_sZ = muzzleX, muzzleY, muzzleZ
local l_eX, l_eY, l_eZ = getPedTargetCollision( source )
table.insert( ray, { l_sX, l_sY, l_sZ, l_eX, l_eY, l_eZ } )
end
end)
function drawRays()
for i, v in ipairs( ray ) do
dxDrawLine3D( v[ 1 ], v[ 2 ], v[ 3 ], v[ 4 ], v[ 5 ], v[ 6 ], tocolor( 255, 0, 0, 100 ), 2 )
end
end
addEventHandler( "onClientRender", root, drawRays )
That's the script. I want to draw a ray from weapon's muzzle XYZ to (XYZ + range) but if i use getPedTargetEnd() it has a weapon's range limitations and I can't change that correctly because of RenderWare engine and MTA limits