View Single Post
Infractem
Member
Join Date: Dec 2016
Old 01-26-2017 , 09:11   Re: [Snippet request]Best way to randomly choose a random player from the enemy team?
Reply With Quote #3

I made this code using the other parts of the plugin I am editing right now(cypis' killstreak plugin)
The thing is this bombs EVERY enemy on the map, I only need a single random enemy to get bombed. Can you help me with this one, please?

Code:
public CreatePredator2(id)
{
	new num, players[32];
	get_players(players, num, "gh");
	for(new a = 0; a < num; a++)
	{
		new i = players[a];
		if(get_user_team(id) != get_user_team(i))
			client_cmd(i, "spk sound/mw/predator_enemy.wav");
		else
			client_cmd(i, "spk sound/mw/predator_friend.wav");
	}
	set_task(5.0, "predator_continue", id)
	predator[id] = false;
}

public predator_continue(id)
{
	new num, players[32], PlayerCoords[3];
	get_players(players, num, "gh")
	for(new a=0; a<num; a++)
	{      
		if(!is_user_alive(players[a]) || get_user_team(players[a]) == get_user_team(id)) 
			continue;
		get_user_origin(players[a], PlayerCoords);
		
		new Float:LocVec[3]; 
		IVecFVec(PlayerCoords, LocVec); 
		create_ent(id, "bomb", "models/p_hegrenade.mdl", 2, 10, LocVec);
	}
}
Infractem is offline