SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 01/02/2014, 12:07 PM   #1
thegamer355
Big Clucker
 
Join Date: May 2013
Location: In my house
Posts: 142
Reputation: 5
Default Kick/ban problem

hi all,
i have a little problem with my kick/ban command
it doesn't show the reason.
NOTE: the code is used in an include

/kick:
Code:
COMMAND:kick(playerid, params[])
{
	new PlayerToKick, Reason[128], ReasonMsg[128], Name[24];

	// Send the command to all admins so they can see it
	SendAdminText(playerid, "/kick", params);

	// Check if the player has logged in
	if (APlayerData[playerid][LoggedIn] == true)
	{
		// Check if the player's admin-level is at least 1
		if (APlayerData[playerid][PlayerLevel] >= 1)
		{
			if (sscanf(params, "us[128]", PlayerToKick, Reason)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/kick <PlayerToKick> <Reason>\"");
			else
				if (IsPlayerConnected(PlayerToKick)) // If the player is a valid playerid (he's connected)
				{
					// Get the name of the player who warned the player
					GetPlayerName(playerid, Name, sizeof(Name));
					// Send the warned player a message who kicked him and why he's been kicked
					format(ReasonMsg, 128, "You have been kicked by %s %s", AdminLevelName[APlayerData[playerid][PlayerLevel]], Name);
					SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
					format(ReasonMsg, 128, "Reason: %s", Reason);
					SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
					SetTimerEx("kick",1000,false,"i",playerid);
					// Kick the player
					Kick(PlayerToKick);
				}
				else
				    SendClientMessage(playerid, 0xFF0000FF, "That player isn't online");
		}
		else
		    return 0;
	}
	else
	    return 0;

	// Let the server know that this was a valid command
	return 1;
}
/ban:
Code:
COMMAND:ban(playerid, params[])
{
	// Setup local variables
	new PlayerToBan, Days, Hours, Reason[128], TotalBanTime, Msg[128], Name[24], AdminName[24];

	// Send the command to all admins so they can see it
	SendAdminText(playerid, "/ban", params);

	// Check if the player has logged in
	if (APlayerData[playerid][LoggedIn] == true)
	{
		// Check if the player's admin-level is at least 3
		if (APlayerData[playerid][PlayerLevel] >= 3)
		{
			if (sscanf(params, "uiis[128]", PlayerToBan, Days, Hours, Reason))
				SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/ban <PlayerToBan> <Days> <Hours> <Reason>\"");
			else
			{
				if (IsPlayerConnected(PlayerToBan))
				{
					// Get the names of the player and the admin who executed the ban
					GetPlayerName(playerid, AdminName, sizeof(AdminName));
					GetPlayerName(PlayerToBan, Name, sizeof(Name));

					// Increase the number of bans
					APlayerData[PlayerToBan][Bans]++;
					// Calculate the total bantime (when the player can login again)
					TotalBanTime = (Days * 86400) + (Hours * 3600) + gettime();
					// Check if this is the player's 5th ban
					if (APlayerData[PlayerToBan][Bans] == 5)
						APlayerData[PlayerToBan][BanTime] = 2147483640; // Make the ban permanent (as high as it can go)
					else
						APlayerData[PlayerToBan][BanTime] = TotalBanTime; // Store this value for the player

					// Inform the player about his ban
					// Check if this is the player's 5th ban
					if (APlayerData[PlayerToBan][Bans] == 5)
					{
						format(Msg, 128, "You have been banned permanently by %s, this was your 5th ban", AdminName);
						SendClientMessage(PlayerToBan, 0x808080FF, Msg);
					}
					else
					{
						format(Msg, 128, "You have been banned by %s for %i days and %i hours", AdminName, Days, Hours);
						SendClientMessage(PlayerToBan, 0x808080FF, Msg);
						format(Msg, 128, "Reason: %s", Reason);
						SendClientMessage(PlayerToBan, 0x808080FF, Msg);
						format(Msg, 128, "You've been banned %i times now, 5th time is permament", APlayerData[PlayerToBan][Bans]);
						SendClientMessage(PlayerToBan, 0x808080FF, Msg);
					}

					// Kick the player (his data will be saved)
					Kick(PlayerToBan);

					// Inform everybody else which player was banned and for how long
					format(Msg, 128, "%s %s has banned %s for %i days and %i hours", AdminLevelName[APlayerData[playerid][PlayerLevel]], AdminName, Name, Days, Hours);
					SendClientMessageToAll(0x808080FF, Msg);
				}
			}
		}
		else
		    return 0;
	}
	else
	    return 0;

	return 1;
}
__________________

