Vice City Multiplayer

VC:MP 0.3 => mIRC/pawn Scripting => Snippet Showroom => Topic started by: NeskWriter on October 13, 2013, 04:01:16 pm

Title: Long shot code
Post by: NeskWriter on October 13, 2013, 04:01:16 pm
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]
Title: Re: Long shot code
Post by: sseebbyy on October 13, 2013, 05:42:48 pm
If you reposted this, why you didn't moved it to the Snippet Showroom ?
Title: Re: Long shot code
Post by: NeskWriter on October 13, 2013, 05:51:47 pm
If you reposted this, why you didn't moved it to the Snippet Showroom ?

Sorry, I've got monster laggs with internet today. Let someone of moders move it. Thanx
Title: Re: Long shot code
Post by: NeskWriter on October 16, 2013, 06:01:13 pm
stormeus can I just up my topic?
Title: Re: Long shot code
Post by: stormeus on October 16, 2013, 10:34:10 pm
Don't bump threads unless you have something to add; it's spammy.