Here is the function and test script with some output results.
Code:
/* OUTPUT
TOTALNUM[1]
ARRELEM[0] PLAYER[6]
TOTALNUM[0]
TOTALNUM[2]
ARRELEM[0] PLAYER[5]
ARRELEM[1] PLAYER[3]
TOTALNUM[3]
ARRELEM[0] PLAYER[6]
ARRELEM[1] PLAYER[5]
ARRELEM[2] PLAYER[3]
*/
#include <amxmodx>
#include <fakemeta>
#include <xs>
public plugin_init() {
register_concmd("test", "func")
}
public func(id) {
new players[32], num = fm_get_aim_players(id, players)
server_print("TOTALNUM[%d]", num)
for (new i; i < num; i++)
server_print("ARRELEM[%d] PLAYER[%d]", i, players[i])
server_print("^n")
return PLUGIN_HANDLED
}
stock fm_get_aim_players(index, players[32]) {
new Float:start[3], Float:view_ofs[3]
pev(index, pev_origin, start)
pev(index, pev_view_ofs, view_ofs)
xs_vec_add(start, view_ofs, start)
new Float:dest[3]
pev(index, pev_v_angle, dest)
engfunc(EngFunc_MakeVectors, dest)
global_get(glb_v_forward, dest)
xs_vec_mul_scalar(dest, 9999.0, dest)
xs_vec_add(start, dest, dest)
new tr, num, player = index, max_aims = get_maxplayers() - 1
for (new i; i < max_aims; i++) {
tr = 0
engfunc(EngFunc_TraceLine, start, dest, 0, player, tr)
player = get_tr2(tr, TR_pHit)
if (!is_user_alive(player))
break
players[num++] = player
get_tr2(tr, TR_vecEndPos, start)
}
return num
}