22.07.2015, 05:51
Better Hook Names that won't conflict with other includes
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
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.
Memset is WAY faster than manually setting array elements to zero
Use memset for these loops, its WAY faster than your PAWN loop.
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
when you can simply
The same TIP applies to these
Check New Code Optimizations Tip #2 for more information
Include won't work -> Infinite Loop
You just made an infinite loop!
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).
Code:
#if defined _ALS_OnPlayerConnect #undef OnPlayerConnect #else #define _ALS_OnPlayerConnect #endif #define OnPlayerConnect OnPlayerConnectEx
Static Variables & Char Variables
Code:
new givenDamage[MAX_PLAYERS][MAX_PLAYERS];
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];
Use memset for these loops, its WAY faster than your PAWN loop.
Code:
for(new i; i < MAX_PLAYERS; i++) { givenDamage[playerid][i] = 0; }
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);
Code:
#if defined OnPlayerTakeDamage OnPlayerTakeDamage(playerid, issuerid, amount, weaponid, bodypart); #endif
Code:
CallLocalFunction("OnPlayerDeathEx", "ddd", playerid, killerid, reason); CallLocalFunction("OnPlayerDie", "ddd", playerid, killerid, reason); CallLocalFunction("OnPlayerFakeKill", "ddd", playerid, killerid, reason);
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; }
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).