16.05.2013, 18:43
(
Последний раз редактировалось Jason`; 17.05.2013 в 10:59.
)
Desenvolvi este pequeno script por necessidade e como й simples nгo custa nada compartilhar.
Й um sistema no qual pode-se inserir um log no banco de dados e ler a todos os logs in-game.
Crйditos:
- Pedro Miranda: script;
- BlueG: MySQL Plugin (r20)
- RyDeR`: CTime library
Cуdigo:
Como adiciono a biblioteca a meu script?
Como posso inserir um log na db?
PS: Nгo tenho intenзгo que vocк use isto. Mas se for o caso, vocк precisa ao menos saber criar o banco de dados.
Download:
- http://pastebin.com/ZNWvqyzD
Й um sistema no qual pode-se inserir um log no banco de dados e ler a todos os logs in-game.
Crйditos:
- Pedro Miranda: script;
- BlueG: MySQL Plugin (r20)
- RyDeR`: CTime library
Cуdigo:
pawn Код:
#if defined _sys_log_included
#endinput
#endif
#define _sys_log_included
#include <a_samp>
#include <a_mysql>
#include <CTime>
/*
native InsertLog(const text[]);
native DisplayLogs(playerid, limit);
*/
#if !defined mysql_included
#error "a_mysql must be included"
#endif
#if !defined _CTime_Included
#error "CTime must be included"
#endif
new
connectionHandle,
scriptString[256];
#if defined FILTERSCRIPT
public OnFilterScriptInit() {
connectionHandle = mysql_connect("localhost", "root", "sa-mp", "");
if(mysql_ping(connectionHandle) == -1)
return SendRconCommand("unloadfs sys_log");
mysql_function_query(connectionHandle,
"CREATE TABLE IF NOT EXISTS `sys_log` (`log_date` INT(11) NOT NULL, `log_text` VARCHAR(128) NOT NULL)", false, #, #);
if(funcidx("log_OnFilterScriptInit") != -1)
return CallLocalFunction("log_OnFilterScriptInit", #);
return true;
}
public OnFilterScriptExit() {
mysql_close(connectionHandle);
if(funcidx("log_OnFilterScriptExit") != -1)
return CallLocalFunction("log_OnFilterScriptExit", #);
return true;
}
#if defined _ALS_OnFilterScriptInit
#undef OnFilterScriptInit
#else
#define _ALS_OnFilterScriptInit
#endif
#define OnFilterScriptInit log_OnFilterScriptInit
#if defined _ALS_OnFilterScriptExit
#undef OnFilterScriptExit
#else
#define _ALS_OnFilterScriptExit
#endif
#define OnFilterScriptExit log_OnFilterScriptExit
forward log_OnFilterScriptInit();
forward log_OnFilterScriptExit();
#else
public OnGameModeInit() {
connectionHandle = mysql_connect("localhost", "root", "sa-mp", "");
if(mysql_ping(connectionHandle) == -1)
return SendRconCommand("unloadfs sys_log");
mysql_function_query(connectionHandle,
"CREATE TABLE IF NOT EXISTS `sys_log` (`log_date` INT(11) NOT NULL, `log_text` VARCHAR(128) NOT NULL)", false, #, #);
if(funcidx("log_OnGameModeInit") != -1)
return CallLocalFunction("log_OnGameModeInit", #);
return true;
}
public OnGameModeExit() {
mysql_close(connectionHandle);
if(funcidx("log_OnGameModeExit") != -1)
return CallLocalFunction("log_OnGameModeExit", #);
return true;
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit log_OnGameModeInit
#if defined _ALS_OnGameModeExit
#undef OnGameModeExit
#else
#define _ALS_OnGameModeExit
#endif
#define OnGameModeExit log_OnGameModeExit
forward log_OnGameModeInit();
forward log_OnGameModeExit();
#endif
stock InsertLog(const text[]) {
mysql_format(connectionHandle, scriptString, sizeof scriptString,
"INSERT INTO `sys_log` (`log_date`, `log_text`) VALUES (UNIX_TIMESTAMP(), '%s')", text);
mysql_function_query(connectionHandle, scriptString, false, #, #);
return true;
}
stock DisplayLogs(playerid, limit) {
mysql_format(connectionHandle, scriptString, sizeof scriptString,
"SELECT * FROM `sys_log` ORDER BY `log_date` ASC LIMIT %d", limit);
mysql_function_query(connectionHandle, scriptString, true, "r@DisplayLogs", "ii", playerid, limit);
return true;
}
r@DisplayLogs(playerid, limit); public r@DisplayLogs(playerid, limit) {
new num_rows, num_fields;
cache_get_data(num_rows, num_fields, connectionHandle);
if(!num_rows)
return SendClientMessage(playerid, 0xff0000ff, "(!) Nгo hб nenhum log no banco de dados.");
new
index = -1,
timestamp,
content[128],
tm<tmTime>;
format(content, sizeof content, "Ъltimos %02d logs", limit);
SendClientMessage(playerid, 0xffffffff, content);
while(++index < num_rows) {
timestamp = cache_get_field_content_int(index, "log_date", connectionHandle);
localtime(Time:timestamp, tmTime);
strftime(scriptString, sizeof scriptString, "%d/%m/%Y аs %X", tmTime);
cache_get_field_content(index, "log_text", content, connectionHandle);
format(scriptString, sizeof scriptString,
" %s, %s: %s", GetWeekDay(timestamp), scriptString, content);
SendClientMessage(playerid, 0xffffffff, scriptString);
}
return true;
}
stock GetWeekDay(timestamp) {
new
tm<tmTime>,
buffer[32];
localtime(Time:timestamp, tmTime);
switch(tmTime[tm_wday]) {
case 1: buffer = "Segunda-feira";
case 2: buffer = "Terзa-feira";
case 3: buffer = "Quarta-feira";
case 4: buffer = "Quinta-feira";
case 5: buffer = "Sexta-feira";
case 6: buffer = "Sбbado";
case 7: buffer = "Domingo";
}
return buffer;
}
Como adiciono a biblioteca a meu script?
pawn Код:
#include <sys_log>
Como posso inserir um log na db?
pawn Код:
InsertLog("Pedro Miranda criou o sys_log script.");
InsertLog("O script utiliza o MySQL Plugin e o CTime Plugin");
InsertLog("Crйditos para RyDeR` e BlueG.");
InsertLog("Postado em forum.sa-mp.com");
PS: Nгo tenho intenзгo que vocк use isto. Mas se for o caso, vocк precisa ao menos saber criar o banco de dados.
Download:
- http://pastebin.com/ZNWvqyzD