SA-MP Forums Archive
killer distance ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: killer distance ? (/showthread.php?tid=474807)



killer distance ? - Champ - 09.11.2013

I want to send client message to all in which there must be the distance mentioned.
I mean the distance from where the killer killed a person.

for example:
%s has killed %s from the distance of %d.

I don't know how to find distance :/


Re: killer distance ? - Konstantinos - 09.11.2013

https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint

Get the position of the player who died and then use the above function for the killer and the position of the player who died. It returns the distance between the two players.


Re: killer distance ? - erminpr0 - 09.11.2013

pawn Код:
forward Float:GetDistanceBetweenPlayers(playerid,targetplayerid);

public Float:GetDistanceBetweenPlayers(playerid,targetplayerid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {
        return -1.00;
    }
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(targetplayerid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}

public OnPlayerDeath(playerid, killerid, reason)
{
   new string[128], player[MAX_PLAYER_NAME], killer[MAX_PLAYER_NAME];
   new Float:dist = GetDistanceBetweenPlayers(playerid, killerid);
   GetPlayerName(killerid, killer, sizeof(killer));
   GetPlayerName(playerid, player, sizeof(player));
   format(string, sizeof(string), "*Player %s has killed %s from distance: %.2f", killer, player, dist);
   SendClientMessageToAll(0xFFFFFFFF, string);
   return 1;
}



Re: killer distance ? - Pottus - 09.11.2013

erminpr0: Why bother using your own function when there is already a native?


Re: killer distance ? - Champ - 09.11.2013

ok thanks friends.
I will try it.


Re: killer distance ? - Champ - 09.11.2013

will this work

pawn Код:
new Float:x;
    new Float:y;
    new Float:z;
    new
        Float: fDistance = GetPlayerDistanceFromPoint(playerid, x, y, z),
        szMessage[44];

    format(szMessage, sizeof(szMessage), "%s has killed %s from the distance of %0.2f", killerid, playerid, fDistance);
    SendClientMessage(playerid, 0xA9C4E4FF, szMessage);
?


Re: killer distance ? - iZN - 09.11.2013

Quote:
Originally Posted by Champ
Посмотреть сообщение
will this work

pawn Код:
new Float:x;
    new Float:y;
    new Float:z;
    new
        Float: fDistance = GetPlayerDistanceFromPoint(playerid, x, y, z),
        szMessage[44];

    format(szMessage, sizeof(szMessage), "%s has killed %s from the distance of %0.2f", killerid, playerid, fDistance);
    SendClientMessage(playerid, 0xA9C4E4FF, szMessage);
?
Yes it will work. Try it.


Re: killer distance ? - Konstantinos - 09.11.2013

No, it will not. You never get any position.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
[..] Get the position of the player who died and then use the above function for the killer and the position of the player who died. It returns the distance between the two players.
pawn Код:
new Float:x, Float:y, Float:z, Float:fDistance, szMessage[44];
GetPlayerPos(playerid, x, y, z);
fDistance = GetPlayerDistanceFromPoint(killerid, x, y, z);
format(szMessage, sizeof(szMessage), "%s has killed %s from the distance of %0.2f", killerid, playerid, fDistance);
SendClientMessage(playerid, 0xA9C4E4FF, szMessage);



Re: killer distance ? - Champ - 09.11.2013



Bug .
no name is written in this message.
and it is also bugged when player suicides.


Re: killer distance ? - Konstantinos - 09.11.2013

I made only the distance part, the rest was copy-paste of what you did. You use %s which is for strings and the arguments are killerid and playerid which are integers..

You'll also need to check if the killer is valid.

That should work:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        new Float:x, Float:y, Float:z, Float:fDistance, szMessage[90], szName[MAX_PLAYER_NAME];
        GetPlayerPos(playerid, x, y, z);
        fDistance = GetPlayerDistanceFromPoint(killerid, x, y, z);
        GetPlayerName(killerid, szMessage, MAX_PLAYER_NAME);
        GetPlayerName(playerid, szName, MAX_PLAYER_NAME);
        format(szMessage, sizeof(szMessage), "%s has killed %s from the distance of %0.2f", szMessage, szName, fDistance);
        SendClientMessage(playerid, 0xA9C4E4FF, szMessage);
        // I assume you wanted a message to all?
        //SendClientMessageToAll(0xA9C4E4FF, szMessage);
    }
    return 1;
}