File Already Exists-problem.
#1

I want my login script to detect if a file with that players name exists, if not, then on /login say that it does not exist.

However, my current one says it never exists, even when it does. Someone correct it please? Tell me if you need more of the code. Thanks a lot

Note: "file" has been formatted to (playername).ini.

pawn Код:
if(strcmp(cmd, "/login", true) == 0)
    {
      new PlayerName[24];
      tmp = strtok(cmdtext, idx);
      if(strlen(tmp) == 0) return SendClientMessage(playerid, COLOR_GREY, "Usage: /login (password)");
        if(IsLogged[playerid] == 1)
        {
            SendClientMessage(playerid, COLOR_GREY, "ERROR: You already are logged in.");
            PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            return 1;
        }
        else
        {
          if(!fexist(file))
            {
            SendClientMessage(playerid, COLOR_GREY, "ERROR: This account does not exist.");
            PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            return 1;
            }
            else
Login code here
Reply
#2

You need to format the string, where the file is located.

Код:
if(!fexist(file))
Example only:
Код:
new file[256];
new name[24];
GetPlayerName(playerid, name, 24);
format(string, 256, "my_gamemode/accounts/%s.ini", name);
if(!fexists(string))
{
 //file doesn't exist blah blah
}
else
{
  login
}
Reply
#3

Quote:
Originally Posted by Rac3r
You need to format the string, where the file is located.

Код:
if(!fexist(file))
Example only:
Код:
new file[256];
new name[24];
GetPlayerName(playerid, name, 24);
format(string, 256, "my_gamemode/accounts/%s.ini", name);
if(!fexists(string))
{
 //file doesn't exist blah blah
}
else
{
  login
}
You sure about that? Here's my /register command, I never specify the path. It saves in Scriptfiles per default. And the "This already exists" works perfect.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256], idx, file[128], tmp[256], tmp2[256];
    cmd = strtok(cmdtext, idx);
    if(strcmp(cmd, "/register", true) == 0)
    {
      new name[MAX_PLAYER_NAME];
      tmp = strtok(cmdtext, idx);
      GetPlayerName(playerid, name, sizeof(name));
      if(strlen(tmp) == 0) return SendClientMessage(playerid, COLOR_GREY, "Usage: /register (password)");
      format(file,sizeof(file),"%s.ini",name);
      if(!fexist(file))
            {

dini_Create(file);
And more here.
}
            else
            {
              SendClientMessage(playerid, COLOR_GREY, "ERROR: Account already exists. Please login.");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            }
Reply
#4

Must be what Race3r says
Код:
if(strcmp(cmd, "/login", true) == 0)
	{
	  new PlayerName[24];
	  tmp = strtok(cmdtext, idx);
	  if(strlen(tmp) == 0) return SendClientMessage(playerid, COLOR_GREY, "Usage: /login (password)");
		if(IsLogged[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR_GREY, "ERROR: You already are logged in.");
			PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
			return 1;
		}
		else
		{
	  new name[MAX_PLAYER_NAME];
	  GetPlayerName(playerid, name, sizeof(name));
	  format(file,sizeof(file),"%s.ini",name);
		  if(!fexist(file))
			{
		  	SendClientMessage(playerid, COLOR_GREY, "ERROR: This account does not exist.");
		  	PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
		  	return 1;
			}
			else
Login code here
Reply
#5

Ahh I see it now, forgot to define the file at that part of the /login command, it came further down.

Oh, thanks for the help, gaiz!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)