This is nothing special but i find it incredibly useful and wonder why nobody uses this technique (at least i didn't saw something like that in another plugin).
If you write big plugins, things can get complicated and you might end up with resetting 20 variables on ClientDisconnect.
I still don't know exactly how to use bitwise operators, which brought me to the idea to use them in my scripts.
This was intended as a "library" for my own includes, but i think this will be useful to someone else too.
Well, here is an simple example that should explain what the purpose of this includefile is.
public OnPluginStart() { RegConsoleCmd("sm_test", Command_Test);
// Set our flags if you reload the Plugin if(g_bLateLoaded) { for(new i; i <= MaxClients; i++) { if(IsClientValid(i)) { OnClientPostAdminCheck(i); } } } }
// Define example flags for us to use
// If a player has genericflags we set this to him #define IS_ADMIN (1 << 0)
// If a players has rootflags set this to him #define HAS_MESSAGE (1 << 1)
public Action:Command_Test(client, args) { if(IsClientValid(client)) { if(HasCustomClientFlag(client, IS_ADMIN)) { PrintToChat(client, "Congratulations, you are an admin!"); }
if(HasCustomClientFlag(client, HAS_MESSAGE)) { PrintToChat(client, "Congratulations, you will get an message!"); } }
public OnClientDisconnect(client) { if(IsClientValid(client)) { // If an client has custom flags set, remove them if(GetCustomClientFlags(client) > 0) { SetCustomClientFlags(client, 0); } } }
Notes
From what i've found out you can store ~30 flags until they start again from zero.
You can use this for example to limit native calls to things like: IsFakeClient, IsPlayerAlive, etc
Of course you can group your flags, for example:
* 0.6
Fixed return and prototype of SetCustomClientFlags and some other functions
Added experimental function IsValidCustomFlag
Added experimental function GetNextValidCustomFlag
Added experimental function GetPreviousValidCustomFlag