їComo guardar algunas cosas?
#1

Necesito saber como guardar esto:

pawn Код:
Puntos[playerid] += 10;
Quiero que cuando el jugador se desconecte se guarden en "scripfiles", y cuando se conecte se cargen.
Espero que me puedan ayudar.
Reply
#2

Si solo fuera esa variable, lo guardarнa en simple archivo de texto, asн:
pawn Код:
public OnPlayerConnect(playerid)
{
    new
        File:input, // Variable como referencia al archivo abierto.
        string[MAX_PLAYER_NAME + 4]; // Matriz para el nombre del jugador y el nombre del archivo.
       
    GetPlayerName(playerid, string, sizeof(string)); // Obtenemos el nombre del jugador.
    format(string, sizeof(string), "%s.txt", string); // Ponemos en una cadena de texto el nombre del jugador con la extenciуn del archivo.
    input = fopen(string, io_read); // Abrimos y a la vez asignamos a la variable el archivo.
    if(input != 0) // Si el archivo fuй abierto correctamente:
    {
        fread(input, string); // Leer el archivo y su contenido ponerlo en la cadena de texto "string".
        Puntos[playerid] = strval(fread); // Convertimos el contenido de "string" en un valor numйrico.
        fclose(input); // Cerramos el archivo.
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new
        File:output,
        string[MAX_PLAYER_NAME + 4];
       
    GetPlayerName(playerid, string, sizeof(string));
    format(string, sizeof(string), "%s.txt", string);
    output = fopen(string, io_write);
    if(output != 0)
    {
        format(string, sizeof(string), "%i", Puntos[playerid]);
        fwrite(output, string);
        fclose(output);
    }
    return 1;
}
Cuando el jugador se desconecta se guardan los datos, y cuando se conecta se cargan.
Reply
#3

Pero, їesto lo tengo que agregar en donde quiera que se guarde la informaciуn? їo ya se guarda si lo agrego en "OnPlayerConnect" y "OnPlayerDisconnect"?
Reply
#4

En realidad en el callback que quieras, pero te recomiendo que guardes la informaciуn cuando el jugador entre y salga solamente.
Reply
#5

Obtengo estos errores:

pawn Код:
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(248) : error 017: undefined symbol "string"
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(248) : error 017: undefined symbol "string"
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(249) : error 017: undefined symbol "string"
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(257) : error 017: undefined symbol "MAX_PLAYER_string"
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(257) : error 009: invalid array size (negative, zero or out of bounds)
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(257) : warning 217: loose indentation
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(257) : error 036: empty statement
C:\Documents and Settings\Administrador\Escritorio\Server\TDM\gamemodes\TDM.pwn(257) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


7 Errors.
Esto es lo que agregue en mi Gamemode:

pawn Код:
public OnPlayerConnect(playerid)
{
    new
        File:input,
        string[MAX_PLAYER_string + 4];
       
    GetPlayerName(playerid, string, sizeof(string));
    format(string, sizeof(string), "%s.txt", string);
    input = fopen(string, io_read);
    if(input != 0)
    {
        fread(input, string);
        Puntos[playerid] = strval(fread)
        fclose(input);
    }
    return 1;
}
Y OnPlayerDisconnect:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new
        File:output,
        string[MAX_PLAYER_string + 4];
       
    GetPlayerName(playerid, string, sizeof(string));
    format(string, sizeof(string), "%s.txt", string);
    output = fopen(string, io_write);
    if(output != 0)
    {
        format(string, sizeof(string), "%i", Puntos[playerid]);
        fwrite(output, string);
        fclose(output);
    }
    return 1;
}
Reply
#6

Fбcil, con DINI.

pawn Код:
#include <a_samp>
OnPlayerConnect
pawn Код:
if(dini_Isset("Puntos.ini",Nome))
Puntos[playerid] = dini_Int("Puntos.ini",Nome);
OnPlayerDisconnect
pawn Код:
new Nome[MAX_PLAYER_NAME];
GetPlayerName(playerid, Nome, sizeof(Nome));
dini_IntSet("Puntos.ini", Nome, Puntos[playerid]);
OnGameModeInit

pawn Код:
if(!dini_Exists("Puntos.ini")) dini_Create("Puntos.ini");
Reply
#7

Muchas gracias Garfield, si me sirvio.
Y tambien gracias Miguel.

Pero їporque cuando cierro el archivo "samp-server", lo vuelvo a abrir y entro a mi server tengo 0 Puntos?
Reply
#8

Quote:
Originally Posted by arturo clark
Посмотреть сообщение
Muchas gracias Garfield, si me sirvio.
Y tambien gracias Miguel.

Pero їporque cuando cierro el archivo "samp-server", lo vuelvo a abrir y entro a mi server tengo 0 Puntos?
Los datos se estбn guardando en OnPlayerDisconnect. Segъn como se cierre el server, o si crashea, OnPlayerDisconnect no es llamado para todos los jugadores. Lo que hacen algunos servers para evitar esto es guardar los datos en un timer cada cierta cantidad de tiempo, para asegurarse de que si el server crashea los 'relativamente' ъltimos datos estбn guardados.
Reply
#9

Quote:
Originally Posted by Zamaroht
Посмотреть сообщение
Los datos se estбn guardando en OnPlayerDisconnect. Segъn como se cierre el server, o si crashea, OnPlayerDisconnect no es llamado para todos los jugadores. Lo que hacen algunos servers para evitar esto es guardar los datos en un timer cada cierta cantidad de tiempo, para asegurarse de que si el server crashea los 'relativamente' ъltimos datos estбn guardados.
Check cada millesegundo.

pawn Код:
public OnGameModeInit()
{
    SetTimer("Check", 1000, true); // Recomended.
    return true;
}
public OnPlayerDisconnect(playerid, reason)
{
   Check(playerid);
   return true;
}
forward Check(playerid);
public Check(playerid);
{
    new Nome[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Nome, sizeof(Nome));
    dini_IntSet("Puntos.ini", Nome, Puntos[playerid]);
    return true;
}
Reply
#10

Aquн porque solo guarda una variable, pero un timer de 1 segundo para guardar los datos no es nada recomendable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)