+REP me if i helped you
Quote:
This forum requires that you wait 120 seconds between posts. Please try again in 0 seconds.

(click the image to join)

Last edited by thegamer355; 01/02/2014 at 01:01 PM.
thegamer355 is offline   Reply With Quote
Old 01/02/2014, 12:17 PM   #2
CuervO
High-roller
 
CuervO's Avatar
 
Join Date: Oct 2008
Posts: 1,164
Reputation: 200
Default Re: Kick/ban problem

Are you using sscanf2 plugin?

Also something little I noticed, the reason is a 128 long cell, while the ReasonMsg/Msg is also a 128 long cell. You're already using 8 cells at ReasonMsg/Msg, that means the reason will only display 120 characters.
__________________
[IMG]http://************/pdpu4qe[/IMG]    - Team Fortress 2 [Gamemode] [SQL] [Whirlpool] [Streamer] [Sscanf] [ZCMD]
[IMG]http://************/pdpu4qe[/IMG] - Live map object editor [Filterscript] [DINI] [Streamer] [Sscanf] [ZCMD]
[img]http://************/pdpu4qe[/img] [img]http://************/nfxrrrz[/img] - Inventory & Object System [Filterscript] [SQL] [Streamer] [Sscanf] [ZCMD]

- RenderMessage(toAll) [Snippet]
CuervO is offline   Reply With Quote
Old 01/02/2014, 12:21 PM   #3
Nourdin
Big Clucker
 
Nourdin's Avatar
 
Join Date: Nov 2013
Posts: 130
Reputation: 15
Default Re: Kick/ban problem

Kick

