Puntos[playerid] += 10;
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;
}
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.
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;
}
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;
}
#include <a_samp>
if(dini_Isset("Puntos.ini",Nome))
Puntos[playerid] = dini_Int("Puntos.ini",Nome);
new Nome[MAX_PLAYER_NAME];
GetPlayerName(playerid, Nome, sizeof(Nome));
dini_IntSet("Puntos.ini", Nome, Puntos[playerid]);
if(!dini_Exists("Puntos.ini")) dini_Create("Puntos.ini");
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.
|
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;
}