diff --git a/_fixes_options.inc b/_fixes_options.inc index 9703f04..014894d 100644 --- a/_fixes_options.inc +++ b/_fixes_options.inc @@ -341,6 +341,12 @@ #warning Option `FIX_memcpy` must now be explicit. #elseif _FIXES_WARNING == 144 #warning Option `FIX_SHA256` must now be explicit. +#elseif _FIXES_WARNING == 145 + #warning Option `FIX_OnPlayerSpawnCall` must now be explicit. +#elseif _FIXES_WARNING == 146 + #warning Option `FIX_OnPlayerStateChange` must now be explicit. +#elseif _FIXES_WARNING == 147 + #warning Option `FIX_OnPlayerKeyStateChange` must now be explicit. #else #error `_fixes_options.inc` included, but `_FIXES_WARNING` is not set to a valid warning message. #endif diff --git a/fixes.inc b/fixes.inc index e646586..9da9219 100644 --- a/fixes.inc +++ b/fixes.inc @@ -7588,6 +7588,128 @@ _FIXES_FUNC_PAWNDOC(_FIXES_IS_UNSET(const symbol[])); #define FIX_SHA256 (0) #endif +/** + * fixes.inc + * + * + * This function isn't called for players who are already spawned when a filterscript starts. + * + * + * Call it for all spawned players. + * + * On_FilterScriptInit + * iAmir + * + */ + +#if _FIXES_NPC + #if defined FIX_OnPlayerSpawnCall + #undef FIX_OnPlayerSpawnCall + #endif + static stock FIX_OnPlayerSpawnCall = 0; + #define FIX_OnPlayerSpawnCall (0) +#elseif !defined FIX_OnPlayerSpawnCall + #define _FIXES_WARNING 145 + #tryinclude "_fixes_options" + #undef _FIXES_WARNING + static _FIXES_OPTION FIX_OnPlayerSpawnCall = _FIXES_DEFAULT; + #define FIX_OnPlayerSpawnCall _FIXES_DEFAULT +#elseif _FIXES_IS_UNSET(FIX_OnPlayerSpawnCall) + #undef FIX_OnPlayerSpawnCall + static stock FIX_OnPlayerSpawnCall = 2; + #define FIX_OnPlayerSpawnCall (2) +#elseif FIX_OnPlayerSpawnCall + #undef FIX_OnPlayerSpawnCall + static stock FIX_OnPlayerSpawnCall = 1; + #define FIX_OnPlayerSpawnCall (1) +#else + #undef FIX_OnPlayerSpawnCall + static stock FIX_OnPlayerSpawnCall = 0; + #define FIX_OnPlayerSpawnCall (0) +#endif + +/** + * fixes.inc + * + * + * This function isn't called for players who are already in the server with state when a filterscript starts. + * + * + * Call it for all players. + * + * On_FilterScriptInit + * iAmir + * + */ + +#if _FIXES_NPC + #if defined FIX_OnPlayerStateChange + #undef FIX_OnPlayerStateChange + #endif + static stock FIX_OnPlayerStateChange = 0; + #define FIX_OnPlayerStateChange (0) +#elseif !defined FIX_OnPlayerStateChange + #define _FIXES_WARNING 146 + #tryinclude "_fixes_options" + #undef _FIXES_WARNING + static _FIXES_OPTION FIX_OnPlayerStateChange = _FIXES_DEFAULT; + #define FIX_OnPlayerStateChange _FIXES_DEFAULT +#elseif _FIXES_IS_UNSET(FIX_OnPlayerStateChange) + #undef FIX_OnPlayerStateChange + static stock FIX_OnPlayerStateChange = 2; + #define FIX_OnPlayerStateChange (2) +#elseif FIX_OnPlayerStateChange + #undef FIX_OnPlayerStateChange + static stock FIX_OnPlayerStateChange = 1; + #define FIX_OnPlayerStateChange (1) +#else + #undef FIX_OnPlayerStateChange + static stock FIX_OnPlayerStateChange = 0; + #define FIX_OnPlayerStateChange (0) +#endif + +/** + * fixes.inc + * + * + * This function isn't called for players who are already in the server holding or pressing a key when a filterscript starts. + * So this way it calls OnPlayerStateChange to make sure script never misses user action based code execution just key state + * didn't change to call it yet. + * + * + * Call it for all players. + * + * On_FilterScriptInit + * iAmir + * + */ + +#if _FIXES_NPC + #if defined FIX_OnPlayerKeyStateChange + #undef FIX_OnPlayerKeyStateChange + #endif + static stock FIX_OnPlayerKeyStateChange = 0; + #define FIX_OnPlayerKeyStateChange (0) +#elseif !defined FIX_OnPlayerKeyStateChange + #define _FIXES_WARNING 147 + #tryinclude "_fixes_options" + #undef _FIXES_WARNING + static _FIXES_OPTION FIX_OnPlayerKeyStateChange = _FIXES_DEFAULT; + #define FIX_OnPlayerKeyStateChange _FIXES_DEFAULT +#elseif _FIXES_IS_UNSET(FIX_OnPlayerKeyStateChange) + #undef FIX_OnPlayerKeyStateChange + static stock FIX_OnPlayerKeyStateChange = 2; + #define FIX_OnPlayerKeyStateChange (2) +#elseif FIX_OnPlayerKeyStateChange + #undef FIX_OnPlayerKeyStateChange + static stock FIX_OnPlayerKeyStateChange = 1; + #define FIX_OnPlayerKeyStateChange (1) +#else + #undef FIX_OnPlayerKeyStateChange + static stock FIX_OnPlayerKeyStateChange = 0; + #define FIX_OnPlayerKeyStateChange (0) +#endif + /* 88b d88 @@ -17423,6 +17545,59 @@ public OnJITCompile() // ================= #endif #endif + + // Just like above, if you don't have "OnPlayerSpawn" + // script it's your fault! Just disable the fix! + #if FIX_OnPlayerSpawnCall + // ======================== + // BEGIN: OnPlayerSpawnCall + // ======================== + // If it's any state other than the ones below, it means player + // has surely been spawned once, so let's call it because then how + // would filterscript process that and user's code related to spawn + // get executed? + if (GetPlayerState__(playerid) != PLAYER_STATE_WASTED && GetPlayerState__(playerid) != PLAYER_STATE_NONE && GetPlayerState__(playerid) != PLAYER_STATE_SPECTATING) + { + OnPlayerSpawn(playerid); + } + // ======================== + // END: OnPlayerSpawnCall + // ======================== + #endif + + // This time since we don't have any "OnPlayerStateChange" defined + // we use "CallLocalFunction" for it + #if FIX_OnPlayerStateChange + // ======================== + // BEGIN: OnPlayerStateChange + // ======================== + // If state is not "none", then let's call OnPlayerStateChange + if (GetPlayerState__(playerid) != PLAYER_STATE_NONE) + { + CallLocalFunction("OnPlayerStateChange", "iii", playerid, GetPlayerState__(playerid), PLAYER_STATE_NONE); + } + // ======================== + // END: OnPlayerStateChange + // ======================== + #endif + + // Just like above, if you don't have "OnPlayerKeyStateChange" + // script it's your fault! Just disable the fix! + #if FIX_OnPlayerKeyStateChange + // ======================== + // BEGIN: OnPlayerKeyStateChange + // ======================== + // If key value is not 0, then let's call OnPlayerKeyStateChange + new KEY:keys, KEY:updown, KEY:leftright; + GetPlayerKeys__(playerid, keys, updown, leftright); + if (_:keys != 0) + { + OnPlayerKeyStateChange(playerid, keys, KEY:0); + } + // ======================== + // END: OnPlayerStateChange + // ======================== + #endif } } #endif