15.08.2013, 14:36
Ok, lets say that I want to make /duty command(admin duty on/off).
EDIT: here's another example
* I'm not sure here, is it 0?
pawn Код:
//in normal way
new bool:Duty[MAX_PLAYERS];
CMD:duty(playerid)
{
if(Duty[playerid] == false)
{
SendClientMessage(playerid, -1, "You are now on duty.");
Duty[playerid] = true;
}
else
{
SendClientMessage(playerid, -1, "You are now off duty.");
Duty[playerid] = false;
}
return 1;
}
//So can I use bit-flags and ternary operator together to create that command?
EDIT: here's another example
pawn Код:
enum DutyFlag:(<< = 1)
{
Duty = 1
}
new DutyFlag:g_Duty[MAX_PLAYERS];
//OnPlayerConnect
g_Duty[playerid] = DutyFlag:0;
//Ok so, the main question is, can I change if-else statement in the command below to ternary operator?
CMD:duty(playerid)
{
if(g_Duty[playerid] & Duty) *
{
g_Duty[playerid] |= Duty;
SendClientMessage(playerid, -1, "Now on duty!");
}
else
{
g_Duty[playerid] &= Duty;
SendClientMessage(playerid, -1, "Now off duty!");
}
return 1;
}