One more thing to consider. You might wanna change
to a MAX_PLAYERS array
Код:
new PMEnabled[MAX_PLAYERS] = 1;
Because the one you have currently is setting the variable for ALL players, and one player would be able to toggle it for ALL the players online. So I'm assuming you have a togpm command, your toggle pm command should look like this.
pawn Код:
CMD:togpm(playerid,params[])
{
if(PMEnabled[playerid] == 1)
{
PMEnabled = 0;
SendClientMessage(playerid,color,"PM disabled.");
return 1;
}
else if(PMEnabled[playerid] == 0)
{
PMEnabled = 1;
SendClientMessage(playerid,color,"PM enabled.");
return 1;
}
return 1;
}
and your PM command should look like this.
pawn Код:
CMD:pm(playerid, params[])
{
if(IsPlayerConnected(playerid))
{
new pID, Message[60], SenderName[MAX_PLAYER_NAME], RecieverName[MAX_PLAYER_NAME], string[128], string2[128];
if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, COLOR_ORANGE, "SYNTAX: /pm [PlayerID/PlayerName] [Message]");
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid Player");
if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
GetPlayerName(pID, RecieverName, sizeof(RecieverName));
GetPlayerName(playerid, SenderName, sizeof(SenderName));
format(string, sizeof(string), "Private message from %s: %s", SenderName, Message);
format(string2, sizeof(string2), "Private message to %s: %s", RecieverName, Message);
PMLog(string2);
PMLog(string);
SendClientMessage(playerid, -1, string2);
SendClientMessage(pID, -1, string);
}
return 1;
}
The change I made was this
pawn Код:
if(PMEnabled[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Private Messaging is disabled.");
notice the [playerid]? So this small change would make your PM command more efficient in a user-interface way.