enum e_Bit8_pData
{
e_AdminLevel,
e_Rank
};
new
Bit8: pData_8Bit[e_Bit8_pData] <MAX_PLAYERS>
;
Bit8_Set(e_Bit8_pData[e_AdminLevel], playerid, someLevel);
Bit8_Set(e_Bit8_pData[e_Rank], playerid, someRank);
new
Bit16: numPlayerObjects <MAX_PLAYERS>
;
Bit16_Set(numPlayerObjects, playerid, Bit16_Get(numPlayerObjects, playerid) + 1);
|
You can sort enums by bit type like for example for 8 bits data:
pawn Код:
pawn Код:
Increment like this: pawn Код:
|
|
I mean, I have an enum, and want to use the enum.
@Edit, How do I increment or decrease a value? Ah, nevermind, I use bitx_get() + 1. Right? |
#define BitSetEx%0(%1, %2, %3, %4) %0_Set(%1, %2, %0_Get(%1, %2) %3 %4)
BitSetEx Bit4 ( iVar, id, + , 5 );
// Bit1 support only true/false
|
lol i try to make something like macro fnc for that here it is
pawn Код:
pawn Код:
|
stock TogglePlayerIntro(playerid, toggle)
return Bit1_Set(PlayingIntro, playerid, toggle);
stock IsPlayingIntro(playerid)
return Bit1_Get(PlayingIntro, playerid);
stock GetPlayerDeaths(playerid)
return Bit16_Get(Deaths, playerid);
stock GetPlayerKills(playerid)
return Bit16_Get(Deaths, playerid);
stock SetPlayerDeaths(playerid, deaths)
return Bit16_Set(Deaths, playerid, deaths);
stock SetPlayerKills(playerid, kills)
return Bit16_Set(Deaths, playerid, kills);
stock IncreasePlayerDeaths(playerid)
return Bit16_Set(Deaths, playerid, Bit16_Get(Deaths, playerid) + 1);
stock IncreasePlayerKills(playerid)
return Bit16_Set(Kills, playerid, Bit16_Get(Kills, playerid) + 1);
stock SetWrongPasswords(playerid, passes)
return Bit4_Set(WrongPassword, playerid, passes);
stock GetWrongPasswords(playerid)
return Bit4_Get(WrongPassword, playerid);
stock WrongPasswordIncrease(playerid)
return Bit4_Set(WrongPassword, playerid, Bit4_Get(WrongPassword, playerid) + 1);
stock GetPlayerVip(playerid)
return Bit4_Get(Vip, playerid);
stock SetPlayerVip(playerid, vip)
return Bit4_Set(Vip, playerid, vip);
stock GetPlayerLevel(playerid)
return Bit4_Get(Admin, playerid);
stock SetPlayerLevel(playerid, level)
return Bit4_Set(Admin, playerid, level);
stock SetLastON(playerid)
LastON[playerid] = GetDate();
stock GetLastON(playerid)
return LastON[playerid];
stock SetScore(playerid, score)
return Score{playerid} = score;
stock GetScore(playerid)
return Score{playerid};
stock SetMoney(playerid, money)
return Money{playerid} = money;
stock GetMoney(playerid)
return Money{playerid};
stock ToggleLogged(playerid, toggle)
return Bit1_Set(Logged, playerid, toggle);
stock IsLogged(playerid)
return Bit1_Get(Logged, playerid);
stock GetPlayerIntroPart(playerid)
return Bit4_Get(pIntroPart, playerid);
stock SetPlayerIntroPart(playerid, part)
return Bit4_Set(pIntroPart, playerid, part);
stock SetBitEx(biteType, iVar, playerid = INVALID_PLAYER_ID, bool:plus, value) {
switch(biteType) { case 2: {
if(value == true) return Bit2_Set(iVar, playerid, Bit2_Get(iVar, playerid) + value); // +
else Bit2_Set(iVar, playerid, Bit2_Get(iVar, playerid) - value); // -
} case 4: {
if(value == true) return Bit4_Set(iVar, playerid, Bit4_Get(iVar, playerid) + value); // +
else Bit4_Set(iVar, playerid, Bit4_Get(iVar, playerid) - value); // -
} case 8: {
if(value == true) return Bit8_Set(iVar, playerid, Bit8_Get(iVar, playerid) + value); // +
else Bit8_Set(iVar, playerid, Bit8_Get(iVar, playerid) - value); // -
} case 16: {
if(value == true) return Bit16_Set(iVar, playerid, Bit16_Get(iVar, playerid) + value); // +
else Bit16_Set(iVar, playerid, Bit16_Get(iVar, playerid) - value); // -
} } }
SetBitEx((2,4,8,16), Variable, playerid, true, 5); // Added +5
SetBitEx((2,4,8,16), Variable, playerid, false, 5); // Taked -5
But thanks for the tip.
|
What do you exactly mean by that? The examples are just examples on how to use it, don't get confused by that please.
|
g_VehiclePrice[vehicleid] = random(65535);
#define Bit<%0>:%1<%2> \
Bit%0: %1[((%2) + (32 / (Bit%0 + 1)) - 1) >>> _: (Bit32 - Bit%0)]
#define SetBit<%0>(%1,%2,%3) \
Bit_Set(%1, (%2), %3, Bit%0)
#define GetBit<%0>(%1,%2) \
Bit_Get(%1, (%2), Bit%0)
|
Since you have made the Bit_Set/Get functions general, how about making the whole syntax general?
pawn Код:
|

