[INC] Customflags 0.6 Beta
2 Attachment(s)
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.
Example #1
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:
Example
Changelog
Tell me what you think Yours sincerely Impact |
Re: [INC] Customflags 0.5 Beta
Doesn't SMLIB have these functions? Or somewhat similar ones? Correct me if I'm wrong (which I probably am)
|
Re: [INC] Customflags 0.5 Beta
Smlib has an wonderful makro called LOOP_CLIENTS where you can pass one or more clientfilters defines.
Something like i wrote i saw nowhere till now. Maybe you can show me this function? Yours sincerely Impact |
Re: [INC] Customflags 0.6 Beta
Oh nvm, I was only looking at the IS_ADMIN. That's the only a-like function I see from SMLIB.
|
Re: [INC] Customflags 0.6 Beta
The problem with the given example is that it ignores anything other plugins are doing. For example, if another plugin does this:
PHP Code:
This is the same problem you'd have if you called GetConVarSomething in OnAllPluginsLoaded or OnConfigsExecuted rather than when you actually need the value... something else may change it first. For that matter, to check if a flag is present, you can already just do this: PHP Code:
You're limited to 32 flags because that's how many bits you have in a cell. |
Re: [INC] Customflags 0.6 Beta
Yes you are right, it really depends on what you doing with it.
If you use if as a cache for like IsPlayerAlive (together with a hook ofc) or IsFakeClient that should work fine. &= seems to be correct, at least it is docmented like that, for example here and don't get the right results with =. I think it is better to look over a function, than over a statement for the same reason we use defines for some variables. Note: I think the spelling is bad, i might fix it later. Yours sincerely Impact |
Re: [INC] Customflags 0.6 Beta
Not quite sure about the purpose of this. The only reason you would want to stack boolean states into 1 cell is when you are very low on memory and really really care about speed. But in this case, your interface is quite cumbersome. In my plugins, if I want to store a boolean state of client, I just do
PHP Code:
|
Re: [INC] Customflags 0.6 Beta
Wow, looking at this topic again, I have no idea why I was using ^= HAS_MESSAGE to unset flags rather than &= ^HAS_MESSAGE
Quote:
|
Re: [INC] Customflags 0.6 Beta
Let's solve it once and for all:
Get PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
| All times are GMT -4. The time now is 11:43. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.