03.04.2019, 12:48
I don't understand why people have to complicate their life by adding such useless and repeated checks.
You're already checking if the player is connected in order to execute the command, what's the point of this?
More than 100 lines for a simple ban command, that's a record!
Just made it in 5 minutes because i have to go, there can be errors.
pawn Code:
if(gPlayerLogged[playerid] == 0)
pawn Code:
if(IsPlayerConnected(playerid))
pawn Code:
CMD:ban(playerid, params[])
{
if(!gPlayerLogged[playerid]) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to log in first.");
if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_LIGHTGREEN3, AdminOnly);
new id,reason[128],reasone[128],string[200],giveplayer[30],sendername[30],days,str[1400],playerip[16],year,month,day,hour,minute,second,time;
if(sscanf(params, "uds[128]", id,days,reason)) return SCM(playerid, COLOR_GREY, "Syntax:{FFFFFF} /ban [name/playerid] [days/0=permanent] [reason]");
if(days < 0) return SCM(playerid, COLOR_GREY, "Syntax:{FFFFFF} /ban [name/playerid] [days/0=permanent] [reason]");
if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID)) return SendClientMessage(playerid, -1, "player is not connected or is invalid.");
mysql_real_escape_string(reason, reasone);
getdate(year, month, day), gettime(hour, minute, second);
GetPlayerName(id, giveplayer, sizeof(giveplayer)), GetPlayerName(playerid, sendername, sizeof(sendername)), GetPlayerIp(id, playerip, sizeof(playerip));
if(PlayerInfo[id][pAdmin] >= PlayerInfo[playerid][pAdmin])
{
new gString1[256];
format(gString1, sizeof(gString1), "{f03337}AdmWarning:{FFFFFF} %s a incercat sa-l baneze pe %s, motiv: %s", PlayerInfo[playerid][pNormalName], PlayerInfo[id][pNormalName], reason );
ABroadCast(-1, gString1, 1);
return 1;
}
switch(days)
{
case 0:
{
format(string,sizeof(string),"Ban: %s has been permanent banned by %s, reason: %s.",giveplayer,sendername,reasone);
if(strfind(reason, "silent", true) != -1)
{
ABroadCast(COLOR_LIGHTRED, "Silent ban:", 1);
ABroadCast(COLOR_LIGHTRED, string, 1);
}
else SendClientMessageToAll(COLOR_LIGHTRED, string);
if(gPlayerLogged[id] == 0)
{
mysql_format(SQL,str,sizeof(str),"INSERT INTO bans (PlayerName, AdminName, Reason, IP, Days, IPBan, Permanent, Active, Time) VALUES('%s', '%s', '%s', '%s', 0, 0, 1, 1, 0)",
giveplayer,PlayerInfo[playerid][pNormalName],reasone,playerip);
}
else
{
mysql_format(SQL,str,sizeof(str),"INSERT INTO bans (PlayerName, AdminName, Reason, IP, Days, IPBan, Permanent, Active, Time) VALUES('%s', '%s', '%s', '%s', 0, 0, 1, 1, 0)",
PlayerInfo[id][pNormalName],PlayerInfo[playerid][pNormalName],reasone,playerip);
}
mysql_tquery(SQL,str,"","");
new var100[256];
mysql_format(SQL, var100, sizeof(var100), "INSERT INTO punishlogs (`playerid`,`giverid`,`actionid`,`actiontime`,`reason`,`playername`,`givername`,`unixtime`) VALUES ('%d','%d','1','0','%s','%s','%s','%d')", PlayerInfo[id][pSQLID],PlayerInfo[playerid][pSQLID],reasone,giveplayer,sendername,gettime());
mysql_tquery(SQL,var100,"","");
KickEx(id);
}
default:
{
time = gettime() + (days*86400);
format(string,sizeof(string),"Ban: %s has been banned by %s for %d days, reason: %s.",giveplayer,sendername,days,reasone);
if(strfind(reason, "silent", true) != -1) ABroadCast(COLOR_LIGHTRED, string, 1);
else SendClientMessageToAll(COLOR_LIGHTRED, string);
if(gPlayerLogged[id] == 0)
{
mysql_format(SQL,str,sizeof(str),"INSERT INTO bans (PlayerName, AdminName, Reason, IP, Days, IPBan, Permanent, Active, Time) VALUES('%s', '%s', '%s', '%s', %d, 0, 0, 1, %d)",
giveplayer,PlayerInfo[playerid][pNormalName],reasone,playerip,days,time);
}
else
{
mysql_format(SQL,str,sizeof(str),"INSERT INTO bans (PlayerName, AdminName, Reason, IP, Days, IPBan, Permanent, Active, Time) VALUES('%s', '%s', '%s', '%s', %d, 0, 0, 1, %d)",
PlayerInfo[id][pNormalName],PlayerInfo[playerid][pNormalName],reasone,playerip,days,time);
}
mysql_tquery(SQL,str,"","");
new var100[256];
mysql_format(SQL, var100, sizeof(var100), "INSERT INTO punishlogs (`playerid`,`giverid`,`actionid`,`actiontime`,`reason`,`playername`,`givername`,`unixtime`) VALUES ('%d','%d','2','%d','%s','%s','%s','%d')", PlayerInfo[id][pSQLID],PlayerInfo[playerid][pSQLID],days,reasone,giveplayer,sendername,gettime());
mysql_tquery(SQL,var100,"","");
KickEx(id);
}
}
return 1;
}