Ban/kick problems
#1

Hello, when i try to ban/kick someoane is showing me "/Ban or /kick : you are not an admin".
Here is my command:
Code:
CMD:ban(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to log in first.");
	if(IsPlayerConnected(playerid))
	{
		if (PlayerInfo[playerid][pAdmin] >= 1)
		{
			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]");
			mysql_real_escape_string(reason, reasone);
			if(IsPlayerConnected(id))
			{
			    if(id != INVALID_PLAYER_ID)
			    {
			        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;
    				}
					if(days == 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);
					}
					if(days > 0)
					{
						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);
					}
				}
			}
			else return SendClientMessage(playerid, COLOR_GREY, "Player not connected.");
		}
		else return SendClientMessage(playerid, COLOR_LIGHTGREEN3, AdminOnly);
	}
	return 1;
Please help me .
I want to said that the problem is on all gamemodes then i used on all probality is one script or someting wrong!
Sorry for my englich but i need help!
Reply
#2

I don't understand why people have to complicate their life by adding such useless and repeated checks.

pawn Code:
if(gPlayerLogged[playerid] == 0)
You're already checking if the player is connected in order to execute the command, what's the point of this?

pawn Code:
if(IsPlayerConnected(playerid))
More than 100 lines for a simple ban command, that's a record!

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;
}
Just made it in 5 minutes because i have to go, there can be errors.
Reply
#3

You need elementary knowledge on the scripting language. Judging from the code above, the problem would simply be that you are not assigning variables right.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)