Sorry for the late reply guys. Was busy with work. I was also tinkering with the code Crazy. gave me. It seem it has some problems listing all of the players or something related to that. I haven't explored Bugsy's recommendation yet. But I ended up using find_sphere_class like HamletEagle suggested. I didn't use it before because I didn't know what to put in the entity parameter. I didn't know you can actually put -1 there if there's no entity to base the radius around. Haven't done a hard test but so far it's working well. Here's the code:
PHP Code:
RegisterHam(Ham_TraceAttack, "worldspawn", "SotB_Sniper_Warning", false);
...
public SotB_Sniper_Warning(victim, attacker, Float:damage, Float:direction[3], prt, damage_bits)
{
if(g_sniperspotted_time[attacker] + 10.0 > get_gametime())
return HAM_IGNORED
new wpn_id = get_user_weapon(attacker);
new team = get_user_team(attacker);
if(CSW_ALL_SNIPERRIFLES & 1 << wpn_id)
{
new players[MAX_PLAYERS], iplayer, num;
new spotters[MAX_PLAYERS], Float:origin[3];
get_tr2(prt, TR_vecEndPos, origin);
find_sphere_class(-1, "player", 350.0, players, MAX_PLAYERS, origin);
for(new i = 0; i < MAX_PLAYERS; i++)
{
iplayer = players[i];
if(is_user_alive(iplayer) && iplayer != attacker
&& get_user_team(iplayer) != team && !g_is_sneaking[iplayer])
{
spotters[num] = iplayer;
num++;
}
}
if(num <= 0) return HAM_IGNORED
new audio_id = random_num(0, sizeof SND_SNIPER_WARNING - 1);
emit_sound(spotters[0], CHAN_VOICE, SND_SNIPER_WARNING[audio_id], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
g_sniperspotted_time[attacker] = get_gametime();
}
return HAM_IGNORED
}
Basically what it does is when an enemy player fires a sniper rifle somewhere near you, it takes everyone around where the shot landed then picks a player to yell, "There's a sniper!"...
__________________