Portal SAMP
[Tutorial] STOCK DE SALVAMENTO COM DOF2 - 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] STOCK DE SALVAMENTO COM DOF2 (/showthread.php?tid=5165)



STOCK DE SALVAMENTO COM DOF2 - namedu - 09/01/2026

EXEMPLO PRÁTICO DE STOCK DE SALVAMENTE DE DADOS
USANDO DOF2


STOCK DE SALVAMENTO
Código:
stock salvarInfo(playerid)
{
    new arquivo[64], nome[MAX_PLAYER_NAME];
    new Float:x, Float:y, Float:z;

    GetPlayerName(playerid, nome, sizeof nome);
    format(arquivo, sizeof arquivo, "Contas/%s.ini", nome);

    GetPlayerPos(playerid, x, y, z);

    DOF2_SetInt(arquivo, "Dinheiro", GetPlayerMoney(playerid));
    DOF2_SetInt(arquivo, "Score", GetPlayerScore(playerid));
    DOF2_SetInt(arquivo, "Skin", GetPlayerSkin(playerid));

    // POSIÇÃO
    DOF2_SetFloat(arquivo, "PosX", x);
    DOF2_SetFloat(arquivo, "PosY", y);
    DOF2_SetFloat(arquivo, "PosZ", z);

    // INTERIOR E MUNDO
    DOF2_SetInt(arquivo, "Interior", GetPlayerInterior(playerid));
    DOF2_SetInt(arquivo, "VirtualWorld", GetPlayerVirtualWorld(playerid));

    DOF2_SaveFile();
    return 1;
}

ONDE USAR:

public OnPlayerDisconnect(playerid, reason)
{
    SalvarInfo(playerid);
    return 1;
}


////////////////////////////////////////////////////////////

STOCK DE CARREGAR INFORMACOES:

stock CarregarDados(playerid)
{
    new arquivo[64], nome[MAX_PLAYER_NAME];
    new Float:x, Float:y, Float:z;

    GetPlayerName(playerid, nome, sizeof nome);
    format(arquivo, sizeof arquivo, "Contas/%s.ini", nome);

    if(!DOF2_FileExists(arquivo)) return 0;

    x = DOF2_GetFloat(arquivo, "PosX");
    y = DOF2_GetFloat(arquivo, "PosY");
    z = DOF2_GetFloat(arquivo, "PosZ");

    SetPlayerInterior(playerid, DOF2_GetInt(arquivo, "Interior"));
    SetPlayerVirtualWorld(playerid, DOF2_GetInt(arquivo, "VirtualWorld"));

    SetPlayerPos(playerid, x, y, z);
    SetPlayerSkin(playerid, DOF2_GetInt(arquivo, "Skin"));

    SetPlayerScore(playerid, DOF2_GetInt(arquivo, "Score"));
    GivePlayerMoney(playerid, DOF2_GetInt(arquivo, "Dinheiro"));

    return 1;
}

COMO USAR:


public OnPlayerSpawn(playerid)
{

        CarregarDados(playerid);

    return 1;
}

///////////////////////////////////////

EXEMPLO COM SISTEMA DE LOGIN (configurado pelo dev da  GM):

Código:
public OnPlayerSpawn(playerid)
{
    if(PlayerInfo[playerid][pLogado])
    {
        CarregarDados(playerid);
    }
    return 1;
}