SA-MP Forums Archive
Kick message - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Kick message (/showthread.php?tid=517351)



Kick message - Tuntun - 04.06.2014

Код:
// Kicks a player with a reason
CMD:kick(playerid, params[])
{
	new PlayerToKick, Reason[128], ReasonMsg[128], Name[24];

	// Check if the player has logged in
	if (PInfo[playerid][LoggedIn] == true)
	{
		// Check if the player's admin-level is at least 1
		if (PInfo[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));
					format(ReasonMsg, 128, "{FFFFFF}You have been kicked by {FFCC00} %s{FF0000} %s", AdminLevelName[PInfo[playerid][PlayerLevel]], Name);
					SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
					format(ReasonMsg, 128, "{FF0000}Reason:{FFFFFF} %s", Reason);
					SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
					SetTimerEx("KickPlayer", 500, 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;
}
Why no one can see the kick message and the reason? can someone edit it?


Re: Kick message - rickisme - 04.06.2014

Quote:

// In order to display a message (eg. reason) for the player before the connection is closed
// you have to use a timer to create a delay. This delay needs only to be a few milliseconds long,
// but this example uses a full second just to be on the safe side.

forward DelayedKick(playerid);
public DelayedKick(playerid)
{
Kick(playerid);
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/kickme", true) == 0)
{
// Kick the player who executed this command.

// First, send them a message.
SendClientMessage(playerid, 0xFF0000FF, "You have been kicked!");

// Actually kick them a second later on a timer.
SetTimerEx("DelayedKick", 1000, false, "d", playerid);
return 1;
}
return 0;
}

https://sampwiki.blast.hk/wiki/Kick


Re: Kick message - Stanford - 04.06.2014

Use KickWithMessage which simply works using a timer, it's a 0.3x++ bug, there's an example on sa-mp wiki.
send the message and then set a timer of 1000 seconds at least for the kick.


Re: Kick message - Tuntun - 04.06.2014

It will be more easy if you edit the lines.


Re: Kick message - iOxide - 04.06.2014

pawn Код:
// Kicks a player with a reason
CMD:kick(playerid, params[])
{
    new PlayerToKick, OtherName[24], Reason[128], ReasonMsg[128], Name[24];

    // Check if the player has logged in
    if (PInfo[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 1
        if (PInfo[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));
                    GetPlayerName(PlayerToKick, OtherName, sizeof(OtherName));
                    format(ReasonMsg, 128, "{FFFFFF}You have been kicked by {FFCC00} %s{FF0000} %s", AdminLevelName[PInfo[playerid][PlayerLevel]], Name);
                    SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
                    format(ReasonMsg, 128, "{FF0000}Reason:{FFFFFF} %s", Reason);
                    SendClientMessage(PlayerToKick, 0xFF0000FF, ReasonMsg);
                    format(ReasonMsg, 128, "%s has been kicked by admin %s! Reason: %s", OtherName, Name, Reason);
                    SendClientMessageToAll(0xFF0000FF, ReasonMsg);
                    SetTimerEx("KickPlayer", 1000, false, "i", 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;
}

forward KickPlayer(playerid);
public KickPlayer(playerid)
{
    Kick(playerid);
    return 1;
}
Your SetTimerEx syntax is wrong, you set playerid on it which returns the cmd user not the target + you need to create the public function which kicks the player.


Re: Kick message - Tuntun - 04.06.2014

Okey... you will get +rep if you fix it too.. after ban someone it should show all the message... %s has been banned by admin %s days: reason:
Код:
// Bans a player for (days, hours, minutes, seconds)
CMD: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 (PInfo[playerid][LoggedIn] == true)
	{
		// Check if the player's admin-level is at least 3
		if (PInfo[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
					PInfo[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 (PInfo[PlayerToBan][Bans] == 5)
						PInfo[PlayerToBan][BanTime] = 2147483640; // Make the ban permanent (as high as it can go)
					else
						PInfo[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 (PInfo[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", PInfo[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[PInfo[playerid][PlayerLevel]], AdminName, Name, Days, Hours);
					SendClientMessageToAll(0x808080FF, Msg);
				}
			}
		}
		else
		    return 0;
	}
	else
	    return 0;

	return 1;
}



Re: Kick message - iOxide - 04.06.2014

Dude, you can just make it in the same way as the kick cmd above. Its not that hard, you will just need to format the string and SendClientMessageToAll.