Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixes for OnPlayerSpawn, OnPlayerKeyStateChange, OnPlayerStateChange #181

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _fixes_options.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
175 changes: 175 additions & 0 deletions fixes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7588,6 +7588,128 @@ _FIXES_FUNC_PAWNDOC(_FIXES_IS_UNSET(const symbol[]));
#define FIX_SHA256 (0)
#endif

/**
* <library>fixes.inc</library>
* <fix name="OnPlayerSpawnCall">
* <problem>
* This function isn't called for players who are already spawned when a filterscript starts.
* </problem>
* <solution>
* Call it for all spawned players.
* </solution>
* <see>On_FilterScriptInit</see>
* <author href="https://github.com/AmyrAhmady/" >iAmir</author>
* </fix>
*/

#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

/**
* <library>fixes.inc</library>
* <fix name="OnPlayerStateChange">
* <problem>
* This function isn't called for players who are already in the server with state when a filterscript starts.
* </problem>
* <solution>
* Call it for all players.
* </solution>
* <see>On_FilterScriptInit</see>
* <author href="https://github.com/AmyrAhmady/" >iAmir</author>
* </fix>
*/

#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

/**
* <library>fixes.inc</library>
* <fix name="OnPlayerStateChange">
* <problem>
* 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.
* </problem>
* <solution>
* Call it for all players.
* </solution>
* <see>On_FilterScriptInit</see>
* <author href="https://github.com/AmyrAhmady/" >iAmir</author>
* </fix>
*/

#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
Expand Down Expand Up @@ -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
Expand Down