[Ajuda] Erro SalvarPlayer DOF2
#1

Fiz um sistema de login atravйs de um tutorial aqui do forum, mas nгo estava salvando as informaзхes do player adicionei 2 forwards mas nгo salva informaзхes do mesmo jeito. Aqui estб o Gm

pawn Код:
#include <a_samp>
#include <dof2>

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define CONTAS "Contas/%s.ini"
main()
{
        print(" Blank Gamemode DOF2");
}

public OnGameModeInit()
{
        SetGameModeText("SERVIDOR RPG");
        return 1;
}
enum pInfo
{
        pKills,
        pDeaths,
        pMoney,
        pAdmin
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward SalvarLevel(playerid);
forward CarregarLevel(playerid);
//-------------------------

public OnGameModeExit()
{
        for(new i=0; i<MAX_PLAYERS; i++)
        SalvarPlayer(i);
        DOF2_Exit();
        return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
        return 1;
}

public OnPlayerConnect(playerid)
{
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid,name,sizeof(name));
        new String[225];
        format(String, sizeof(String), CONTAS, name);
        if(DOF2_FileExists(String)) // We check if the player is registered
        {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Welcome.Please log-in","{FFFFFF}Type your {00FF22}password {FFFFFF}here to log-in","Log-in","Quit");
        }
        else // If not registered
        {
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Please register!","{FFFFFF}Type your {00FF22}password {FFFFFF}here to register.","Register","Quit");
        }
        return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
        switch(dialogid) // We switch the dialogs
        {
                case DIALOG_REGISTER: // If dialog_register (id 1) shows up
                {
                        if(!response) Kick(playerid); // If he click on Quit, he will get kicked
                        if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Please register!","{FFFFFF}Type your {00FF22}password {FFFFFF}here to register.","Register","Quit");
                        // If he doesn't type anything, the dialog will show again.
                        if(response) // If he click on Register
                        {
                                new name[MAX_PLAYER_NAME]; // We declare the size of the name
                                GetPlayerName(playerid,name,sizeof(name)); // We get the name name
                                new String[225];
                                format(String, sizeof(String), CONTAS, name); // We get the path name from DOF2_File, that means from Users folder.
                                DOF2_CreateFile(String, inputtext); // Creates the name and the password.
                                DOF2_SetInt(String, "pKills", 0);
                                DOF2_SetInt(String, "pDeaths", 0);
                                DOF2_SetInt(String, "pMoney", 1000);
                                DOF2_SetInt(String, "pAdmin", 0);
                                DOF2_SaveFile();
                                SetSpawnInfo(playerid, 0, 0, 1722.5123, -1912.7931, 13.5647, 269.15, 0, 0, 0, 0, 0, 0); // Sets where the player will spawn, this coordinates are from the Unity Station in Los Santos
                                SpawnPlayer(playerid); // After registering, the player will spawn.
                                OnPlayerConnect(playerid);//Chama a public novamente
                        }
                }
                case DIALOG_LOGIN: // If dialog_login (id 2) shows up
                {
                        if(!response) Kick(playerid); // If he click on Quit, he will get kicked.
                        if(response) // If he click on Log-in
                        {
                                new name[MAX_PLAYER_NAME]; // We declare the size of the name
                                GetPlayerName(playerid,name,sizeof(name)); // We get the name name
                                new String[225];
                                format(String, sizeof(String), CONTAS, name); // We get the user path from DOF2_name ( folder Contas )
                                if(DOF2_FileExists(String)) // If he is registered
                                {
                                        if(DOF2_CheckLogin(String,inputtext)) // We check if the password match
                                        {
                                                PlayerInfo[playerid][pKills] = DOF2_GetInt(String,"pKills"); // We load our settings
                                                PlayerInfo[playerid][pDeaths] = DOF2_GetInt(String,"pDeaths");
                                                PlayerInfo[playerid][pMoney] = DOF2_GetInt(String, "pMoney");
                                                PlayerInfo[playerid][pAdmin] = DOF2_GetInt(String,"pAdmin");
                                                SetSpawnInfo(playerid, 0, 0, 1722.5123, -1912.7931, 13.5647, 269.15, 0, 0, 0, 0, 0, 0); // We set the spawn (Unity Station)
                                                SpawnPlayer(playerid); // The player spawns after log-in
                                                CarregarPlayer(playerid);
                                                return 1;
                                        }
                                        else // If the password don't match, they will get an error
                                        {
                                                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Wrong Password!","{F81414}You have typed a wrong password\n{FFFFFF}Type your password here to log-in!","Log-in","Quit");
                                                return 1;
                                        }
                                }
                        }
                }
        }
        return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
        SalvarPlayer(playerid);
        return 1;
}

