AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save Entity Index with BitSum (https://forums.alliedmods.net/showthread.php?t=338802)

XSlayer 07-26-2022 18:33

Save Entity Index with BitSum
 
Hi i wanted to know, how can i save an index for a client, with bitsums

PHP Code:

new __int_Entity[33];

public 
CreateEntityClient )
{
      
__int_Entity[Client] = create_entity"env_sprite" );
}
public 
RemoveEntityClient )
{
     if(
is_valid_ent(__int_Entity[Client]))
     {
         
entity_set_int__int_Entity[Client], EV_INT_flagsentity_get_int__int_Entity[Client], EV_INT_flags ) | FL_KILLME );        
     }
     
__int_Entity[Client]  = 0;



Bugsy 07-26-2022 18:43

Re: Save Entity Index with BitSum
 
May be more work than it's worth, what are you trying to accomplish?

XSlayer 07-26-2022 19:15

Re: Save Entity Index with BitSum
 
Quote:

Originally Posted by Bugsy (Post 2784949)
May be more work than it's worth, what are you trying to accomplish?

try to save all 33 cells and bytes, like

PHP Code:

new __int_Variable[33];

public 
TestClient )
{
       if(!
__int_Variable[Client])) // if is false
       
{
              
__int_Variable[Client] = 1;
       } 
       else 
// if is true
       
{
             
__int_Variable[Client] = 0;
       }


to

PHP Code:


#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 __int_Variable;

public 
TestClient )
{
       if(!
CheckPlayerBit__int_VariableClient )) 
       {
             
SetPlayerBit(__int_VariableClient);
       } 
       else 
       {
             
ClearPlayerBit(__int_VariableClient);
       }


but in this case for saving and index

Bugsy 07-26-2022 19:28

Re: Save Entity Index with BitSum
 
Take a look at the Manipulating bits outside of the bit-range of a memory cell section here https://forums.alliedmods.net/showthread.php?t=139916

I assume you are looking to store index's larger than 1 to 32, so you need to use an array which will give you increments of 32 for each cell used.

XSlayer 07-26-2022 19:32

Re: Save Entity Index with BitSum
 
Quote:

Originally Posted by Bugsy (Post 2784951)
Take a look at the Manipulating bits outside of the bit-range of a memory cell section here https://forums.alliedmods.net/showthread.php?t=139916

I assume you are looking to store index's larger than 1 to 32, so you need to use an array which will give you increments of 32 for each cell used.

yes I read it, but I don't fully understand that part, I understand about setting the bits to players, but not what continues, that's why the post

Bugsy 07-26-2022 19:52

Re: Save Entity Index with BitSum
 
Ok, I'll try to give you a quick visual

Lets use a 3-cell array

Cell 1 - 4 bytes/32 bits - 32 bits total
A single cell is perfect for player booleans since player ID's range from 1 to 32.
[ 0000 0000 ][ 0000 0000 ][ 0000 0000 ][ 0000 0000 ]

Cell 2 - 4 bytes/32 bits - 64 bits total
[ 0000 0000 ][ 0000 0000 ][ 0000 0000 ][ 0000 0000 ]

Cell 3 - 4 bytes/32 bits - 96 bits total
[ 0000 0000 ][ 0000 0000 ][ 0000 0000 ][ 0000 0000 ]

When you want to set bits beyond 32, you need to use an array, cell 2 holds bits 33 to 64, cell 3 holds 65-96, etc. Those macros do the work for you to set the appropriate bit.

HamletEagle 07-27-2022 02:07

Re: Save Entity Index with BitSum
 
Please don't do this in practice. There is absolutely no reason for it.

XSlayer 07-27-2022 02:11

Re: Save Entity Index with BitSum
 
Quote:

Originally Posted by HamletEagle (Post 2784977)
Please don't do this in practice. There is absolutely no reason for it.

and because??...

Bugsy 07-27-2022 07:59

Re: Save Entity Index with BitSum
 
This is why I asked for your use-case. It's not beneficial to use bit-wise operators/logic if you need to jump through hoops to accomplish it. There is likely a much simpler and economical way to do what are attempting

fysiks 07-28-2022 00:42

Re: Save Entity Index with BitSum
 
Quote:

Originally Posted by XSlayer (Post 2784979)
and because??...

You're using a modern computer for an ancient game engine, there won't be any issues with performance by using arrays.

Also, I have no idea what you're actually requesting. What does it even mean to "save an index"? Didn't you literally just write the code you needed in post #3? I think you'd need to provide context for what you are ACTUALLY trying to do so we can give you the best advice.


All times are GMT -4. The time now is 15:33.

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