As you may already know, this code deals with a long shot. Yes, if you kill a player, a stock function will compare the distance between you and your victim/you and the guy who shot you. if the distance is longer than 50 meters, you/your killer will be congratulated.
P.S. Seby has told me that it was not a new idea, so excuse me if the similar code already exists!
[pawn]
public OnPlayerDeath(playerid, killerid, reason, bodypart)
{
if(killerid != INVALID_PLAYER_ID)
{
if(GetDistanceBetween(playerid, killerid) >= 50) //Replace "50" with your own integer, if you want. "50" is the default distance of long shot between victim and killer.
{
new longshotmsg[128];
format(longshotmsg, sizeof(longshotmsg), "%s killed %s by a long shot.", RetPlayerName(killerid), RetPlayerName(playerid));
SendClientMessageToAll(COLOR_GREEN, longshotmsg);
SetPlayerMoney(killerid, GetPlayerMoney(playerid) + 1000);
SendClientMessage(killerid, COLOR_GREEN, "You've been given $1000 as a bonus of long shot");
}
}
return 0;
}
[/pawn]
Here are stock functions I used:
[pawn]
//A stock function to get distance between two players (very similar to that one from GUPS)
stock GetDistanceBetween(playerid, playerid2)
{
new Float:px, Float:py, Float:pz, Float:px2, Float:py2, Float:pz2, Float:distance;
GetPlayerPos(playerid, px, py, pz);
GetPlayerPos(playerid2, px2, py2, pz2);
distance = floatsqroot(floatpower((px2 - px), 2) + floatpower((py2 - py), 2) + floatpower((pz2 - pz), 2));
return floatround(distance);
}
//This function returns player name
stock RetPlayerName(playerid)
{
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
return pname;
}
//This is definition of HEX-code of green color
#define COLOR_GREEN 0x00FF00AA
[/pawn]