Almacenar informaciуn en un archivo .txt -
xTexTx - 09.08.2014
Hola, tengo ganas de aprender a como hacer para que cuando utilicen: /g [Mensaje], almacene los mensajes que envнan en un archivo .txt.
їAlguien se tomarнa las molestias de explicarme?, muchas gracias.
Re: Almacenar informaciуn en un archivo .txt -
admantis - 09.08.2014
Hola amigo, puedes utilizar la funciуn fwrite. Estб muy bien documentada en la Wiki.
https://sampwiki.blast.hk/wiki/Fwrite
Respuesta: Almacenar informaciуn en un archivo .txt -
Alvaro89 - 09.08.2014
No soy bueno explicando amigo. Pero como veras el codigo es de lo mas simple
Aqui imagenes que funciona
[IMG]

[/IMG]
[IMG]

[/IMG]
Codigo
PHP код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define loghablan "Logs/Hablan.txt"
CMD:hablar(playerid, params[])
{
new texto[128];
if(sscanf(params, "s[128]", texto)) return SendClientMessage(playerid, -1, "USA:{FF0000} /hablar (texto)");
new string[150], nombre[MAX_PLAYER_NAME];
GetPlayerName(playerid, nombre, sizeof(nombre));
format(string, sizeof(string), "%s dice: %s", nombre, texto);
LogTest(string);
return 1;
}
forward LogTest(string[]);
public LogTest(string[])
{
new entry[256];
format(entry, sizeof(entry), "%s\r\n",string);
new File:hFile;
hFile = fopen(loghablan, io_append);
fwrite(hFile, entry);
fclose(hFile);
}
Respuesta: Almacenar informaciуn en un archivo .txt -
Swedky - 09.08.2014
Quote:
Originally Posted by Alvaro89
No soy bueno explicando amigo. Pero como veras el codigo es de lo mas simple
Aqui imagenes que funciona
[IMG]  [/IMG]
[IMG]  [/IMG]
Codigo
PHP код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define loghablan "Logs/Hablan.txt"
CMD:hablar(playerid, params[])
{
new texto[128];
if(sscanf(params, "s[128]", texto)) return SendClientMessage(playerid, -1, "USA:{FF0000} /hablar (texto)");
new string[150], nombre[MAX_PLAYER_NAME];
GetPlayerName(playerid, nombre, sizeof(nombre));
format(string, sizeof(string), "%s dice: %s", nombre, texto);
LogTest(string);
return 1;
}
forward LogTest(string[]);
public LogTest(string[])
{
new entry[256];
format(entry, sizeof(entry), "%s\r\n",string);
new File:hFile;
hFile = fopen(loghablan, io_append);
fwrite(hFile, entry);
fclose(hFile);
}
|
Formateas la misma cadena 2 veces, para quй?
Respuesta: Almacenar informaciуn en un archivo .txt -
DesingMyCry - 09.08.2014
A que te refieres Enzo?
Re: Almacenar informaciуn en un archivo .txt -
SickAttack - 09.08.2014
Te sugiero que guardes la informaciуn en archivos nuevos con la fecha como nombre del archivo, asн podrбs disminuir el tamaсo del archivo y se abran mas rбpido.