|
please put this in .pwn 'cause I got errors when I complie my script with this, I really want this
![]() good job ![]() |
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(1) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(71) : error 021: symbol already defined: "Bit_Set"
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(85) : error 001: expected token: "-identifier-", but found "("
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(91) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(92) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(94) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\gamemodes\iStunt.pwn(3902) : warning 203: symbol is never used: "bitLim"
D:\Private\A lot of shit\iStunt\gamemodes\iStunt.pwn(3902) : warning 203: symbol is never used: "bitVar"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
8 Errors.
|
Still doesn't work, I got this errors
pawn Code:
|
/*
SA-MP "rBits" Include
Copyright © 2011 RyDeR`
*/
#if defined _Included_rBits
#endinput
#endif
#define _Included_rBits
#define BIT_TAGS \
{ Bit1, Bit2, Bit4, Bit8, Bit16 }
enum e_Bits
{
Bit1,
Bit2,
Bit4,
Bit8,
Bit16,
Bit32
};
#define Bit1:%0<%1> \
Bit1: %0[((%1) + 31) >>> _: Bit32]
#define Bit1_Set(%0,%1,%2) \
Bit_Set(%0, (%1), (%2), Bit1)
#define Bit1_Get(%0,%1) \
Bit_Get(%0, (%1), Bit1)
#define Bit2:%0<%1> \
Bit2: %0[((%1) + 15) >>> _: (Bit32 - Bit2)]
#define Bit2_Set(%0,%1,%2) \
Bit_Set(%0, (%1), (%2), Bit2)
#define Bit2_Get(%0,%1) \
Bit_Get(%0, (%1), Bit2)
#define Bit4:%0<%1> \
Bit4: %0[((%1) + 7) >>> _: (Bit32 - Bit4)]
#define Bit4_Set(%0,%1,%2) \
Bit_Set(%0, (%1), (%2), Bit4)
#define Bit4_Get(%0,%1) \
Bit_Get(%0, (%1), Bit4)
#define Bit8:%0<%1> \
Bit8: %0[(%1) char]
#define Bit8_Set(%0,%1,%2) \
(_: %0{(%1)} = (%2))
#define Bit8_Get(%0,%1) \
(_: %0{(%1)})
#define Bit16:%0<%1> \
Bit16: %0[((%1) + 1) >>> _: (Bit32 - Bit16)]
#define Bit16_Set(%0,%1,%2) \
Bit_Set(%0, (%1), (%2), Bit16)
#define Bit16_Get(%0,%1) \
Bit_Get(%0, (%1), Bit16)
stock Bit_Set(BIT_TAGS: bitArr[], arrIdx, value, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
new
bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
bitLim = ((1 << (1 << _: bitShift)) - 1)
;
if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
return 0;
(_: bitArr[arrIdx]) &= ~(bitLim << bitVar);
(_: bitArr[arrIdx]) |= ((bitLim & value) << bitVar);
return 1;
}
stock Bit_Get(BIT_TAGS: bitArr[], arrIdx, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
new
bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
bitLim = ((1 << (1 << _: bitShift)) - 1)
;
if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
return 0;
return ((_: bitArr[arrIdx] >>> bitVar) & bitLim);
}
new
g_iBit1_pData[eBit1_pData] <MAX_PLAYERS>
;
new
Bit1:g_iBit1_pData[eBit1_pData] <MAX_PLAYERS>
;
rBits - 410bytes Normal way - 1,69 kilobyte.
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\YSI\y_bit.inc(245) : warning 209: function "Bit_Set" should return a value
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\YSI\y_bit.inc(248) : warning 209: function "Bit_Set" should return a value
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(71) : error 021: symbol already defined: "Bit_Set"
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(73) : warning 219: local variable "bitVar" shadows a variable at a preceding level
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(74) : warning 219: local variable "bitLim" shadows a variable at a preceding level
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(85) : error 001: expected token: "-identifier-", but found "("
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(91) : error 010: invalid function or declaration
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(92) : error 010: invalid function or declaration
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(94) : error 010: invalid function or declaration
C:\Documents and Settings\Kakarotto\Pulpit\LiveFor3Run.pwn(2299) : warning 203: symbol is never used: "bitLim"
C:\Documents and Settings\Kakarotto\Pulpit\LiveFor3Run.pwn(2299) : warning 203: symbol is never used: "bitVar"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
7 Errors.
#include "a_samp"
#include "streamer"
#include "sscanf"
#include "zcmd"
//#include "audio"
#include "live_textdraws"
#include "YSI\y_ini"
#include "YSI\y_groups"
#include "YSI\y_classes"
#include "rBits"