24.10.2014, 17:52
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.
[*]Then we need to make the KickPlayer function
[*]Finished Result
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.
[*]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; }
Код:
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; }