PHP код:
#include <a_samp>
public OnPlayerConnect(playerid)
{
new str[128], idx = 0;
GetPlayerName(playerid, str, sizeof(str));
format(str, sizeof(str), "players/%s.txt", str);
if(fexist(str))
{
new File:ftw = fopen(str, io_read);
if(ftw)
{
new Float:X = floatstr(strtok(str, idx));
new Float:Y = floatstr(strtok(str, idx));
new Float:Z = floatstr(strtok(str, idx));
new Float:A = floatstr(strtok(str, idx));
SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, A);
}
fclose(ftw);
}
return 1;
}
public OnPlayerDisconnect(playerid)
{
new str[128], Float:X, Float:Y, Float:Z, Float:A;
GetPlayerName(playerid, str, sizeof(str));
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
format(str, sizeof(str), "players/%s.txt", str);
new File:ftw = fopen(str, io_write);
if(ftw)
{
format(str, sizeof(str), "%.2f %.2f %.2f %.2f", X, Y, Z, A);
fwrite(ftw, str);
}
fclose(ftw);
return 1;
}
stock strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[128];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}