SA-MP Forums Archive
OnPlayerDisconnect saving problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerDisconnect saving problem (/showthread.php?tid=262402)



[Solved]OnPlayerDisconnect saving problem - =WoR=Varth - 17.06.2011

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new files[48],message[48];
    format(files,sizeof(files),"Last log/%s.ini",Name());
    new INI:file = INI_Open(files);
    format(message,sizeof(message),"%s",TimeDate());
    INI_WriteString(file,"Logged off",message);
    INI_Close(file);
    return 1;
}
pawn Код:
Name()
{
    new n[MAX_PLAYER_NAME];
    foreach (Player,i) GetPlayerName(i,n,MAX_PLAYER_NAME);
    return n;
}
It create file ".ini" instead with the name. I put it in OnPlayerConnect and it worked perfectly (Saved in playername.ini)
I know some people said "It's not a good idea to save in OnPlayerDisconnect" but as ****** said:
Quote:

I've never heard of any issues using OnPlayerDisconnect either. The only one issue you COULD have is if the server crashes, but that's got nothing to do with OnPlayerDisconnect (and neither does lag so I don't know why it was even mentioned as an argument).

EDIT: If I remove "foreach (Player,i)" it's work fine. Is that the problem?


Re: OnPlayerDisconnect saving problem - Sascha - 17.06.2011

your "Name" function seems to be a bit senseless to me..
it will return the name of the last player... you should add an "id" to it..


Re: OnPlayerDisconnect saving problem - Calgon - 17.06.2011

Elaborating on what Sasha replied with, your "Name()" function loops through every player and gets the player name of the last connected player - this code is illogical and won't work for what you want it to do.

Scripting is based primary off logic - you script things, they make sense!

To fix your problem, you're going to need to add an ID parameter to your function and you're going to need to use that parameter. The proper term for a function parameter is an "argument" though.

The code most likely to fix this is:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new files[48],message[48];
    format(files,sizeof(files),"Last log/%s.ini",Name(playerid)); // you probably shouldn't use spaces in var names though!
    new INI:file = INI_Open(files);
    format(message,sizeof(message),"%s",TimeDate());
    INI_WriteString(file,"Logged off",message);
    INI_Close(file);
    return 1;
}
pawn Код:
Name(playerid)
{
    new n[MAX_PLAYER_NAME];
    GetPlayerName(playerid, n, MAX_PLAYER_NAME);
    return n;
}



Re: OnPlayerDisconnect saving problem - =WoR=Varth - 18.06.2011

I'm sorry, I'm just 4 days scripter .
Btw yeah that's do the trick. Thanks Calg00ne and Sascha
I'll learn more about loop