03.01.2017, 13:11
(
Последний раз редактировалось Lordzy; 05.02.2017 в 03:34.
)
script_compatibility.inc
Version - 1.0.1
Last update : 2nd of February, 2017
IntroductionVersion - 1.0.1
Last update : 2nd of February, 2017
This include enables your script to be easily compatible with gamemodes or filterscripts without any need of extra defines. It is mainly created for the includes that requires (#define FILTERSCRIPT) to make it run on filterscripts. Using this include, you no longer need to have such defines. Those includes using this doesn't require (FILTERSCRIPT) to be defined above your filterscript.
This include replaces the use of these callbacks : OnFilterScriptInit, OnFilterScriptExit, OnGameModeInit and OnGameModeExit. Instead, you'll need to use only the two callbacks that this include provides : OnScriptInit and OnScriptExit.
By using this include, you don't even have to define an entry point (main) on your gamemode which allows you to easily switch over filterscripts and gamemodes.
NOTE: You must define OnScriptInit and OnScriptExit in case if you're using this include. Simply remove OnFilterScriptInit, OnFilterScriptExit, OnGameModeInit and OnGameModeExit.
NOTE 2: Even though it replaces the above mentioned callbacks, you can still use them but it's totally unnecessary.
NOTE 3: If you're using YSI, you don't need this include since YSI library provides these callbacks already.
Functions & Callbacks
This is what the include provides currently:
pawn Код:
Callbacks:
public OnScriptInit(); (replaces OnFilterScriptInit and OnGameModeInit)
public OnScriptExit(); (replaces OnFilterScriptExit and OnGameModeExit)
Function:
native GetInitMode();
//Returns SCRIPT_MODE_FS if running as filterscript.
//Returns SCRIPT_MODE_GM if running as gamemode.
Constants by their default values:
SCRIPT_MODE_FS = 1
SCRIPT_MODE_GM = 2
Suppose you have an include that requires FILTERSCRIPT to be defined to know it should run for filterscript or not.
pawn Код:
//without using script_compatibility
#include <a_samp>
#if defined FILTERSCRIPT
public OnFilterScriptInit() {
//codes
//hooks
return 1;
}
public OnFilterScriptExit() {
//codes
//hooks
return 1;
}
//hooking these
#else //if FILTERSCRIPT is not defined
public OnGameModeInit() {
//codes
//hooks
return 1;
}
public OnGameModeExit() {
//codes
//hooks
return 1;
}
//hooks
#endif
pawn Код:
#include <a_samp>
#include <script_compatibility>
public OnScriptInit() {
//codes
//just hook OnScriptInit like a usual callback.
return 1;
}
public OnScriptExit() {
//codes
//just hook OnScriptExit like a usual callback.
return 1;
}
Changelog
script_compatibility - v1.0.1:
- Callbacks provided by this include are now optional. So there won't be any warnings if one among them is left unused.
script_compatibility - v1.0:
- Initial release.
Download
Github : https://github.com/Lordzy/script_compatibility
Raw source : https://raw.githubusercontent.com/Lo...patibility.inc
Example : https://raw.githubusercontent.com/Lo...mpleFSorGM.pwn