SA-MP Forums Archive
Allow Certain Names - 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: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Allow Certain Names (/showthread.php?tid=253543)



Allow Certain Names - ToPhrESH - 07.05.2011

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??


Re: Allow Certain Names - grand.Theft.Otto - 07.05.2011

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.


Re: Allow Certain Names - Bakr - 07.05.2011

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.


Re: Allow Certain Names - ToPhrESH - 07.05.2011

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


Re: Allow Certain Names - Bakr - 07.05.2011

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 )



Re: Allow Certain Names - ToPhrESH - 07.05.2011

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


Re: Allow Certain Names - Lorenc_ - 07.05.2011

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.