08.08.2017, 18:14
PHP код:
CMD:offlineban(playerid, params[], help)
{
if(help)
{
SendClientMessage(playerid, COLOR_WHITE, "{AFAFAF}Command /offlineban: {FFFFFF}Bans a player who is offline.");
}
else
{
if(pInfo[playerid][pLogged] == 0) return 0;
if(pInfo[playerid][pAdminLevel] >= 4)
{
new string[158], reason[120], targetname[MAX_PLAYER_NAME], filestring[79], sendername[MAX_PLAYER_NAME]; // sendername needed to be declared
if(sscanf(params, "s[24]s[120]", targetname, reason)) return SendClientMessage(playerid, COLOR_WHITE, "{AFAFAF}Syntax: {FFFFFF}/offlineban [fullname] [reason]");
GetPlayerName(playerid, sendername, sizeof(sendername)); // Here in this line is where I throw the error.
format(filestring, sizeof(filestring), "/ZMA/Users/%s.ini", targetname);
if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_WHITE, "{AFAFAF}Error: {FFFFFF}Player doesn't exist.");
else
{
new INI:File = INI_Open(filestring));
INI_SetTag(File, "data");
INI_RemoveEntry(File, "Banned");
INI_WriteInt(File, "Banned", 1);
INI_Close(File);
format(string, sizeof(string),"{FF6347}Admin %s banned the offline player %s, reason: %s", sendername, targetname, reason);
SendClientMessageToAll(COLOR_WHITE, string);
}
} else return SendClientMessage(playerid, COLOR_WHITE, MinimumAdmin1); // {} + return SendClientMessage
}
return 1;
}
{} can be avoided if you have only one line after the condition. You can return SendClientMessage because SendClientMessage return 1 if the player is connected and when you type a command, you are connected to the server so it will return 1.