OnPlayerConnect
#1

Whats wrong with this? I put this under OnPlayerConnect and its pretty easy to guess what it does, if that player has a certain name it kicks them


Код:
if(strcmp(params, "test", true) == 0 );
		{
			Kick(playerid);

		}
Reply
#2

Can we please see where you fetch the name and put it into the params array?
Reply
#3

You mean this?

Код:
	if(fexist(file)) {
	    ShowLogin(playerid);
	}else {
	    ShowRegister(playerid);
		new params;
		if(strcmp(params, "test", true) == 0 );
		{
			Kick(playerid);

		}
	}
Reply
#4

Quote:
Originally Posted by Socan
Посмотреть сообщение
You mean this?

Код:
	if(fexist(file)) {
	    ShowLogin(playerid);
	}else {
	    ShowRegister(playerid);
		new params;
		if(strcmp(params, "test", true) == 0 );
		{
			Kick(playerid);

		}
	}
There is your issue. You're never fetching the players name. You're comparing "test" which is an array:

pawn Код:
array[0] = 't';
array[1] = 'e';
array[2] = 's';
array[3] = 't';
to a number: params ( aka a single value - not an array or string for that matter )


What you should have done is fetch the name using https://sampwiki.blast.hk/wiki/GetPlayerName

Then what you do is compare the name(which in turn is a string - or an array for pawn's scenario) with the strcmp function.
Reply
#5

Too much information for my brain :/ haha. May you please just edit the second piece of code I sent so that it works?
Reply
#6

Right, sorry.

I have a tendency of making things a lot more complicated than they have to be.

So, what you need to do is something along these lines:

pawn Код:
new name[MAX_PLAYER_NAME]; // create a variable thats big enough to hold the players name
GetPlayerName(playerid, name, sizeof(name)); // Fetch the name of the player and put it into the variable
if(strcmp(name, "test", true) == 0) // compare if the variable matches "test".
Reply
#7

Cool thanks, but is there a way to seach for that name? So I do get kicked if I join with 'test' but if I join with 'tester' or 'testing' it wont kick me, only when I join with the name 'test'
Reply
#8

anyone?
Reply
#9

Just use the last parameter of strcmp:

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

e.g.

pawn Код:
strcmp(string1, "Hello", true, 5)
Reply
#10

Please note that Kicking in OnPlayerConnect can have some unexpected side effects (player not seeing the kick message and is just constantly reconnecting)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)