Quote:
Originally Posted by Mitchell
Just making sure, ill have to test this at a later moment but say if i want to show it to only one player i would just make the bitstring: "2^(clientindex)" correct?
|
For bitfields, why not just use (left) bitshifting? That's what it exists for.
The only catch is that I'm not sure if it counts from 0 or not.
So, here's both versions... try both and see if they work.
PHP Code:
new bitfield = 0;
// Iterating through all clients to build a visibility bitfield of all alive players
for (new client = 1; client <= MaxClients; i++)
{
if (IsClientInGame(client) && IsPlayerAlive(client))
{
// 1-based
bitfield |= (1 << client);
// 0-based
//bitfield |= (1 << (client - 1));
}
}
// or for a single client
new bitfield = (1 << client);
(I'm assuming 1-based is correct based on glancing at the gravestone plugin's BuildBitString)
Edit: For those of you who don't know what bitshifting does, I'll give a quick example.
Pretend this is a series of 8 bits: 0b00000000 (0b is used to denote it's binary... it's a GCC thing)
Like a standard decimal, the lowest number is the one at the far right. What (1 << client) does is tell it to take the number 1 and move it to the left client bits. So:
Code:
(1 << 0) = 0b00000001
(1 << 1) = 0b00000010
(1 << 2) = 0b00000100
and there are 32-bits to a cell in Pawn.
It's a cheap way of storing a bunch of bools as a single value.
__________________