Portal SAMP
[Tutorial] SCRIPT QUE GETA A POSICAO E ANGULO DO PLAYER E SALVA EM ARQUIVO .txt - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Guias e Tutoriais (https://portalsamp.com/forumdisplay.php?fid=7)
+--- Tópico: [Tutorial] SCRIPT QUE GETA A POSICAO E ANGULO DO PLAYER E SALVA EM ARQUIVO .txt (/showthread.php?tid=5166)



SCRIPT QUE GETA A POSICAO E ANGULO DO PLAYER E SALVA EM ARQUIVO .txt - namedu - 09/01/2026

IMPORTANTE:
Crie uma pasta chamada "Documents" dentro da pasta scriptfiles

Código:
#define FILTERSCRIPT

#include <a_samp>
#include <zcmd>

public OnFilterScriptInit()
{
    print("FS SalvarPos carregado com sucesso.");
    return 1;
}

public OnFilterScriptExit()
{
    print("FS SalvarPos descarregado.");
    return 1;
}

CMD:salvar(playerid, params[])
{
    new Float:x, Float:y, Float:z, Float:ang;
    new nome[MAX_PLAYER_NAME];
    new caminho[128];
    new linha[256];
    new File:arquivo;

    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, ang);
    GetPlayerName(playerid, nome, sizeof nome);

    // Caminho do arquivo
    format(caminho, sizeof caminho, "Documents/%s.txt", nome);

    // io_append = não sobrescreve
    arquivo = fopen(caminho, io_append);
    if (!arquivo)
    {
        SendClientMessage(playerid, -1, "Erro ao salvar a posicao.");
        return 1;
    }

    // Salva tudo em uma unica linha
    format(linha, sizeof linha, "%.4f, %.4f, %.4f, %.4f\r\n", x, y, z, ang);
    fwrite(arquivo, linha);
    fclose(arquivo);

    // Exibe no chat o que foi salvo
    format(linha, sizeof linha,
        "Posicao salva: X=%.4f | Y=%.4f | Z=%.4f | Angulo=%.4f",
        x, y, z, ang
    );
    SendClientMessage(playerid, 0x00FF00FF, linha);

    return 1;
}