A new question
#1

Hi!

I want to make a script, that searches a character in the name of the player, and returns with the number of the searched character. I have a RP gamemode, and I don't want to allow people to register with names that have more than 1 _ characters. In the basic gamemode, there's a script that don't allows the register with names without _ character, but you can register with names with any _ characters.

I tryed this, but I can't compile it:

Код:
public OnPlayerConnect(playerid)
{
  new plname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, plname, sizeof(plname));
  split(plname, playernamesplit, '_');
	if(Security != 0)
	{
	  SendClientMessage(playerid, COLOR_YELLOW, "Host has broken one of the Agreement rules, action has been taken.");
	  Kick(playerid);
	  return 1;
	}
  new namestring = strfind(plname, "_", true);
 	if(namestring == -1)
	{
		SendClientMessage(playerid, COLOR_YELLOW2, "Immigration Department: Your name is not acceptable.");
		SendClientMessage(playerid, COLOR_YELLOW2, "Hint: Your name must be in the format Firstname_Lastname.");
		Kick(playerid);
		return 1;
	}
	else if(playernamesplit >= 2)
	{
		SendClientMessage(playerid, COLOR_YELLOW2, "Immigration Department: Your name is not acceptable.");
		SendClientMessage(playerid, COLOR_YELLOW2, "Hint: Your name must be in the format Firstname_Lastname.");
		Kick(playerid);
		return 1;
	}
[...]
	return 1;
}
Compiling:

Код:
C:\Documents and Settings\LTomi\My Documents\Server\gamemodes\rpg.pwn(2900) : error 033: array must be indexed (variable "playernamesplit")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Sorry for my bad English.
Reply
#2

Anybody?
Please help me!
Reply
#3

Use a function such as this, to count the _ in the name:
pawn Код:
chrcount(str[], chr)
{
  new c;

  for (new i, j = strlen(str); i < j; i++)
    if (str[i] == chr)
      c++;

  return c;
}
Use like this:
pawn Код:
new c = chrcount(plname, '_');

if (c == 0) // no "_" in the name
  Kick(playerid);
Reply
#4

Thanks man!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)