OnPlayerConnect - 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)
+--- Thread: OnPlayerConnect (
/showthread.php?tid=381890)
OnPlayerConnect -
Socan - 01.10.2012
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);
}
Re: OnPlayerConnect -
Extremo - 01.10.2012
Can we please see where you fetch the name and put it into the params array?
Re: OnPlayerConnect -
Socan - 01.10.2012
You mean this?
Код:
if(fexist(file)) {
ShowLogin(playerid);
}else {
ShowRegister(playerid);
new params;
if(strcmp(params, "test", true) == 0 );
{
Kick(playerid);
}
}
Re: OnPlayerConnect -
Extremo - 01.10.2012
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.
Re: OnPlayerConnect -
Socan - 01.10.2012
Too much information for my brain :/ haha. May you please just edit the second piece of code I sent so that it works?
Re: OnPlayerConnect -
Extremo - 01.10.2012
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".
Re: OnPlayerConnect -
Socan - 01.10.2012
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'
Re: OnPlayerConnect -
Socan - 01.10.2012
anyone?
Re: OnPlayerConnect -
Extremo - 01.10.2012
Just use the last parameter of strcmp:
https://sampwiki.blast.hk/wiki/Strcmp
e.g.
pawn Код:
strcmp(string1, "Hello", true, 5)
Re: OnPlayerConnect -
mamorunl - 01.10.2012
Please note that Kicking in OnPlayerConnect can have some unexpected side effects (player not seeing the kick message and is just constantly reconnecting)