MySQL server info saving?
#1

Is it possible to save server infos in MySQL? like...

TotalKicks: X
TotalConnects: X

pawn Код:
Serverkicks ++;
ServerConnects ++;
and how to read from them?
pawn Код:
new string[35];
format(string,sizeof(string),"There has been %d kiced players on this server",ServerKicks);
SendClientMessage(playerid,0xFFFFFAA,string);
if possible... HOW? soz caps
Reply
#2

make a var that store the players kicks and stuff. when he gets kicked just do

kick[playerid]=kick[playerid]+1;

and then save it to mysql. so your just loading the value when ever he loggs in and then increasing it when he gets kicked and the save
Reply
#3

Something like:
ehh

btw im not used to use MySQL and.. Y_ini wont save the info... dini wont either

pawn Код:
#include <a_samp>
#include <mysql>

#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

enum ServerStats
{
    TotalKicks,
    TotalConnects,
    TotalDisconnects
}
new ServerData[MAX_PLAYERS][ServerStats];

public OnPlayerConnect(playerid)
{
    ServerData[playerid][TotalConnects] ++;
    UpdateConnects(playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    ServerData[playerid][TotalDisconnects] ++;
    return 1;
}




public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(create, 6, cmdtext);
    return 0;
}

dcmd_create(playerid, params[])
{
    #pragma unused params
    #pragma unused playerid
    new queue[200];
   
    format(queue, sizeof(queue), "INSERT INTO `ServerInfo` (TotalKicks, TotalConnects, TotalDisconnects) VALUES ('0', '0, '0')");
    mysql_query(queue);
    return 1;
}

stock UpdateConnects(playerid)
{
    new queue[200];

    format(queue, sizeof(queue), "UPDATE `ServerInfo` SET TotalConnects= '%d' WHERE TotalConnects= '%d'", ServerData[playerid][TotalConnects]);
    mysql_query(queue);

    mysql_free_result();
    return 1;
}
Reply
#4

first query fix:
format(queue, sizeof(queue), "INSERT INTO `ServerInfo` (TotalKicks, TotalConnects, TotalDisconnects) VALUES (0, 0, 0)");

second:

format(queue, sizeof(queue), "UPDATE `ServerInfo` SET TotalConnects= '%d''",ServerData[playerid][TotalConnects]);
Reply
#5

Код:
new tkicks;
new tcons;
new tdiscons;

public OnPlayerConnect(playerid)
{
	tcons++;
	new q[128];
	format(q,128,"UPDATE `setverinfo` SET totalkicks=%d, totalconnects=%d, totaldiscons=%d",tkicks,tcons,tdiscons);
	mysql_query(q);
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	tdiscons++;
	if(reason == 2) tkicks++;
	new q[128];
	format(q,128,"UPDATE `setverinfo` SET totalkicks=%d, totalconnects=%d, totaldiscons=%d",tkicks,tcons,tdiscons);
	mysql_query(q);
	return 1;
}

dcmd_create(playerid, params[])
{
    #pragma unused params
    #pragma unused playerid
    new queue[200];

    format(queue, sizeof(queue), "INSERT INTO `ServerInfo` (TotalKicks, TotalConnects, TotalDisconnects) VALUES (0, 0, 0)");
    mysql_query(queue);
    return 1;
}
proper way todo it
Reply
#6

Quote:
Originally Posted by THE_KNOWN
Посмотреть сообщение
Код:
new tkicks;
new tcons;
new tdiscons;

public OnPlayerConnect(playerid)
{
	tcons++;
	new q[128];
	format(q,128,"UPDATE `setverinfo` SET totalkicks=%d, totalconnects=%d, totaldiscons=%d",tkicks,tcons,tdiscons);
	mysql_query(q);
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	tdiscons++;
	if(reason == 2) tkicks++;
	new q[128];
	format(q,128,"UPDATE `setverinfo` SET totalkicks=%d, totalconnects=%d, totaldiscons=%d",tkicks,tcons,tdiscons);
	mysql_query(q);
	return 1;
}

dcmd_create(playerid, params[])
{
    #pragma unused params
    #pragma unused playerid
    new queue[200];

    format(queue, sizeof(queue), "INSERT INTO `ServerInfo` (TotalKicks, TotalConnects, TotalDisconnects) VALUES (0, 0, 0)");
    mysql_query(queue);
    return 1;
}
proper way todo it
Hmm it dont work :S

and if i get it to work... how to read from it?

Edit: i got it to work.. but how to read from the Database?
pawn Код:
new string[35];
format(string,sizeof(string),"Total connects of this server is %s",TotalConnects);
SendClientMessage(playerid,0xFFFFFAA,string);

//??/??/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)