Allow Certain Names
#1

Mmm, I forgot how to only allow players with certain tags.
Like if they don't have the [ABC] or [123] tag then they get kicked.. Any help??
Reply
#2

pawn Код:
public OnPlayerConnect(playerid)
{        
    if(!strcmp(Name,"[ABC]", true) == 0)
    {
           // Code here
               SendClientMessage(playerid,COLOR_BRIGHTRED,"You Must Have A Tag Contained At The Beginning Of Your Name. Please Change It Blabla. You Will Be Kicked.");
           return Kick(playerid);
    }
}
I guess you could give that a try, it's something similar to what you need but you need to edit it a bit more.
Reply
#3

The above method will only check if the whole name is equal to the tag name. I'm assuming you want it to only kick the player if the tag is not in the name at all? Here is an example of how you could accomplish this:
pawn Код:
public OnPlayerConnect( playerid ) {

   new name[ MAX_PLAYER_NAME ]; // Create a new variable to store the player's name
   GetPlayerName( playerid, name, MAX_PLAYER_NAME ); // Store the player's name

   // Check if their name has the [ABC] or [123] tag
   // strfind usage - https://sampwiki.blast.hk/wiki/Strfind
   if( strfind( name, "[ABC]", true ) == -1 && strfind( name, "[123]", true ) == -1 ) {
   
      // Tell the player what's happening, and kick them
      SendClientMessage( playerid, 0xFF00FFFF, "Your name must contain the [ABC] or [123] tag to play." );
      Kick( playerid );
   }
   return 1;
}
If there is a part of the code you don't understand or need more explanation of, please ask! It's better to understand the code itself instead of simply getting someone else to hand it to you every time. That way, you'll be able to replicate it in the future, if needed.
Reply
#4

Quote:
Originally Posted by Bakr
Посмотреть сообщение
The above method will only check if the whole name is equal to the tag name. I'm assuming you want it to only kick the player if the tag is not in the name at all? Here is an example of how you could accomplish this:
pawn Код:
public OnPlayerConnect( playerid ) {

   new name[ MAX_PLAYER_NAME ]; // Create a new variable to store the player's name
   GetPlayerName( playerid, name, MAX_PLAYER_NAME ); // Store the player's name

   // Check if their name has the [ABC] or [123] tag
   // strfind usage - https://sampwiki.blast.hk/wiki/Strfind
   if( strfind( name, "[ABC]", true ) == -1 && strfind( name, "[123]", true ) == -1 ) {
   
      // Tell the player what's happening, and kick them
      SendClientMessage( playerid, 0xFF00FFFF, "Your name must contain the [ABC] or [123] tag to play." );
      Kick( playerid );
   }
   return 1;
}
If there is a part of the code you don't understand or need more explanation of, please ask! It's better to understand the code itself instead of simply getting someone else to hand it to you every time. That way, you'll be able to replicate it in the future, if needed.
Ok thanks I understand what you did. I just needed a little remembering on how to script. Thanks alot dude!

what if i had a
pawn Код:
#define CLAN_TAG [ABC]
Thanks all i needed was some remembering
Reply
#5

You would need to make the definition a string, and use it like a variable (how I consider it) in the strfind( ) function:
pawn Код:
#define CLAN_TAG "[ABC]"
#define CLAN_TAG_2 "[123]"

if( strfind( name, CLAN_TAG, true ) == -1 && strfind( name, CLAN_TAG_2, true ) == -1 )
Reply
#6

Quote:
Originally Posted by Bakr
Посмотреть сообщение
You would need to make the definition a string, and use it like a variable (how I consider it) in the strfind( ) function:
pawn Код:
#define CLAN_TAG "[ABC]"
#define CLAN_TAG_2 "[123]"

if( strfind( name, CLAN_TAG, true ) == -1 && strfind( name, CLAN_TAG_2, true ) == -1 )
Oh yeah, thanks, I solved that like right after I asked and then edited my post so no one would post below but I guess you saw before I edited xd
Reply
#7

Why is there a && in the statement? That would only work if the player had his name like

[ABC]Lorenc[123]

pawn Код:
if( strfind( name, CLAN_TAG, true ) == -1 || strfind( name, CLAN_TAG_2, true ) == -1 )
Might wanna replace && with ||

I think || means 'or' in coding.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)