Help OnPlayerConnect
#1

i have this code that when they disconnect it saves theyr score in a .txt file
but when they connect it should be theyr score = txt file but it remaains 0 but in scriptfiles... they score is has the last time they disconnected help
Код:
public OnPlayerConnect(playerid)
{
    new file[1];
    new name[MAX_PLAYER_NAME];
    format(file, sizeof(file), "mygamemode/users/%s.txt", name);
    SetPlayerScore(playerid, dini_Int(file, "Score"));
    return 1;
}
Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[MAX_PLAYER_NAME+25], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    dini_Create(file);
    format(file, sizeof(file), "mygamemode/users/%s.txt", name);
    dini_IntSet(file, "Score", GetPlayerScore(playerid));
    return 1;
}
help plz
Reply
#2

I experienced the same problem. Try to run a timer which will set their score each second in the file.
Reply
#3

In OnPlayerConnect the size of 'file' is too small, it cant store the file path.
Set it to MAX_PLAYER_NAME+25 like in OnPlayerDisconnect.

Edit: +You forgot the GetPlayerName(playerid, name, sizeof(name)); in OnPlayerConnect
Reply
#4

Well you are setting the score on player connect and i suppose you got a login register system so you need loads players data at login cmd hope it help you
Reply
#5

mauzen i puted this
Quote:

public OnPlayerConnect(playerid)
{
new file [MAX_PLAYER_NAME+25], name[MAX_PLAYER_NAME];
format(file, sizeof(file), "mygamemode/users/%s.txt", name);
SetPlayerScore(playerid, dini_Int(file, "Score"));
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
new file[MAX_PLAYER_NAME+25], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
dini_Create(file);
format(file, sizeof(file), "mygamemode/users/%s.txt", name);
dini_IntSet(file, "Score", GetPlayerScore(playerid));
return 1;
}

still i get the same problem
Reply
#6

Oghh....
pawn Код:
new file[1];
format(file, sizeof(file), "mygamemode/users/%s.txt", name);
Are you thinking what you do?
How long is file string? I see its 1 character, but I guess "mygamemode/users/%s.txt" isnt one character long it has some 50+-5

you need
pawn Код:
new file[50]; // If I remeber right MAX_PLAYER_NAME == 24;
format(file, sizeof(file), "mygamemode/users/%s.txt", name);
Reply
#7

voldemort do you have msn?
Reply
#8

Check PM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)