Last active
September 5, 2021 15:59
-
-
Save Jackzmc/09c926ece26d2e7b129434114a390ce3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function GetEndCoord(deg, start, range) | |
local rad_x = deg['x'] * 0.0174532924 | |
local rad_z = deg['z'] * 0.0174532924 | |
return { | |
x = range * (-math.sin(rad_z) * math.cos(rad_x)) + start.x, | |
y = range * (math.cos(rad_z) * math.cos(rad_x)) + start.y, | |
z = range * math.sin(rad_x) + start.z | |
} | |
end | |
local my_ped = PLAYER.GET_PLAYER_PED_SCRIPT_INDEX(players.user()) | |
local cpos = CAM.GET_GAMEPLAY_CAM_COORD() | |
local rot = CAM.GET_GAMEPLAY_CAM_ROT(0) | |
local pos2 = GetEndCoord(rot, cpos, 2000.0) | |
-- local pos2 = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(my_ped, 0.0, 1000.0, 0) | |
local ray = SHAPETEST.START_SHAPE_TEST_LOS_PROBE(cpos.x, cpos.y, cpos.z, pos2.x, pos2.y, pos2.z, 33, my_ped, 4) | |
-- local ray = SHAPETEST.START_SHAPE_TEST_CAPSULE(cpos.x, cpos.y, cpos.z, cpos.x + pos2.x, cpos.y + pos2.y, cpos.z + pos2.z, 2.0, 1, my_ped, 7) | |
local p_bool = memory.alloc(8) | |
local p_endPos = memory.alloc(24) | |
local p_surfaceNormal = memory.alloc(24) | |
local p_entityHit = memory.alloc(32) | |
while SHAPETEST.GET_SHAPE_TEST_RESULT(ray, p_bool, p_endPos, p_surfaceNormal, p_entityHit) == 1 do | |
util.yield() | |
end | |
local hit = memory.read_byte(p_bool) | |
if hit == 1 then | |
src = cpos | |
dest = memory.read_vector3(p_endPos) | |
dest.z = dest.z + 1.0 | |
util.toast(string.format("from %f %f %f", src.x, src.y, src.z)) | |
util.toast(string.format("to %f %f %f", dest.x, dest.y, dest.z)) | |
local vdist = SYSTEM.VDIST(src.x, src.y, src.z, dest.x, dest.y, dest.z) | |
util.toast(vdist) | |
menu.trigger_commands("launchself") | |
else | |
util.toast("miss") | |
end | |
memory.free(p_bool) | |
memory.free(p_endPos) | |
memory.free(p_surfaceNormal) | |
memory.free(p_entityHit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment