[Include] leEx - Leadaim Extension
#1

I am currently writing a series of extensions, adding functions and callbacks to various subjects like vehicles, objects, skins, and so on.

This is my leadaim extension. (Removes the need to leadaim)

pawn Код:
/******************************************************************************/

new leEx_Killer [MAX_PLAYERS],
    leEx_Reason [MAX_PLAYERS];

/******************************************************************************/

forward OnPlayerTakeSyncDamage(playerid, issuerid, Float:amount, reason);
public OnPlayerTakeSyncDamage(playerid, issuerid, Float:amount, reason)
{
    new Float:health, Float:armour;
    GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
    if(armour > 0)
    {
        if(amount > armour)
            SetPlayerArmour(playerid, 0.0);
        else
            SetPlayerArmour(playerid, armour - amount);
        amount -= armour;
    }
    if(health > 0 && amount > 0)
    {
        if(amount > health)
        {
            leEx_Killer [playerid] = issuerid;
            leEx_Reason [playerid] = reason;
            SetPlayerHealth(playerid, 0.0);
        }
        else
            SetPlayerHealth(playerid, health - amount);
    }
    return 1;
}

/******************************************************************************/

public OnPlayerSpawn(playerid)
{
    SetPlayerTeam(playerid, 0);
    leEx_Killer[playerid] = INVALID_PLAYER_ID;
    leEx_Reason[playerid] = 0;

    #if defined leEx_OnPlayerSpawn
        return leEx_OnPlayerSpawn(playerid);
    #else
        return 1;
    #endif
}
#if defined leEx_OnPlayerSpawn
    forward leEx_OnPlayerSpawn(playerid);
#endif
#if defined _ALS_OnPlayerSpawn
    #undef OnPlayerSpawn
#else
    #define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn leEx_OnPlayerSpawn

/******************************************************************************/

public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(leEx_Killer[playerid]))
    {
        killerid = leEx_Killer[playerid];
        reason = leEx_Reason[playerid];
    }

    #if defined leEx_OnPlayerDeath
        return leEx_OnPlayerDeath(playerid, killerid, reason);
    #else
        return 1;
    #endif
}
#if defined leEx_OnPlayerDeath
    forward leEx_OnPlayerDeath(playerid, killerid, reason);
#endif
#if defined _ALS_OnPlayerDeath
    #undef OnPlayerDeath
#else
    #define _ALS_OnPlayerDeath
#endif
#define OnPlayerDeath leEx_OnPlayerDeath

/******************************************************************************/

public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
    if(IsPlayerStreamedIn(playerid, damagedid) && IsPlayerStreamedIn(damagedid, playerid))
        OnPlayerTakeSyncDamage(damagedid, playerid, amount, weaponid);

    #if defined leEx_OnPlayerGiveDamage
        return leEx_OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid);
    #else
        return 1;
    #endif
}
#if defined leEx_OnPlayerGiveDamage
    forward leEx_OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid);
#endif
#if defined _ALS_OnPlayerGiveDamage
    #undef OnPlayerGiveDamage
#else
    #define _ALS_OnPlayerGiveDamage
#endif
#define OnPlayerGiveDamage leEx_OnPlayerGiveDamage

/******************************************************************************/

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
    if(IsPlayerConnected(issuerid) && (weaponid == 37 || weaponid == 49 || weaponid == 50 || weaponid == 51 || (GetPlayerState(issuerid) == PLAYER_STATE_DRIVER && (weaponid == 31 || weaponid == 38))))
        OnPlayerTakeSyncDamage(playerid, issuerid, amount, weaponid);

    #if defined leEx_OnPlayerTakeDamage
        return leEx_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid);
    #else
        return 1;
    #endif
}
#if defined leEx_OnPlayerTakeDamage
    forward leEx_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid);
#endif
#if defined _ALS_OnPlayerTakeDamage
    #undef OnPlayerTakeDamage
#else
    #define _ALS_OnPlayerTakeDamage
#endif
#define OnPlayerTakeDamage leEx_OnPlayerTakeDamage

/******************************************************************************/
Just include it in your script like so:
pawn Код:
#include <leEx>
[ame]http://www.youtube.com/watch?v=b0LfuBgvA6U[/ame]

Enjoy.
Reply
#2

Quote:

SA-MP 0.3z RC:

Updated shooting sync for bullet weapons

Shots fired by players are now lag compensated, meaning you can aim at the skin instead of lead aiming.

Your include is outdated before it's even published
(Yes, i know 0.3z is in testing and this can be used to fix the aiming in older versions, but still)
Reply
#3

0.3z is not finished. The sync in 0.3z is not flawless either, and this can be used for it if you just add a bone param
Reply
#4

Looks pretty good, I'll test it out
Reply
#5

NEW: As i forgot to add damage for vehicles like hunter, rustlers, etc, I have now added it.
Reply
#6

Your missing the most important thing in OnPlayerGiveDamage()

pawn Код:
if(!IsPlayerInStreamedIn(playerid, damagedid) || IsPlayerInStreamedIn(damagedid, playerid)) return 1;
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Your missing the most important thing in OnPlayerGiveDamage()

pawn Код:
if(!IsPlayerInStreamedIn(playerid, damagedid) || IsPlayerInStreamedIn(damagedid, playerid)) return 1;
Why is that necesarry?
Reply
#8

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
Why is that necesarry?
1.) Fake OnPlayerGiveDamage() messages
2.) Packetloss/bugged players where only one player streams in for one but not the other
Reply
#9

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
1.) Fake OnPlayerGiveDamage() messages
2.) Packetloss/bugged players where only one player streams in for one but not the other
OK Thanks, added it.
Reply
#10

Good ya.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)