14.09.2010, 06:33
Код:
#define bit(%1) (1 << %1)
#define setBit(%1,%2) %1 |= bit(%2)
#define unsetBit(%1,%2) %1 ^= bit(%2)
#define getBit(%1,%2) ((%1 & bit(%2)) != 0)
#define setAllBits(%1) %1 = 2147483647
#define unsetAllBits(%1) %1 = 0
stock encodeBits({bool}:...)
{
new
result = getarg(0),
num = numargs(),
arg;
while(++arg < num)
{
if(getarg(arg))
{
setBit(result, arg);
}
}
return result;
}
PRIVATE - Converts a bit in a value, for the functions.
Example: bit(2) is 4 and bit(3) is 8.
setBit(var, slot)
Sets the bit 'slot' (from 0 to 31) of a var to true.
unsetBit(var, slot)
Sets the bit 'slot' (from 0 to 31) of a var to false.
getBit(var, slot)
Returns the bit 'slot' (from 0 to 31) of a var.
setAllBits(var)
Sets all bits of a var to true.
unsetAllBits
Sets all bits of a var to false.
Example:
Код:
enum
{
Connected,
Logged,
Spawned,
Dead
}
new
pBools[MAX_PLAYERS];
OnPlayerDeath(playerid, killerid, reason)
{
unsetBit(pBools[playerid], Spawned);
setBit(pBools[playerid], Dead);
return 1;
}
OnPlayerRequestSpawn(playerid)
{
if(!getBit(pBools[playerid], Logged)) return 0;
return 1;
}
OnPlayerSpawn(playerid)
{
if(getBit(pBools[playerid], Dead))
{
SendClientMessage(playerid, COLOR_WHITE, "You was dead");
unsetBit(pBools[playerid], Dead);
}
setBit(pBools[playerid], Spawned);
return 1;
}
OnPlayerConnect(playerid)
{
setBit(pBools[playerid], Connected);
return 1;
}
OnPlayerDisconnect(playerid, reason)
{
unsetAllBits(pBools[playerid]);
return 1;
}
Returns a set of bit of values "bools". It's like encode_tires or encode_lights, so it's "universal"...
Example:
Код:
new
panels,
doors,
lights,
tires;
GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, encodeBits(true, true, false, true));

