killer distance ?
#1

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 :/
Reply
#2

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.
Reply
#3

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;
}
Reply
#4

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

ok thanks friends.
I will try it.
Reply
#6

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);
?
Reply
#7

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.
Reply
#8

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);
Reply
#9



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

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)