Kick Command
#1

Here is my /kick command.

Код:
//---------------------------------------------[Kick]-----------------------------------------------------
    if(strcmp(cmd, "/kick", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	    	tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /kick [playerid/PartOfName] <reason>");
				return 1;
			}
			giveplayerid = ReturnUser(tmp);
			if(giveplayerid != playerid && Untouchable[giveplayerid]) return SendClientMessage(playerid, COLOR_GREY, "* You Can't Do this on This player!");
      		new targetlevel = PlayerInfo[giveplayerid][pAdmin];
			new playerlevel = PlayerInfo[playerid][pAdmin];
			if(targetlevel > playerlevel) return SendClientMessage(playerid, COLOR_GREY, "* You can not Kick People that is higher Than You!");
			if (PlayerInfo[playerid][pAdmin] >= 1 || IsPlayerAdmin(playerid))
			{
				if(IsPlayerConnected(giveplayerid))
				{
				    if(giveplayerid != INVALID_PLAYER_ID)
				    {
					    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
						new length = strlen(cmdtext);
						while ((idx < length) && (cmdtext[idx] <= ' '))
						{
							idx++;
						}
						new offset = idx;
						new result[128];
						while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
						{
							result[idx - offset] = cmdtext[idx];
							idx++;
						}
						result[idx - offset] = EOS;
						if(!strlen(result))
						{
							new y, m, d;
							new h,mi,s;
							getdate(y,m,d);
							gettime(h,mi,s);
							format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has been kicked by %s, No Reason Given",d,m,y,h,mi,s,giveplayer,sendername);
							KickLog(string);
							format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] Kicked by %s - No Reason Given.",d,m,y,h,mi,s,sendername);
							AddPunishment(giveplayerid, string);
							format(string, sizeof(string), "%s (%d), Has been kicked by Administrator %s, No Reason Given", giveplayer, giveplayerid, sendername);
							SendClientMessageToAll(COLOR_NICERED, string);
							format(string, sizeof(string), "You have Been Kicked by Administrator %s, No Reason Given", sendername);
							SendClientMessage(giveplayerid,COLOR_LIGHTBLUE, string);
	 						SafeSetPlayerPos(giveplayerid,264.6288,77.5742,1001.0391);
			                SafeSetPlayerInterior(giveplayerid, 6);
							GameTextForPlayer(giveplayerid, "~r~~h~Admin Kicked: ~n~~r~No Reason Given", 6000, 3);
							//SetTimerEx("KickPlayer", 1000, false, "i", playerid);
							Kick(giveplayerid);
							return 1;
						}
						new y, m, d;
						new h,mi,s;
						getdate(y,m,d);
						gettime(h,mi,s);
						format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has been kicked by %s for: %s",d,m,y,h,mi,s,giveplayer,sendername, (result));
						KickLog(string);
						format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] Kicked by %s - Reason: %s",d,m,y,h,mi,s,sendername,(result));
						AddPunishment(giveplayerid, string);
						format(string, sizeof(string), "%s (%d), Has been kicked by Administrator %s for: %s", giveplayer, giveplayerid, sendername, (result));
						SendClientMessageToAll(COLOR_NICERED, string);
						format(string, sizeof(string), "You have Been Kicked by Administrator %s for: %s", sendername, (result));
						SendClientMessage(giveplayerid,COLOR_LIGHTBLUE, string);
 						SafeSetPlayerPos(giveplayerid,264.6288,77.5742,1001.0391);
		                SafeSetPlayerInterior(giveplayerid, 6);
 						format(string, sizeof(string), "~r~~h~Admin Kicked: ~n~~r~%s",(result));
						GameTextForPlayer(giveplayerid, string, 6000, 3);
						//SetTimerEx("KickPlayer", 1000, false, "i", playerid);
						Kick(giveplayerid);
						return 1;
					}
				}
			}
			else
			{
				format(string, sizeof(string), "** %d is not an active player.", giveplayerid);
				SendClientMessage(playerid, COLOR_GRAD1, string);
			}
		}
		return 1;
	}
So..
When I kick someone I want him to get the reason why he is kicked.
How to do it?
Reply
#2

Set a timer dear! :P

I recommend:
- Use anything faster than normal string compere, for your own sake and for the users experiences as well!
- You can use any timer but a normal SetTimerEx would do, no need for an "accurate" timer when doing this.

What you want to do:
- Make the player get the message.
- Let them wait like 2 seconds or 1 second (this is where the timer comes in).
- Kick them once the timer is over.

Example of a timer that would do this:
SetTimerEx("kickFunc", 2000, false, "i", giveplayerid);

OR! If you want to use _Emmets newest and hotest invention of timers that would solve your problem check it out here: http://forum.sa-mp.com/showthread.ph...ighlight=emmet (recommended!)

And yes I won't post the actual code because I believe that is your job!
Reply
#3

Can you make the command for me please?
Reply
#4

Lol you even already have a timer in your command, just higher its seconds and it should work. ^^
Reply
#5

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Lol you even already have a timer in your command, just higher its seconds and it should work. ^^
No need to higher it, just uncomment it.

Change all
pawn Код:
//SetTimerEx("KickPlayer", 1000, false, "i", playerid);
Into
pawn Код:
SetTimerEx("KickPlayer", 1000, false, "i", playerid);
Reply
#6

Hint: Don't copy Godfather, you'll thank me later.
Reply
#7

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
No need to higher it, just uncomment it.

Change all
pawn Код:
//SetTimerEx("KickPlayer", 1000, false, "i", playerid);
Into
pawn Код:
SetTimerEx("KickPlayer", 1000, false, "i", playerid);
I've tried like you said and it simple close the connection to the server.
Reply
#8

You wrote the wrong player ID in the SetTimerEx function; it should be:
pawn Код:
SetTimerEx("KickPlayer", 1000, false, "i", giveplayerid);
Then remove this line:
pawn Код:
Kick(giveplayerid);
The reason for this is because this would cause the player to get kicked before getting the message.
Reply
#9

Quote:
Originally Posted by JJB562
Посмотреть сообщение
You wrote the wrong player ID in the SetTimerEx function; it should be:
pawn Код:
SetTimerEx("KickPlayer", 1000, false, "i", giveplayerid);
Then remove this line:
pawn Код:
Kick(giveplayerid);
The reason for this is because this would cause the player to get kicked before getting the message.
If I do like this it only gives me the reason but dosen't close the server connection.
Reply
#10

Quote:
Originally Posted by Bost
Посмотреть сообщение
If I do like this it only gives me the reason but dosen't close the server connection.
pawn Код:
forward KickTimer(playerid); //local(Before any callback)
pawn Код:
public KickTimer(playerid)
{
    Kick(playerid);
    return 1;
}
pawn Код:
//At the kick command:
SetTimerEx("KickTimer", 1000, false, "i", id); //the id(targetid) will be kicked after 1 second
Try the kick command now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)