AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [INFO] Bitsums and Operators (https://forums.alliedmods.net/showthread.php?t=90507)

ConnorMcLeod 10-26-2013 18:17

Re: [INFO] Bitsums and Operators
 
~1 = 0xFFFFFFFE
~0 = 0xFFFFFFFF

LoL

edon1337 01-08-2017 06:33

Re: [INFO] Bitsums and Operators
 
Quote:

Instead of
We have:
PHP Code:

if (bistum_is_alive & (1<<id))
{



Sorry for bumping but bistum ^_^

XSlayer 07-26-2022 03:42

Re: [INFO] Bitsums and Operators
 
Great tutorial! but i have somes doubts

PHP Code:

if (bistum_is_alive & (1<<id)) // if this is checking if is user alive, how can i check is isnt alive? using this same method
{


and how can i make it more "manipulable", like

PHP Code:

 MyVar |= (1<<id// Setting to true 
         
Myvar &=  ~(1<<id)  // Setting to false 

PHP Code:

stock SetVarStatusbool:Status, Var, id )
{
    switch(
Status)
    {
        case 
true:
        {
               Var |= (
1<<id)
        }
        case 
false:
        {
               Var &=  ~(
1<<id)
        }
     }


something like this but better?

Solved:

PHP Code:

#include <amxmodx>
 
#define SetPlayerBit(%1,%2)      (%1 |= (1<<(%2&31)))
#define ClearPlayerBit(%1,%2)    (%1 &= ~(1 <<(%2&31)))
#define CheckPlayerBit(%1,%2)    (%1 & (1<<(%2&31)))

new BitSumTest;

public 
plugin_init () 

    
register_plugin"Test""1.0""XSlayer" );
    
register_clcmd"bit""bitsum" );

public 
bitsumClient )
{
       if(!
CheckPlayerBitBitSumTestClient )) // if is false
       
{
             
SetPlayerBit(BitSumTestClient);
             
client_printClientprint_chat"BitSum Status: %d"CheckPlayerBitBitSumTestClient )); // setting to true
       

       else 
// if is true
       
{
             
ClearPlayerBit(BitSumTestClient);
             
client_printClientprint_chat"BitSum Status: %d"CheckPlayerBitBitSumTestClient )); // setting to false
       
}
       return 
1;



fysiks 07-26-2022 22:33

Re: [INFO] Bitsums and Operators
 
You should provide the source for the code that you found so that 1) people can see where it came from and 2) give credit to the original author.

Source is here: https://forums.alliedmods.net/showthread.php?t=139916


All times are GMT -4. The time now is 04:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.