Multiple lines in save fiel
#1

Hi.

I am making a license and ticket system for my gamemode and everytime I relog it creates these lines in the save file:
Код:
Driver License = 0
Commercial License = 0
Tickets = 0
Ticket Total = 0
So after 4 logins my save game looks like this:
Код:
Driver License = 0
Commercial License = 0
Tickets = 0
Ticket Total = 0
Driver License = 0
Commercial License = 0
Ticket Total = 0
Driver License = 0
Commercial License = 0
Ticket Total = 0
Driver License = 0
Commercial License = 0
Ticket Total = 0
My code looks like this
Код:
forward SaveChar(playerid);
public SaveChar(playerid)
{	
	if(!IsPlayerConnected(playerid)) return 1;
	if(GetPVarInt(playerid, "prelogin") == 1) return print("Did not save, not logged in.");
	if(GetPVarInt(playerid, "Quiz") == 1) return print("Did not save, in quiz.");
	if(Connected[playerid] != 1) return print("Did not save, not logged in.");
	if(AdminDuty[playerid] == 1) return print("Did not save, admin duty.");
	GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
	new INI:File = INI_Open(UserPath(playerid));
	new Float:hp;
	GetPlayerIp(playerid, PlayerInfo[playerid][pIp], 50);
	GetPlayerHealth(playerid, hp);
	GetPlayerName(playerid, PlayerInfo[playerid][pName], 70);
        INI_SetTag(File,"data");
	INI_WriteInt(File,"Driver License", PlayerInfo[playerid][pDLicense]);
	INI_WriteInt(File,"Commercial License", PlayerInfo[playerid][pCLicense]);
	INI_WriteInt(File, "Tickets", PlayerInfo[playerid][pTickets]);
	INI_WriteInt(File, "Ticket Total", PlayerInfo[playerid][pTicketstotal]);
        INI_Close(File);
        new string[100];
	format(string, 100, "%s's character has saved successfully.", GetName(playerid));
	print(string);
        return 1;
}
Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
	INI_Int("Driver License", PlayerInfo[playerid][pDLicense]);
	INI_Int("Commercial License", PlayerInfo[playerid][pCLicense]);
	INI_Int("Tickets", PlayerInfo[playerid][pTickets]);
	INI_Int("Tickets Total", PlayerInfo[playerid][pTicketstotal]);
        return 1;
}
Reply
#2

Without SHOWING us the CODE how can we fix your PROBLEM?
Reply
#3

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Without SHOWING us the CODE how can we fix your code?
Sorry clicked post instead of preview
Reply
#4

While I was searching, I found a good quote from ****** why the file saves more than twice or every time you execute the callback/function
Quote:
Originally Posted by ******
Посмотреть сообщение
You can't have spaces in keys.
Let me clear this out, ****** said you are not allowed to use spaces, I would suggest you to use _ Underscore instead of space

pawn Код:
forward SaveChar(playerid);
public SaveChar(playerid)
{  
    if(!IsPlayerConnected(playerid)) return 1;

    if(GetPVarInt(playerid, "prelogin") == 1)
        return print("Did not save, not logged in.");

    if(GetPVarInt(playerid, "Quiz") == 1)
        return print("Did not save, in quiz.");

    if(Connected[playerid] != 1)
        return print("Did not save, not logged in.");

    if(AdminDuty[playerid] == 1)
        return print("Did not save, admin duty.");

     // MAX_PLAYERIP 15+1 = 16 | //MAX_PLAYER_NAME = 23+1 = 24
    new
        Float:hp, Float:Position[ 3 ];
    GetPlayerHealth(playerid, hp), GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
    GetPlayerIp(playerid, PlayerInfo[playerid][pIp], 16), GetPlayerName(playerid, PlayerInfo[playerid][pName], 24);

    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Driver_License", PlayerInfo[playerid][pDLicense]);
    INI_WriteInt(File,"Commercial_License", PlayerInfo[playerid][pCLicense]);
    INI_WriteInt(File, "Tickets", PlayerInfo[playerid][pTickets]);
    INI_WriteInt(File, "Ticket_Total", PlayerInfo[playerid][pTicketstotal]);
    INI_Close(File);

    new string[100];
    format(string, 100, "%s's character has saved successfully.", GetName(playerid));
    print(string);
    return 1;
}

forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{  
    INI_Int("Driver_License", PlayerInfo[playerid][pDLicense]);
    INI_Int("Commercial_License", PlayerInfo[playerid][pCLicense]);
    INI_Int("Tickets", PlayerInfo[playerid][pTickets]);
    INI_Int("Tickets_Total", PlayerInfo[playerid][pTicketstotal]);
    return 1;
}
Reply
#5

Ok thanks so much it works now Thanks +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)