SA-MP Forums Archive
BAN function. - 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: BAN function. (/showthread.php?tid=445110)



BAN function. - audriuxxx - 19.06.2013

Hi,

I want to make ban function. I can make it, but problem is i want to do if you write part of name Like:

Tom_

But in server is Tom_Aloe, Tom_Tort . Then you get message, "you can't use /ban command because you have write more name, because there is more players with same name. I think you understand what i want to say.


Re: BAN function. - feartonyb - 19.06.2013

If there is more players with that name then you have to write full name or the part until it's not same. Ex. there is Tom_Tom and Tom_Tech you have to write Tom_Te to bun Tom_Tech or Tom_To to ban Tom_Tom.


Re: BAN function. - RedFusion - 19.06.2013

I made this one for you, enjoy! I did not try to compile this btw.
pawn Код:
stock GetPlayerIDFromName(input[])
{
 /*
  -1 = NO INPUT
  -2 = NO PLAYER FOUND
  -3 = MULTIPLE PLAYERS FOUND
*/


 if(strlen(input) == 0) return -1;

 new name[MAX_PLAYER_NAME+1], savedplayerid, matches;
 for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
 {
  if(!IsPlayerConnected(playerid)) continue;

  GetPlayerName(playerid,name,sizeof(name));
  if(strfind(name,input,true) != -1)
  {
   matches++;
   savedplayerid = playerid;
  }
 }
 
 if(matches == 0) return -2;
 else if(matches > 1) return -3;
 return savedplayerid;
}



Re: BAN function. - CROSS_Hunter - 19.06.2013

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
I made this one for you, enjoy! I did not try to compile this btw.
pawn Код:
stock GetPlayerIDFromName(input[])
{
 /*
  -1 = NO INPUT
  -2 = NO PLAYER FOUND
  -3 = MULTIPLE PLAYERS FOUND
*/


 if(strlen(input) == 0) return -1;

 new name[MAX_PLAYER_NAME+1], savedplayerid, matches;
 for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
 {
  if(!IsPlayerConnected(playerid)) continue;

  GetPlayerName(playerid,name,sizeof(name));
  if(strfind(name,input,true) != -1)
  {
   matches++;
   savedplayerid = playerid;
  }
 }
 
 if(matches == 0) return -2;
 else if(matches > 1) return -3;
 return savedplayerid;
}
That wont change anything... He already has the function but he mis used it ... Like if i want to ban you (your name is Blah_Blah) and i have another one with a name blah_hey so writing /ban blah > according to the script it will either choose a random name... from yours or his or tell him its invalid ... so using blah_bl would identify it more clearly << >> Using the player's ID in such functions is recommended


Re: BAN function. - RedFusion - 19.06.2013

Here's an example of how to use the function.
sscanf and ZCMD is used in this example.
pawn Код:
CMD:ban(playerid,params[])
{
 if(!IsPlayerAdmin(playerid)) return 0;

 #define WHITE 0xFFFFFFFF
 new id, name[MAX_PLAYER_NAME+1];
 if(sscanf(params,"s[24]",name)) return SendClientMessage(playerid, WHITE, "USAGE: /Ban <name>");

 id = GetPlayerIDFromName(name);
 if(!IsPlayerConnected(id))
 {
  switch(id)
  {
   case -1: return SendClientMessage(playerid, WHITE, "ERROR: No input!");
   case -2: return SendClientMessage(playerid, WHITE, "ERROR: This player was not found!");
   case -3: return SendClientMessage(playerid, WHITE, "ERROR: Several players were found!");
   default: return SendClientMessage(playerid, WHITE, "ERROR: Something went wrong!");
  }
 }  
 Ban(id);
 return 1;
}