[Tutorial] Kick players automatically, if they have "admin" in their name.
#1

Hey guys, this is my first tutorial. Ever wondered how to kick players automatically from your server if they have Admin in their name? Well this tutorial can help.


[*]Firstly, we need to put this under the OnPlayerConnect function.
Код:
public OnPlayerConnect(playerid)
{
	new pname[MAX_PLAYER_NAME],string[125]; // These are our variables pname stores the players name for later use, and string is used later too.
	GetPlayerName(playerid,pname,sizeof(pname)); // This reads what player is connecting and saves it to the variable pname that we made.
	if(strfind(pname, "admin", true) != -1) // We use strfind, to check if a certain variable contains something. In this case, we are checking if the players name contains "admin"
	{
	    format(string, sizeof(string), "{FF0000}Hello %s, your name contains the word 'Admin' please change it.",pname);// We use format here, so we can send the player a message with his/her name inside of it.
	    SendClientMessage(playerid, -1, string);// This uses the format what we did above, it basically sends whatever is inside of the format above.
	SetTimerEx("KickPlayer", 100, false, "i", playerid);// We use a timer here, as if we didn't the player would not see the message before he was kicked.
	}
	return 1;
}
[*]Then we need to make the KickPlayer function
Код:
forward KickPlayer(playerid);
public KickPlayer(playerid)// This function will be called when the timer goes down, whatever is inside here will be run.
{
	Kick(playerid);// Finally, this kicks the player from the server.
	return 1;
}

[*]Finished Result
Код:
forward KickPlayer(playerid);
public KickPlayer(playerid)
{
	Kick(playerid);
	return 1;
}

public OnPlayerConnect(playerid)
{
	new pname[MAX_PLAYER_NAME],string[125]; GetPlayerName(playerid,pname,sizeof(pname));
	if(strfind(pname, "admin", true) != -1)
	{
	    format(string, sizeof(string), "{FF0000}Hello %s, your name contains the word 'Admin' please change it.",pname);
	    SendClientMessage(playerid, -1, string);
		SetTimerEx("KickPlayer", 100, false, "i", playerid);
	}
	return 1;
}
Note: I was going to just release this as a filter script.. but it looked kinda too small to be one. So I thought I'd release a small tutorial instead.
Reply
#2

Nice but has bugs.
Reply
#3

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Nice but has bugs.
Which bugs.
Reply
#4

Well. I connected with Admin and it worked then i connected with my name "[Cali]Stuun"

It said hello cali stuun your name contains admin bla bla.. like i still have admin
Reply
#5

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Well. I connected with Admin and it worked then i connected with my name "[Cali]Stuun"

It said hello cali stuun your name contains admin bla bla.. like i still have admin
Really? Let me test it again.
Reply
#6

Sure, go for it.
Reply
#7

Seems you didn't test this but you copied from other gamemode/filterscript.
OT: It would be great if you put screenshot e.t.c so you can show players that this work perfect.
Reply
#8

It is great i liked it very much but i'd like it more if it was dialog :P
Reply
#9

Works perfectly for me. I even tried your name.
Reply
#10

Quote:
Originally Posted by Alex Magaсa
Посмотреть сообщение
Seems you didn't test this but you copied from other gamemode/filterscript.
OT: It would be great if you put screenshot e.t.c so you can show players that this work perfect.
I didn't copy this from another gamemode man. It's not that hard to make. I did test it, once.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)