08.04.2012, 21:58
Bit Flags 0.1
Target Skill SetThis include is geared towards beginner & intermediate scripter's.
While bit manipulation is not new at all, it is often a hard concept to understand.
You have to know about how binary numbers work and the likes...
However this could save even an advanced scripter some time.
Introduction
What is Bit_Flag 0.1 you ask?
Bit_Flag 0.1 is a set of functions to make it simple to store/check/update/delete multiply flags in a single variable.
What kinda advantages does this have?
In short you could store 32 values in one integer.
The advantage should be clear here, saving memory.
How does this save memory?
Well look at this example..
You have 32 vars in your mode,
each var is one integer(cell in pawn) making you use the memory space of 32 integers
You could store ALL 32 values in one single integer letting you use only the memory
space of 1 integer.
Functions
Check for ALL Flags :
pawn Code:
public Check_All_Bit_Flags(flags,{Float,_}:...);
pawn Code:
public Check_Any_Bit_Flags(flags,{Float,_}:...);
pawn Code:
public Check_Bit_Flag(flags,flag);
pawn Code:
public Add_Bit_Flag(&flags,flag);
pawn Code:
public Add_Bit_Flags(&flags,{Float,_}:...);
pawn Code:
public Remove_Bit_Flag(&flags,flag);
pawn Code:
public Remove_Bit_Flags(&flags,{Float,_}:...);
pawn Code:
public Remove_All_Bit_Flags(&flags);
But basically they just allow you to set/check/remove more than 1 flag at a time
and all depend on the functions I have already shown.
Useage
I will describe in short the usage of these functions.
I plan a tutorial later with more details on this.
For the sake of this demo I will not be going into how to load/save these flags.
You'll already need some sort of saving system, be it MYSQL, file based or one of the
many ini systems.
Scenario:
I am setting up a GM that will have 4 Different Types of groups.(not teams)
I will have 4 different Flags for deciding what player can access what .
So I start out by defining my flags.
pawn Code:
BitFlag:
{
FLAG_ADMIN= 1,
FLAG_MOD,
FLAG_VIP,
FLAG_Dev
}
this is very important as it sets up the rest of the values in our BitFlag define.
this is the same as doing
pawn Code:
enum (<<= 1)
{
FLAG_ADMIN= 1,
FLAG_MOD,
FLAG_VIP,
FLAG_Dev
}
normally your PlayerInfo would look along the lines of this(i dont have ALL my info just enough for this demo)
pawn Code:
enum ePlayerInfo
{
//other vars up here
pAdmin,
pMod,
pDev,
pVip
}
pawn Code:
enum ePlayerInfo
{
//other vars up here
pFlags
}
aPlayerIno[MAX_USERS][ePlayerInfo];
Now i will show you how to add/check/remove these flags
WHERE you do this is up to you and your system of loading/saving.
Add a flag
in this case the admin flag.
pawn Code:
Add_Bit_Flag(aPlayerIno[playerid][pFlags],FLAG_ADMIN);
pawn Code:
Check_Bit_Flag(aPlayerIno[playerid][pFlags],FLAG_ADMIN);
pawn Code:
Remove_Bit_Flag(aPlayerIno[playerid][pFlags],FLAG_ADMIN);
Download
SolidFiles
PasteBin
Credits
Jonny5 : Creator of Bit_Flags0.1
SAMP Team : For this wonderful mod you have given us!
SAMP Community Gurus(all you guys help us to improve our skill sets, thank you!)
Authors Notes...
This is my first release to the SAMP community,
I EXPECT you guys to find flaws with this include and topic.
Please post any bugs and suggestions in this topic.