public OnPlayerSpawn(playerid)
{
        GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
        SetPlayerSkin(playerid, 26);
        return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
        PlayerInfo[killerid][pKills]++;
        PlayerInfo[playerid][pDeaths]++;
        SalvarPlayer(playerid);
        return 1;
}


public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp("/status", cmdtext, true))
    {
        new status[999];
        format(status, sizeof(status), "Your Money: %i", PlayerInfo[playerid][pMoney]);
        new deaths[999];
        format(deaths, sizeof(deaths), "Your Deaths: %i", PlayerInfo[playerid][pDeaths]);
        SendClientMessage(playerid, -1, deaths);
        SendClientMessage(playerid, -1, status);
        return 1;
    }
    if(!strcmp("/suicidio", cmdtext, true))
    {
        SetPlayerHealth(playerid, -2);
        return 1;
    }
    if(!strcmp("/money", cmdtext, true))
    {
        GivePlayerMoney(playerid, 50000);
        return 1;
    }
    return SendClientMessage(playerid, -1, "{FF0000}Comando invalido! {FFFF00}Digite /comandos");
}

SalvarPlayer(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    new String[50];
    format(String, sizeof(String), CONTAS, name);
    PlayerInfo[playerid][pAdmin] =  DOF2_GetInt(String, "pAdmin");
    PlayerInfo[playerid][pMoney]  =  DOF2_GetInt(String, "pMoney");
    PlayerInfo[playerid][pKills]  =  DOF2_GetInt(String, "pKills");
    PlayerInfo[playerid][pDeaths] =  DOF2_GetInt(String, "pDeaths");
    return 1;
}
CarregarPlayer(playerid)
{
    new Nome[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Nome, sizeof(Nome));
    new String[50];
    format(String, sizeof(String), CONTAS, Nome);
    PlayerInfo[playerid][pAdmin] =  DOF2_GetInt(String, "pAdmin");
    PlayerInfo[playerid][pMoney]  =  DOF2_GetInt(String, "pMoney");
    PlayerInfo[playerid][pKills]  =  DOF2_GetInt(String, "pKills");
    PlayerInfo[playerid][pDeaths] =  DOF2_GetInt(String, "pDeaths");
    return 1;
}
Reply
#2

O problema estб na funзгo SalvarPlayer. Vocк deveria escrever no arquivo, mas estб fazendo leitura.

PHP код:
SalvarPlayer(playerid)
{
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    new 
String[50];
    
format(Stringsizeof(String), CONTASname);
    
DOF2_SetInt(String"pAdmin"PlayerInfo[playerid][pAdmin]);
    
DOF2_SetInt(String"pMoney"PlayerInfo[playerid][pMoney]);
    
DOF2_SetInt(String"pKills"PlayerInfo[playerid][pKills]);
    
DOF2_SetInt(String"pDeaths"PlayerInfo[playerid][pDeaths]);
    
DOF2_SaveFile();
    return 
1;

Se vocк observar bem o cуdigo, verб que as funзхes SalvarPlayer e CarregarPlayer sгo iguais, o que й estranho, jб que sгo operaзхes "opostas".
Reply
#3

Vish mano, nгo salvou na scriptfile :S.
Reply
#4

Jб verificou se vocк criou a pasta Contas?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)