[Help]Dini, again
#1

Hi i need help with dini, again..

I've done this code practicing round with it

pawn Код:
#include <a_samp>
#include <zcmd>

public OnPlayerConnect(playerid)
{
    new file[50], Float:Armour;
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), "%s.ini", name);
    if(!dini_Exists(file))
    {
      dini_Create(file);
      dini_FloatSet(file, "Armour", 0);
      printf("%s's file created", name);
    }
    else
    {
      Armour = dini_Float(file, "Armour");
      SetPlayerArmour(playerid, Armour);
      printf("%s's file loaded", name);
    }
    return 1;
}


COMMAND:atest(playerid, params[])
{
    SetPlayerArmour(playerid, 100);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new Float:Armour, file[50];
    GetPlayerArmour(playerid, Armour);
    dini_FloatSet(file, "Armour", Armour);
    return 1;
}
It does work getting the players armour on connect, but when leaving it doesnt set the new armour value...anyone know why?

Thanks
Reply
#2

That's because you didn't set the file name before you write the data to it

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[50], Float:Armour;
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), "%s.ini", name);
    GetPlayerArmour(playerid, Armour);
    dini_FloatSet(file, "Armour", Armour);
    return 1;
}
Reply
#3

god im nub, thx
Reply
#4

I recommend using udb_encode for player files.
Since a player might have special characters in his name/nick and therefore the file can't be saved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)