From c3fcf0d4be8287ccd5490472c75b0f0ad0d56116 Mon Sep 17 00:00:00 2001 From: iAmir Date: Thu, 7 Mar 2024 03:17:00 +0330 Subject: [PATCH 1/3] fix OnPlayerSpawn not being called when filterscript starts --- _fixes_options.inc | 2 ++ fixes.inc | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/_fixes_options.inc b/_fixes_options.inc index 9703f04..9ebac1d 100644 --- a/_fixes_options.inc +++ b/_fixes_options.inc @@ -341,6 +341,8 @@ #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. #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..2e56220 100644 --- a/fixes.inc +++ b/fixes.inc @@ -7588,6 +7588,46 @@ _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 + /* 88b d88 @@ -17423,6 +17463,25 @@ public OnJITCompile() // ================= #endif #endif + + // Just like above with "OnPlayerConnect", if you don't have + // "OnPlayerSpawn" script it's your fault! Just disable the fix! + #if FIX_OnPlayerSpawnCall + // ======================== + // BEGIN: OnPlayerSpawn + // ======================== + // 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: OnPlayerSpawn + // ======================== + #endif } } #endif From 696553a063e720c60d02de624749eaef326681ec Mon Sep 17 00:00:00 2001 From: iAmir Date: Thu, 7 Mar 2024 03:26:26 +0330 Subject: [PATCH 2/3] fix OnPlayerStateChange not being called on FS start Player obviously has a state! --- _fixes_options.inc | 2 ++ fixes.inc | 64 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/_fixes_options.inc b/_fixes_options.inc index 9ebac1d..29fc15b 100644 --- a/_fixes_options.inc +++ b/_fixes_options.inc @@ -343,6 +343,8 @@ #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. #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 2e56220..d3bfadb 100644 --- a/fixes.inc +++ b/fixes.inc @@ -7628,6 +7628,46 @@ _FIXES_FUNC_PAWNDOC(_FIXES_IS_UNSET(const symbol[])); #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 + /* 88b d88 @@ -17464,11 +17504,11 @@ public OnJITCompile() #endif #endif - // Just like above with "OnPlayerConnect", if you don't have - // "OnPlayerSpawn" script it's your fault! Just disable the fix! + // Just like above, if you don't have "OnPlayerSpawn" + // script it's your fault! Just disable the fix! #if FIX_OnPlayerSpawnCall // ======================== - // BEGIN: OnPlayerSpawn + // 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 @@ -17479,7 +17519,23 @@ public OnJITCompile() OnPlayerSpawn(playerid); } // ======================== - // END: OnPlayerSpawn + // 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 } From 9086c6282a82020baac71b90d69b8fc3be858a37 Mon Sep 17 00:00:00 2001 From: iAmir Date: Thu, 7 Mar 2024 03:38:11 +0330 Subject: [PATCH 3/3] fix OnPlayerKeyStateChange not being called on FS start Maybe player is holding a key so your script never knows it's happening unless they press or unpress another key --- _fixes_options.inc | 2 ++ fixes.inc | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/_fixes_options.inc b/_fixes_options.inc index 29fc15b..014894d 100644 --- a/_fixes_options.inc +++ b/_fixes_options.inc @@ -345,6 +345,8 @@ #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 d3bfadb..9da9219 100644 --- a/fixes.inc +++ b/fixes.inc @@ -7668,6 +7668,48 @@ _FIXES_FUNC_PAWNDOC(_FIXES_IS_UNSET(const symbol[])); #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 @@ -17538,6 +17580,24 @@ public OnJITCompile() // 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