Üdvözletem.
Ezt az új MySQL R7 plugint nem nagyon ismerem még és gondoltam csinálok valami scriptet ami alapján megértem.
A scriptrõl annyit hogy az Online eltöltött idõt mér és menti kilépésnél, csatlakozásnál pedig beolvassa és ugyan onnan folytatja.
Tábla Struktúra CREATE TABLE IF NOT EXISTS `online` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(24) NOT NULL,
`Online` varchar(45) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Script /*
A scriptet készítette: Norby
Dátum: 2012.07.19 20:03
A script Y_less sscanf pluginját, Zeex zcmd parancsfeldolgozó include, és BlueG mysql pluginját tartalmazza.
Letöltési linkek
ZCMD: http://forum.sa-mp.com/showthread.php?t=91354
sscanf: http://forum.sa-mp.com/showthread.php?t=120356
mysql: http://forum.sa-mp.com/showthread.php?t=337810
*/
#include <a_samp>
#include <zcmd>
#include <a_mysql>
#include <sscanf2>
#define MYSQL_HOST \"localhost\"
#define MYSQL_USER \"root\"
#define MYSQL_DB \"norby\"
#define MYSQL_PASS \"\"
new
dbHandle,
OnlineTimeTimer[MAX_PLAYERS],
str[128],
query[512];
public OnFilterScriptInit()
{
dbHandle = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DB,MYSQL_PASS);
return 1;
}
public OnPlayerConnect(playerid)
{
format(query,sizeof(query),\"SELECT * FROM `online` WHERE Name = \'%s\'\",pName(playerid));
mysql_function_query(dbHandle,query,true,\"MySQL_Query\",\"d\",playerid);
OnlineTimeTimer[playerid] = SetTimerEx(\"OnlineTime\",1000,true,\"i\",playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
format(query,sizeof(query),\"SELECT * FROM `online` WHERE Name = \'%s\'\",pName(playerid));
mysql_function_query(dbHandle,query,true,\"MySQL_Online\",\"dsddddd\",playerid,pName(playerid),GetPVarInt(playerid,\"Years\"),GetPVarInt(playerid,\"Days\"),GetPVarInt(playerid,\"Hour\"),GetPVarInt(playerid,\"Minutes\"),GetPVarInt(playerid,\"Seconds\"));
KillTimer(OnlineTimeTimer[playerid]);
OnlineTimeTimer[playerid] = -1;
return 1;
}
CMD:stats(playerid)
{
format(str,sizeof(str),\"Szerveren Online eltölött idõd: %d év %02d nap %02d óra %02d perc %02d másodperc.\",
GetPVarInt(playerid,\"Years\"),GetPVarInt(playerid,\"Days\"),GetPVarInt(playerid,\"Hour\"),GetPVarInt(playerid,\"Minutes\"),GetPVarInt(playerid,\"Seconds\"));
SendClientMessage(playerid,-1,str);
return 1;
}
forward MySQL_Query(playerid);
public MySQL_Query(playerid)
{
new Time[32],year,day,hour,minute,sec;
cache_get_row(0, 2, Time);
sscanf(Time,\"p<,>ddddd\",year,day,hour,minute,sec);
SetPVarInt(playerid,\"Years\",year);
SetPVarInt(playerid,\"Days\",day);
SetPVarInt(playerid,\"Hour\",hour);
SetPVarInt(playerid,\"Minutes\",minute);
SetPVarInt(playerid,\"Seconds\",sec);
return 1;
}
forward MySQL_Online(playerid, name[],year,day,hour,minute,sec);
public MySQL_Online(playerid, name[],year,day,hour,minute,sec)
{
new rows, fields;
cache_get_data(rows, fields);
if(!rows)
{
format(query,sizeof(query),\"INSERT INTO `online` (ID,Name,Online) VALUES (NULL,\'%s\',\'%d, %02d, %02d, %02d, %02d\')\",name,year,day,hour,minute,sec);
mysql_function_query(dbHandle,query,false,\"\",\"\");
} else {
format(query,sizeof(query),\"UPDATE `online` SET Online = \'%d,%02d,%02d,%02d,%02d\' WHERE Name = \'%s\'\",year,day,hour,minute,sec,name);
mysql_function_query(dbHandle,query,false,\"\",\"\");
}
return 1;
}
forward OnlineTime(playerid);
public OnlineTime(playerid)
{
SetPVarInt(playerid,\"Seconds\",GetPVarInt(playerid,\"Seconds\") +1);
if(GetPVarInt(playerid,\"Seconds\") == 60){
SetPVarInt(playerid,\"Seconds\",0);
SetPVarInt(playerid,\"Minutes\",GetPVarInt(playerid,\"Minutes\") +1);
}
if(GetPVarInt(playerid,\"Minutes\") == 60){
SetPVarInt(playerid,\"Minutes\",0);
SetPVarInt(playerid,\"Hour\",GetPVarInt(playerid,\"Hour\") +1);
}
if(GetPVarInt(playerid,\"Hour\") == 24){
SetPVarInt(playerid,\"Hour\",0);
SetPVarInt(playerid,\"Days\",GetPVarInt(playerid,\"Days\") +1);
}
if(GetPVarInt(playerid,\"Days\") == 365){
SetPVarInt(playerid,\"Days\",0);
SetPVarInt(playerid,\"Years\",GetPVarInt(playerid,\"Years\") +1);
}
return 1;
}
pName(playerid)
{
new pname[24];
GetPlayerName(playerid,pname,sizeof(pname));
return pname;
}
Verzió 2.0
Javítások/Újítások- Csak másodpercet mér és abból számolja ki az adatokat.
- Nincs timer gettime() függvénnyel van megoldva.
Anthony ötlete alapján frissítve.Script /*
A scriptet készítette: Norby
Dátum: 2012.07.19 20:03
A script Y_less sscanf pluginját, Zeex zcmd parancsfeldolgozó include, és BlueG mysql pluginját tartalmazza.
Letöltési linkek
ZCMD: http://forum.sa-mp.com/showthread.php?t=91354
sscanf: http://forum.sa-mp.com/showthread.php?t=120356
mysql: http://forum.sa-mp.com/showthread.php?t=337810
*/
#include <a_samp>
#include <zcmd>
#include <a_mysql>
#include <sscanf2>
#define MYSQL_HOST \"localhost\"
#define MYSQL_USER \"root\"
#define MYSQL_DB \"norby\"
#define MYSQL_PASS \"\"
new
dbHandle,
str[128],
Time[MAX_PLAYERS],
Time2[MAX_PLAYERS],
query[512];
public OnFilterScriptInit()
{
dbHandle = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DB,MYSQL_PASS);
return 1;
}
public OnPlayerConnect(playerid)
{
Time[playerid] = gettime();
format(query,sizeof(query),\"SELECT * FROM `online` WHERE Name = \'%s\'\",pName(playerid));
mysql_function_query(dbHandle,query,true,\"MySQL_Query\",\"d\",playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
Time2[playerid] = gettime();
new OnlineTime2 = Time2[playerid] - Time[playerid];
new OnlineTime = GetPVarInt(playerid,\"OnlineTime\") + OnlineTime2;
format(query,sizeof(query),\"SELECT * FROM `online` WHERE Name = \'%s\'\",pName(playerid));
mysql_function_query(dbHandle,query,true,\"MySQL_Online\",\"dsd\",playerid,pName(playerid),OnlineTime);
return 1;
}
forward MySQL_Query(playerid);
public MySQL_Query(playerid)
{
new oTime[12];
cache_get_row(0, 2, oTime);
SetPVarInt(playerid,\"OnlineTime\",strval(oTime));
format(str,sizeof(str),\"%s\",SecondsTransform(GetPVarInt(playerid,\"OnlineTime\")));
SendClientMessage(playerid,-1,str);
return 1;
}
forward MySQL_Online(playerid, name[],oTime);
public MySQL_Online(playerid, name[],oTime)
{
new rows, fields;
cache_get_data(rows, fields);
if(!rows)
{
format(query,sizeof(query),\"INSERT INTO `online` (ID,Name,Online) VALUES (NULL,\'%s\',\'%d\')\",name,oTime);
mysql_function_query(dbHandle,query,false,\"\",\"\");
} else {
format(query,sizeof(query),\"UPDATE `online` SET Online = \'%d\' WHERE Name = \'%s\'\",oTime,name);
mysql_function_query(dbHandle,query,false,\"\",\"\");
}
return 1;
}
pName(playerid)
{
new pname[24];
GetPlayerName(playerid,pname,sizeof(pname));
return pname;
}
// -----------------------------------------------------------------------------
// Név: SecondsTransform
// Készítõ: GameStar
// Frissítve: 2012. június 17.
// -----------------------------------------------------------------------------
stock SecondsTransform(seconds)
{
new string[64],
rest,
weeks,
days,
hours,
minutes;
weeks = seconds / (60 * 60 * 24 * 7);
rest = seconds % (60 * 60 * 24 * 7);
days = rest / (60 * 60 * 24);
rest %= (60 * 60 * 24);
hours = rest / (60 * 60);
rest %= (60 * 60);
minutes = rest / 60;
rest %= 60;
format(string, 64, \"%i hét %i nap %i óra %i perc %i másodperc\", weeks,days,hours,minutes,rest);
return string;
}
Tesztelve van mûködik, jöhetnek a kritikák!