Last active 1741880560

jackz's Avatar jackz revised this gist 1741880560. Go to revision

No changes

jackz's Avatar Jackz revised this gist 1630857554. Go to revision

1 file changed, 11 insertions

get_point_test.lua

@@ -1,3 +1,14 @@
1 + local function GetEndCoord(deg, start, range)
2 + local rad_x = deg['x'] * 0.0174532924
3 + local rad_z = deg['z'] * 0.0174532924
4 +
5 + return {
6 + x = range * (-math.sin(rad_z) * math.cos(rad_x)) + start.x,
7 + y = range * (math.cos(rad_z) * math.cos(rad_x)) + start.y,
8 + z = range * math.sin(rad_x) + start.z
9 + }
10 + end
11 +
1 12 local my_ped = PLAYER.GET_PLAYER_PED_SCRIPT_INDEX(players.user())
2 13 local cpos = CAM.GET_GAMEPLAY_CAM_COORD()
3 14 local rot = CAM.GET_GAMEPLAY_CAM_ROT(0)

jackz's Avatar Jackz revised this gist 1630857497. Go to revision

1 file changed, 33 insertions

get_point_test.lua(file created)

@@ -0,0 +1,33 @@
1 + local my_ped = PLAYER.GET_PLAYER_PED_SCRIPT_INDEX(players.user())
2 + local cpos = CAM.GET_GAMEPLAY_CAM_COORD()
3 + local rot = CAM.GET_GAMEPLAY_CAM_ROT(0)
4 + local pos2 = GetEndCoord(rot, cpos, 2000.0)
5 + -- local pos2 = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(my_ped, 0.0, 1000.0, 0)
6 +
7 + local ray = SHAPETEST.START_SHAPE_TEST_LOS_PROBE(cpos.x, cpos.y, cpos.z, pos2.x, pos2.y, pos2.z, 33, my_ped, 4)
8 + -- 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)
9 + local p_bool = memory.alloc(8)
10 + local p_endPos = memory.alloc(24)
11 + local p_surfaceNormal = memory.alloc(24)
12 + local p_entityHit = memory.alloc(32)
13 +
14 + while SHAPETEST.GET_SHAPE_TEST_RESULT(ray, p_bool, p_endPos, p_surfaceNormal, p_entityHit) == 1 do
15 + util.yield()
16 + end
17 + local hit = memory.read_byte(p_bool)
18 + if hit == 1 then
19 + src = cpos
20 + dest = memory.read_vector3(p_endPos)
21 + dest.z = dest.z + 1.0
22 + util.toast(string.format("from %f %f %f", src.x, src.y, src.z))
23 + util.toast(string.format("to %f %f %f", dest.x, dest.y, dest.z))
24 + local vdist = SYSTEM.VDIST(src.x, src.y, src.z, dest.x, dest.y, dest.z)
25 + util.toast(vdist)
26 + menu.trigger_commands("launchself")
27 + else
28 + util.toast("miss")
29 + end
30 + memory.free(p_bool)
31 + memory.free(p_endPos)
32 + memory.free(p_surfaceNormal)
33 + memory.free(p_entityHit)
Newer Older