flags/math help [2, 4, 8, 16, 32, etc]
ok, this has been bothering me for a while so im just gonna ask on here. The reason I want this is not exactly directly amxx related, but related to many forms of code.
In AMXX there is the player flags. a-u, and I am assuming they use the values 1,2,4,8,16,32,64,128,256,512,1024,2048, etc... (If this is not the case then please help me anyways because as I said i have been wondering for a while.) when you have something like this you can have a variety of different options selected and store it as a single value because no combination of them will ever equal another. so how do you read it? if i had the number 69, how do i know that its 64, 4, and 1? There has to be a mathematical formula to figure it out but i can't get it. again I know that this is not directly connected with AMXX although I am sure it is used in some way or form, and I know when writing I have often wondered how it is done. If anyone can help thankyou very much. If this is removed since it does not apply to this "Support / Help - Find help for general AMXX issues. This does not include support for individual 3rd party plugins." then thanks anyways.. |
Re: help?
The more serious issue, that this thread would be deleted regarding, is your choice of "help?" as a thread topic. Please fix that before responding again.
Generally you wouldn't be asking which numbers is 69 comprised of. Instead you'd be asking, is x in y? You'd do that in either an if/endif or switch/case statement. |
Re: flags/math help [2, 4, 8, 16, 32, etc]
thanks. i changed the title
also i discovered a method to get it done, but i was wondering if there is a simpler way, since with this you have to count down backwards through them till you find the one you want. Just wondering if there is a more direct way. anyways this is what I am doing: Code:
Dim tmpcntInt As Integer, tmpInt As Integer, max As Long, i As Integeranyways I am getting the value from memory via pointer+offset, then making a copy of it to make it easyer to make changes to the value later. as you can see I had to hard code the max value of what I wanted to find (in this case I went up to 28 flags, and at 28 it happens to equal what the hard coded max value is. the boolean: StorMove(i) is where I store the flag values. if there is a simpler method please let me know. or if this is how its supposed to be done then please also let me know. |
Re: flags/math help [2, 4, 8, 16, 32, etc]
Have you ever heard about binary numeral system?
To convert your decimal number to binary number use this: PHP Code:
PHP Code:
|
Re: flags/math help [2, 4, 8, 16, 32, etc]
Rather than..
Code:
If StarMove(n) Then doStuffCode:
Const ONE As Integer = 1 |
Re: flags/math help [2, 4, 8, 16, 32, etc]
Just bumping this down to scripting help...since its kinda odd being in General AMXx issues.
|
Re: flags/math help [2, 4, 8, 16, 32, etc]
I'll just copy & paste what I'm using in my plugin.
First you'll define flags you want to store: Code:
#define FLAG_LOGGINGIN 1 << 0Code:
You can use it like this: Code:
Hope it helps. It's also very fast this way. |
Re: flags/math help [2, 4, 8, 16, 32, etc]
Just one teeny point ...
This is a little much effort: Code:
#define FLAG_LOGGINGIN 1 << 0Code:
enum <<=1 |
Re: flags/math help [2, 4, 8, 16, 32, etc]
You can't use either in VB6. :)
|
Re: flags/math help [2, 4, 8, 16, 32, etc]
Ah. I forgot that this post in Scripting Help was actually aboot VB ...
I would have posted something relevant, but if I see any more VB I shall either cry or shoot something. It's such an ugly language. Euch. |
| All times are GMT -4. The time now is 11:03. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.