Saving Player Pos and Loading it. - 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)
+--- Thread: Saving Player Pos and Loading it. (
/showthread.php?tid=528357)
Saving Player Pos and Loading it. -
GreenSt4lker - 27.07.2014
Hey can anyone create me a FS or script when player leaves server somewhere and joins back he will spawn where he was last. I am trying to create it for a hour now and i cant error all the times.
Re: Saving Player Pos and Loading it. -
reiss82 - 27.07.2014
Make a players directory in scriptfiles
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;
}
Re: Saving Player Pos and Loading it. -
Wizzy951 - 27.07.2014
You can find mysql and y_ini versions in my signature.
Re: Saving Player Pos and Loading it. -
Ts3 - 27.07.2014
Have that here it is in PT and uses dini, if you use DOF2 or another and only convert ..
Tуpic:
www.forum.sa-mp.com/showthread.php?t=191533
Download:
http://www.solidfiles.com/d/6765c/FS...Coordenada.zip
Re: Saving Player Pos and Loading it. -
GreenSt4lker - 27.07.2014
Quote:
Originally Posted by reiss82
Make a players directory in scriptfiles
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;
}
|
Thanks!