dini saving.
#1

Okay I have these commands:

Код:
dcmd_register(playerid, params[])
{
  new file[128], pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  format(file, sizeof(file), "\\Users\\%s.ini", pname);
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "* Try '/register' [Password]");
  if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "* You are already registered!");
  dini_Create(file);
  dini_IntSet(file, "HashPW", udb_hash(params));
  dini_Set(file, "Password", params);
  dini_IntSet(file, "Score", GetPlayerScore(playerid));
  dini_IntSet(file, "Money", GetPlayerMoney(playerid));
  dini_IntSet(file, "pJob", PlayerInfo[playerid][pJob]);
  new string[128];
  format(string, 128, "* Welcome to Blueberry Role-Play! Nickname %s with password %s", pname, params);
  SendClientMessage(playerid, COLOR_YELLOW, string);
  Logged[playerid] = 1;
  SendClientMessage(playerid, COLOR_YELLOW, "* You have been automatically logged in!");
  return 1;
}

dcmd_login(playerid, params[])
{
  new file[128];
  new string[128], pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  format(file, sizeof(file), "\\Users\\%s.ini", pname);
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "* Try '/login' [Password]");
  if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "* You are not registered!");
  if(Logged[playerid]) return SendClientMessage(playerid, COLOR_RED, "* You are already logged in!");
  new tmp[128];
  tmp = dini_Get(file, "HashPW");
  if(udb_hash(params) != strval(tmp))
  {
    format(string, 128, "You specified the wrong password for %s!", pname);
    SendClientMessage(playerid, COLOR_RED, string);
  }
  else
  {
    Logged[playerid] = 1;
		SetPlayerScore(playerid, dini_Int(file, "Score"));
		GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
		PlayerInfo[playerid][pJob] = dini_Int(file, "pJob");
    SendClientMessage(playerid, COLOR_YELLOW, "* You have succesfully logged in!");
  }
  return 1;
}
My question, when player disconnect, will it save?
Reply
#2

No. You need to save it under OnPlayerDisconnect, or in timer, or both.
Reply
#3

How?

EDIT:Koppa it's my brother.
Reply
#4

Please, helpp!

What do I need to do?

Reply
#5

Since you're using dini/dudb -> http://forum.sa-mp.com/index.php?topic=4798.0
Reply
#6

I made one by my self but I am not at my home, so I can't test it:
But, just looking, it's alright?

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(Logged[playerid] == 1)
    {
        new file[128];
        new plName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, plName, sizeof(plName));
        format(file, sizeof(file), "\\Users\\%s.ini", plName);

        if(dini_Exists(file))
        {
            dini_IntSet(file, "Score", GetPlayerScore(playerid));
        dini_IntSet(file, "Money", GetPlayerMoney(playerid));
        dini_IntSet(file, "pJob", PlayerInfo[playerid][pJob]);
            return 1;
        }
    }
    return 1;
}
Reply
#7

You forgot to logout the player, after you save all that.

pawn Код:
Logged[playerid] = false;
Reply
#8

Код:
public OnPlayerDisconnect(playerid, reason)
{
 	if(Logged[playerid] == 1)
 	{
		new file[128];
		new plName[MAX_PLAYER_NAME];
		GetPlayerName(playerid, plName, sizeof(plName));
		format(file, sizeof(file), "\\Users\\%s.ini", plName);

		if(dini_Exists(file))
		{
			dini_IntSet(file, "Score", GetPlayerScore(playerid));
  		dini_IntSet(file, "Money", GetPlayerMoney(playerid));
  		dini_IntSet(file, "pJob", PlayerInfo[playerid][pJob]);
  			return 1;
  		}
	}
	
	Logged[playerid] = false;
	return 1;
}
Like this ?
Reply
#9

Like that. I guess that is good, try it and you'll know.
Reply
#10

Thanks, it's working!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)