[Include] OnPlayerFakeKill.inc
#5

Better Hook Names that won't conflict with other includes
Code:
#if defined _ALS_OnPlayerConnect
  #undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
 
#define OnPlayerConnect OnPlayerConnectEx
You must use better hook names for example, "OnPlayerConnect_OPFK" so that it won't conflict with other libraries. Good practice! There are many who still use CallbackNameEx.

Static Variables & Char Variables

Code:
new givenDamage[MAX_PLAYERS][MAX_PLAYERS];
Keep it static so that it won't conflict with any other script.

You can also make it into a char array since you just need to store true/false.

Code:
static givenDamage[MAX_PLAYERS][MAX_PLAYERS char];
Memset is WAY faster than manually setting array elements to zero
Use memset for these loops, its WAY faster than your PAWN loop.
Code:
for(new i; i < MAX_PLAYERS; i++)
{
     givenDamage[playerid][i] = 0;
}
Check New Code Optimizations Tip #5 for more information

CallLocalFunction is horribly slow
CallLocalFunction is very slow and you are going to call it every time a player takes damage which makes it more worse!

Why
Code:
 CallLocalFunction("OnPlayerTakeDamage", "ddfdd", playerid, issuerid, amount, weaponid, bodypart);
when you can simply
Code:
#if defined OnPlayerTakeDamage
OnPlayerTakeDamage(playerid, issuerid, amount, weaponid, bodypart);
#endif
The same TIP applies to these
Code:
CallLocalFunction("OnPlayerDeathEx", "ddd", playerid, killerid, reason);
CallLocalFunction("OnPlayerDie", "ddd", playerid, killerid, reason);
CallLocalFunction("OnPlayerFakeKill", "ddd", playerid, killerid, reason);
Check New Code Optimizations Tip #2 for more information

Include won't work -> Infinite Loop
You just made an infinite loop!

Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
        if(issuerid == INVALID_PLAYER_ID || playerid == issuerid) return 1;
        givenDamage[playerid][issuerid] = 1;
       
        CallLocalFunction("OnPlayerTakeDamage", "ddfdd", playerid, issuerid, amount, weaponid, bodypart);
       
        return 1;
}
OnPlayerTakeDamage gets called and you call it again when calls again...

It think it should have been OnPlayerTakeDamageEx :/

Suggestion:
Instead of having people use a new callback "OnPlayerDie" why not let them use OnPlayerDeath? You are hooking OnPlayerDeath, that means you can control OnPlayerDeath calls. Call OnPlayerDeath when the player made a legit kill and don't call when player made an illegal kill.

I do see more potential issue with the include, especially when you kill a player who is AFK (If a player is AFK and you shoot him, when he returns he dies and OnPlayerDeath is called).
Reply


Messages In This Thread
OnPlayerFakeKill.inc - by Abagail - 22.07.2015, 03:09
Re: OnPlayerFakeKill.inc - by DarkLored - 22.07.2015, 03:14
Re: OnPlayerFakeKill.inc - by SickAttack - 22.07.2015, 03:46
Re: OnPlayerFakeKill.inc - by Abagail - 22.07.2015, 04:25
Re: OnPlayerFakeKill.inc - by Yashas - 22.07.2015, 05:51
Re: OnPlayerFakeKill.inc - by Evocator - 22.07.2015, 07:13
Re: OnPlayerFakeKill.inc - by amirab - 22.07.2015, 10:58
Re: OnPlayerFakeKill.inc - by Tamer - 22.07.2015, 12:58
Re: OnPlayerFakeKill.inc - by Lordzy - 22.07.2015, 13:07
Re: OnPlayerFakeKill.inc - by Abagail - 22.07.2015, 15:16

Forum Jump:


Users browsing this thread: 1 Guest(s)