pawn Code:
COMMAND:kick(playerid, params[])
{
    new PlayerToKick, Reason[128], ReasonMsg[128], Name[24];
   
    // Send the command to all admins so they can see it
    SendAdminText(playerid, "/kick", params);
   
    // Check if the player has logged in
    if (APlayerData[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 1
        if (APlayerData[playerid][PlayerLevel] >= 1)
        {
            if (sscanf(params, "us[128]", PlayerToKick, Reason)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick <playerid> <reason>");
            else
                if (IsPlayerConnected(PlayerToKick)) // If the player is a valid playerid (he's connected)
            {
                // Get the name of the player who warned the player
                GetPlayerName(playerid, Name, sizeof(Name));
                // Send the warned player a message who kicked him and why he's been kicked
                format(ReasonMsg, sizeof(ReasonMsg), "You have been kicked by %s %s", AdminLevelName[APlayerData[playerid][PlayerLevel]], Name);
                SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
                format(ReasonMsg, sizeof(ReasonMsg), "Reason: %s", Reason);
                SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
                SetTimerEx("kick",1000,false,"i",playerid);
                // Kick the player
                Kick(PlayerToKick);
            }
            else
                SendClientMessage(playerid, 0xFF0000FF, "That player isn't online");
        }
        else
            return 0;
    }
    else
        return 0;
   
    // Let the server know that this was a valid command
    return 1;
}


Ban
pawn Code:
COMMAND:ban(playerid, params[])
{
    // Setup local variables
    new PlayerToBan, Days, Hours, Reason[128], TotalBanTime, Msg[1024], Name[24], AdminName[24];
   
    // Send the command to all admins so they can see it
    SendAdminText(playerid, "/ban", params);
   
    // Check if the player has logged in
    if (APlayerData[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 3
        if (APlayerData[playerid][PlayerLevel] >= 3)
        {
            if (sscanf(params, "uiis[128]", PlayerToBan, Days, Hours, Reason))
            SendClientMessage(playerid, 0xFF0000AA, "Usage: /ban <PlayerToBan> <Days> <Hours> <Reason>");
            else
            {
                if (IsPlayerConnected(PlayerToBan))
                {
                    // Get the names of the player and the admin who executed the ban
                    GetPlayerName(playerid, AdminName, sizeof(AdminName));
                    GetPlayerName(PlayerToBan, Name, sizeof(Name));
                   
                    // Increase the number of bans
                    APlayerData[PlayerToBan][Bans]++;
                    // Calculate the total bantime (when the player can login again)
                    TotalBanTime = (Days * 86400) + (Hours * 3600) + gettime();
                    // Check if this is the player's 5th ban
                    if (APlayerData[PlayerToBan][Bans] == 5)
                    APlayerData[PlayerToBan][BanTime] = 2147483640; // Make the ban permanent (as high as it can go)
                    else
                        APlayerData[PlayerToBan][BanTime] = TotalBanTime; // Store this value for the player
                   
                    // Inform the player about his ban
                    // Check if this is the player's 5th ban
                    if (APlayerData[PlayerToBan][Bans] == 5)
                    {
                        format(Msg, 128, "You have been banned permanently by %s, this was your 5th ban", AdminName);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                    }
                    else
                    {
                        format(Msg, sizeof(Msg), "You have been banned by %s for %i days and %i hours", AdminName, Days, Hours);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                        format(Msg, sizeof(Msg), "Reason: %s", Reason);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                        format(Msg, sizeof(Msg), "You've been banned %i times now, 5th time is permament", APlayerData[PlayerToBan][Bans]);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                    }
                   
                    // Kick the player (his data will be saved)
                    Kick(PlayerToBan);
                   
                    // Inform everybody else which player was banned and for how long
                    format(Msg, 128, "%s %s has banned %s for %i days and %i hours", AdminLevelName[APlayerData[playerid][PlayerLevel]], AdminName, Name, Days, Hours);
                    SendClientMessageToAll(0x808080FF, Msg);
                }
            }
        }
        else
            return 0;
    }
    else
        return 0;
   
    return 1;
}
__________________
Nourdin is offline   Reply With Quote
Old 01/02/2014, 12:59 PM   #4
thegamer355
Big Clucker
 
Join Date: May 2013
Location: In my house
Posts: 142
Reputation: 5
Default Re: Kick/ban problem

Quote:
Originally Posted by NourdinTRP View Post
Kick

pawn Code:
COMMAND:kick(playerid, params[])
{
    new PlayerToKick, Reason[128], ReasonMsg[128], Name[24];
   
    // Send the command to all admins so they can see it
    SendAdminText(playerid, "/kick", params);
   
    // Check if the player has logged in
    if (APlayerData[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 1
        if (APlayerData[playerid][PlayerLevel] >= 1)
        {
            if (sscanf(params, "us[128]", PlayerToKick, Reason)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick <playerid> <reason>");
            else
                if (IsPlayerConnected(PlayerToKick)) // If the player is a valid playerid (he's connected)
            {
                // Get the name of the player who warned the player
                GetPlayerName(playerid, Name, sizeof(Name));
                // Send the warned player a message who kicked him and why he's been kicked
                format(ReasonMsg, sizeof(ReasonMsg), "You have been kicked by %s %s", AdminLevelName[APlayerData[playerid][PlayerLevel]], Name);
                SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
                format(ReasonMsg, sizeof(ReasonMsg), "Reason: %s", Reason);
                SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
                SetTimerEx("kick",1000,false,"i",playerid);
                // Kick the player
                Kick(PlayerToKick);
            }
            else
                SendClientMessage(playerid, 0xFF0000FF, "That player isn't online");
        }
        else
            return 0;
    }
    else
        return 0;
   
    // Let the server know that this was a valid command
    return 1;
}


Ban
pawn Code:
COMMAND:ban(playerid, params[])
{
    // Setup local variables
    new PlayerToBan, Days, Hours, Reason[128], TotalBanTime, Msg[1024], Name[24], AdminName[24];
   
    // Send the command to all admins so they can see it
    SendAdminText(playerid, "/ban", params);
   
    // Check if the player has logged in
    if (APlayerData[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 3
        if (APlayerData[playerid][PlayerLevel] >= 3)
        {
            if (sscanf(params, "uiis[128]", PlayerToBan, Days, Hours, Reason))
            SendClientMessage(playerid, 0xFF0000AA, "Usage: /ban <PlayerToBan> <Days> <Hours> <Reason>");
            else
            {
                if (IsPlayerConnected(PlayerToBan))
                {
                    // Get the names of the player and the admin who executed the ban
                    GetPlayerName(playerid, AdminName, sizeof(AdminName));
                    GetPlayerName(PlayerToBan, Name, sizeof(Name));
                   
                    // Increase the number of bans
                    APlayerData[PlayerToBan][Bans]++;
                    // Calculate the total bantime (when the player can login again)
                    TotalBanTime = (Days * 86400) + (Hours * 3600) + gettime();
                    // Check if this is the player's 5th ban
                    if (APlayerData[PlayerToBan][Bans] == 5)
                    APlayerData[PlayerToBan][BanTime] = 2147483640; // Make the ban permanent (as high as it can go)
                    else
                        APlayerData[PlayerToBan][BanTime] = TotalBanTime; // Store this value for the player
                   
                    // Inform the player about his ban
                    // Check if this is the player's 5th ban
                    if (APlayerData[PlayerToBan][Bans] == 5)
                    {
                        format(Msg, 128, "You have been banned permanently by %s, this was your 5th ban", AdminName);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                    }
                    else
                    {
                        format(Msg, sizeof(Msg), "You have been banned by %s for %i days and %i hours", AdminName, Days, Hours);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                        format(Msg, sizeof(Msg), "Reason: %s", Reason);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                        format(Msg, sizeof(Msg), "You've been banned %i times now, 5th time is permament", APlayerData[PlayerToBan][Bans]);
                        SendClientMessage(PlayerToBan, 0x808080FF, Msg);
                    }
                   
                    // Kick the player (his data will be saved)
                    Kick(PlayerToBan);
                   
                    // Inform everybody else which player was banned and for how long
                    format(Msg, 128, "%s %s has banned %s for %i days and %i hours", AdminLevelName[APlayerData[playerid][PlayerLevel]], AdminName, Name, Days, Hours);
                    SendClientMessageToAll(0x808080FF, Msg);
                }
            }
        }
        else
            return 0;
    }
    else
        return 0;
   
    return 1;
}
ehm what did you change?


EDIT: i noticed i wrote filterscript instead of include
__________________

+REP me if i helped you
Quote:
This forum requires that you wait 120 seconds between posts. Please try again in 0 seconds.

(click the image to join)
thegamer355 is offline   Reply With Quote
Old 01/02/2014, 01:06 PM   #5
Nourdin
Big Clucker
 
Nourdin's Avatar
 
Join Date: Nov 2013
Posts: 130
Reputation: 15
Default Re: Kick/ban problem

pawn Code:
format(Msg, sizeof(Msg), "Reason: %s", Reason);

And the command itself.
__________________
Nourdin is offline   Reply With Quote
Old 01/02/2014, 01:08 PM   #6
thegamer355
Big Clucker
 
Join Date: May 2013
Location: In my house
Posts: 142
Reputation: 5
Default Re: Kick/ban problem

well there are many threads about this problem
they all say to use a timer to show the message
but when i add the timer like in the kick command it's still not showing the reason
__________________

+REP me if i helped you
Quote:
This forum requires that you wait 120 seconds between posts. Please try again in 0 seconds.

(click the image to join)
thegamer355 is offline   Reply With Quote
Old 01/02/2014, 01:12 PM   #7
Nourdin
Big Clucker
 
Nourdin's Avatar
 
Join Date: Nov 2013
Posts: 130
Reputation: 15
Default Re: Kick/ban problem

Why do you add a timer for a kick/ban script? Just remove it as I guess it isn't really needed to wait untill they get the message.
__________________
Nourdin is offline   Reply With Quote
Old 01/02/2014, 01:14 PM   #8
thegamer355
Big Clucker
 
Join Date: May 2013
Location: In my house
Posts: 142
Reputation: 5
Default Re: Kick/ban problem

Quote:
Originally Posted by NourdinTRP View Post
Why do you add a timer for a kick/ban script? Just remove it as I guess it isn't really needed to wait untill they get the message.
they removed the time from the message till the kick in the 0.3X version
is instantly says: Server closed the connection.
so i need a delay to let it show the message and then kick the player
it is for my trucking server so i will be usefull to see why they are kicked/banned
__________________

+REP me if i helped you
Quote:
This forum requires that you wait 120 seconds between posts. Please try again in 0 seconds.

(click the image to join)
thegamer355 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
0.3x Kick() Problem Skimmer Scripting Help 8 04/02/2013 05:16 PM
/kick problem MrBorsh Scripting Help 3 14/09/2012 08:56 PM
kick problem.. vassilis Scripting Help 2 26/11/2011 05:43 PM
Kick Problem Abreezy Help Archive 7 22/08/2011 12:47 AM
Kick- / Ban-Problem DeathOnaStick Help Archive 6 05/12/2009 10:29 PM


All times are GMT. The time now is 02:38 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.