In your case, who is playerid2? Maybe the closest player to the player pressing the key?
pawn Код:
stock Float:GetDistanceBetweenPlayers(playerid, playerid2)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
GetPlayerPos(playerid2,x2,y2,z2);
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
return tmpdis;
}
/*stock bool:IsPlayerInRangeOfPlayer(playerid, playerid2, Float:range) //An extension if you want it.
{
if(GetDistanceBetweenPlayers(playerid, playerid2) <= range) return true;
return false;
}*/
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == 128)
{
if(gTeam[playerid] == TEAM_ZOMBIES)
{
foreach(Player, playerid2)
{
if((GetDistanceBetweenPlayers(playerid, playerid2) <= 3) && (gTeam[playerid2] !=TEAM_ZOMBIES))
{
new Health; GetPlayerHealth(playerid2, Health);
SetPlayerHealth(playerid2, Health-10);
}
}
}
}
return 1;
}