SA-MP Forums Archive
[Tutorial] Kick players automatically, if they have "admin" in their name. - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Kick players automatically, if they have "admin" in their name. (/showthread.php?tid=543105)



Kick players automatically, if they have "admin" in their name. - Pawnify - 24.10.2014

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.


Re: Kick players automatically, if they have "admin" in their name. - Glossy42O - 25.10.2014

Nice but has bugs.


Re: Kick players automatically, if they have "admin" in their name. - Pawnify - 25.10.2014

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


Re: Kick players automatically, if they have "admin" in their name. - Glossy42O - 25.10.2014

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


Re: Kick players automatically, if they have "admin" in their name. - Pawnify - 25.10.2014

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.


Re: Kick players automatically, if they have "admin" in their name. - Glossy42O - 25.10.2014

Sure, go for it.


Re: Kick players automatically, if they have "admin" in their name. - Alex Magaсa - 25.10.2014

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.


Re: Kick players automatically, if they have "admin" in their name. - Glossy42O - 25.10.2014

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


Re: Kick players automatically, if they have "admin" in their name. - Pawnify - 25.10.2014

Works perfectly for me. I even tried your name.


Re: Kick players automatically, if they have "admin" in their name. - Pawnify - 25.10.2014

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.