pawn Код:
new Text3D:label[MAX_PLAYERS];
CMD:adminduty(playerid, params[])
{
if(!PInfo[playerid][Level]) return SendClientMessage(playerid, STEALTH_BLUE, "You need to be level 1 to go on admin duty.");
CMDMessageToAdmins(playerid, "ADMINDUTY");
new string[55], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
if(!PInfo[playerid][pAdminDuty])
{
PInfo[playerid][God] = PInfo[playerid][GodCar] = PInfo[playerid][pAdminDuty] = 1;
SetPlayerHealth(playerid, 0x7F800000);
SetPlayerSkin(playerid, 217);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 38, 99999);
format(string, sizeof(string), "Administrator %s is now on Admin Duty.", pName);
label[playerid] = Create3DTextLabel("!!ADMIN ON DUTY\nDO NOT ATTACK!!!", COLOR_GREEN, 30.0, 40.0, 50.0, 40.0, 0);
Attach3DTextLabelToPlayer(label[playerid], playerid, 0.0, 0.0, 0.7);
}
else if(PInfo[playerid][pAdminDuty])
{
PInfo[playerid][God] = PInfo[playerid][GodCar] = PInfo[playerid][pAdminDuty] = 0;
format(string, sizeof(string), "Administrator %s is now off Admin Duty.", pName);
SetPlayerHealth(playerid, 0.0); //Really? Why 0 health?
Delete3DTextLabel(label[playerid]);
}
SendClientMessageToAll(COLOR_MENUHIGHLIGHT, string);
return 1;
}
The 'new Text3D:label[MAX_PLAYERS]' line needs to go at the top of your script. This is a global variable, so you have a value saved when you attempt to delete it.
Also, you were using an 'else' statement, when you should have been using an 'else if' statement.
Basically:
pawn Код:
new variable = 0;
if(variable == 0)
{
variable = 1;
}
else
{
variable = 0;
}
Variable starts off as 0, so the first 'if' statement gets called. Variable is now equal to '1'. Once we reach the 'else' statement, the variable is not equal to 0 anymore, so this else statement gets called. Variable is now equal to 0 again, so we're back where we started.
By using an 'else if' statement, this pretty much decides which one should be called at the time the first 'if' statement is called.
References:
https://sampwiki.blast.hk/wiki/Control_Structures