[Ajuda] Salvar e Carregar Posiзхes
#1

Jб tenho esse cod de salvar as posiзхes mas estou com dificuldade para fazer carregar varias posiзхes ao mesmo tempo.
Esse e para salvar.
Код:
CMD:sav(playerid,params[])
{
    new p;
    new str[100],Float:X,Float:Y,Float:Z,Float:Rotation;
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, Rotation);

    new File:pos = fopen("positions.txt", io_append);

    if(!sscanf(params,"i",p))
    {
        format(str, 100, "%dX_%f,%dY_%f,%dZ_%f,%dR_%f\r\n", p,X,p,Y,p,Z,p,Rotation);
        fwrite(pos, str);
    }
    fclose(pos);
    return 1;
}
Reply
#2

Acho que isto irб ajudar. Boa sorte https://sampforum.blast.hk/showthread.php?tid=409002
Reply
#3

Bom, terб que mudar algumas coisas no comando:
Код:
CMD:sav(playerid,params[])
{
    new p;
    new str[100],Float:X,Float:Y,Float:Z,Float:Rotation;
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, Rotation);

    new File:pos = fopen("positions.txt", io_append);

    if(!sscanf(params,"i",p))
    {
        format(str, 100, "%d,%.3f,%.3f,%.3f,%.3f\r\n", p,X,Y,Z,Rotation);
        fwrite(pos, str);
    }
    fclose(pos);
    return 1;
}
Depois para carregar:
Код:
forward CarregarArquivo();
public CarregarArquivo()
{
	if(fexist("positions.txt"))
	{
	    new lines;
	    CountLines("positions.txt", lines);
		new Argument[5][10];
		new entry[256];
		new File:file = fopen("positions.txt", io_read);
		new p, Float:X, Float:Y, Float:Z, Float:Rotation;
	    if(file)
		{
		    for(new i; i < lines; i++)
			{
				fread(file, entry);
				split(entry, Argument, ',');
				if(Argument[0][0] != EOS)
				{
				    p = strval(Argument[0]);
					X = floatstr(Argument[1]);
					Y = floatstr(Argument[2]);
					Z = floatstr(Argument[3]);
					Rotation = floatstr(Argument[4]);
					//Agora sete as informaзхes onde querer
				}
			}
			fclose(file);
		}
	}
	return 1;
}

stock CountLines(file[], &lines)
{
	lines = 0;
    new entry[256];
	new File:file2 = fopen(file, io_read);
	while(fread(file2, entry, 256))
	{
		lines++;
  	}
  	fclose(file2);
}

forward split(const strsrc[], strdest[][], delimiter);
public split(const strsrc[], strdest[][], delimiter)
{
	new i, li;
	new aNum;
	new len;
	while(i <= strlen(strsrc)){
	    if(strsrc[i]==delimiter || i==strlen(strsrc)){
	        len = strmid(strdest[aNum], strsrc, li, i, 128);
	        strdest[aNum][len] = 0;
	        li = i+1;
	        aNum++;
		}
		i++;
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)