· 9 years ago · Dec 21, 2016, 02:48 PM
1//============================[ MYSQL functions ]===============================
2forward MySQL_Load_ChristmasEvent(playerid);
3public MySQL_Load_ChristmasEvent(playerid)
4{
5 new rows, fields;
6 cache_get_data(rows, fields);
7 if(!rows) return CreateNewRecord(playerid);
8 PlayerXmas[playerid][PLAYER_SACK] = cache_get_field_content_int(0, "PLAYER_SACK");
9 PlayerXmas[playerid][LV_PRESENT] = cache_get_field_content_int(0, "LV_PRESENT");
10 PlayerXmas[playerid][SF_PRESENT] = cache_get_field_content_int(0, "SF_PRESENT");
11 PlayerXmas[playerid][RC_PRESENT] = cache_get_field_content_int(0, "RC_PRESENT");
12 PlayerXmas[playerid][FC_PRESENT] = cache_get_field_content_int(0, "FC_PRESENT");
13 PlayerXmas[playerid][BS_PRESENT] = cache_get_field_content_int(0, "BS_PRESENT");
14 PlayerXmas[playerid][AA_PRESENT] = cache_get_field_content_int(0, "AA_PRESENT");
15 PlayerXmas[playerid][TBE_PRESENT] = cache_get_field_content_int(0, "TBE_PRESENT");
16 PlayerXmas[playerid][CHI_PRESENT] = cache_get_field_content_int(0, "CHI_PRESENT");
17 PlayerXmas[playerid][LS_PRESENT] = cache_get_field_content_int(0, "LS_PRESENT");
18 PlayerXmas[playerid][FINISHED_EVENT] = cache_get_field_content_int(0, "FINISHED_EVENT");
19 return 1;
20}
21forward CreateNewRecord(playerid);
22public CreateNewRecord(playerid)
23{
24 new query[500];
25 mysql_format(sqlGameConnection, query, 500, "INSERT INTO `xmasevent2016` SET `ID` = %d, `PLAYER_SACK` = 0, `LV_PRESENT` = 0, `SF_PRESENT` = 0, `RC_PRESENT` = 0, `FC_PRESENT` = 0, `BS_PRESENT` = 0, ", PlayerInfo[playerid][pID]);
26 mysql_format(sqlGameConnection, query, 500, "%s `AA_PRESENT` = 0, `TBE_PRESENT` = 0, `CHI_PRESENT` = 0, `LS_PRESENT` = 0, `FINISHED_EVENT` = 0;", query);
27 mysql_tquery(sqlGameConnection, query);
28 return 1;
29}
30
31MySQL_Save_ChristmasEvent(playerid)
32{
33 new query[1000];
34 mysql_format(sqlGameConnection, query, sizeof(query), "UPDATE xmasevent2016 SET PLAYER_SACK = %d, LV_PRESENT = %d, SF_PRESENT = %d",
35 PlayerXmas[playerid][PLAYER_SACK], PlayerXmas[playerid][LV_PRESENT], PlayerXmas[playerid][SF_PRESENT]);
36
37 mysql_format(sqlGameConnection, query, sizeof(query), "%s, RC_PRESENT = %d, FC_PRESENT = %d, BS_PRESENT = %d, AA_PRESENT = %d",
38 query, PlayerXmas[playerid][RC_PRESENT], PlayerXmas[playerid][FC_PRESENT], PlayerXmas[playerid][BS_PRESENT], PlayerXmas[playerid][AA_PRESENT]);
39
40 mysql_format(sqlGameConnection, query, sizeof(query), "%s, TBE_PRESENT = %d, CHI_PRESENT = %d, LS_PRESENT = %d, FINISHED_EVENT = %d WHERE ID = %d;",
41 query, PlayerXmas[playerid][TBE_PRESENT], PlayerXmas[playerid][CHI_PRESENT], PlayerXmas[playerid][LS_PRESENT], PlayerXmas[playerid][FINISHED_EVENT], PlayerInfo[playerid][pID]);
42
43 mysql_tquery(sqlGameConnection, query, "");
44
45 return 1;
46}
47
48MySQL_createtable()
49{
50 new query[600];
51 mysql_format(sqlGameConnection, query, 600, "CREATE TABLE IF NOT EXISTS `xmasevent2016` (`ID` int(11), `PLAYER_SACK` int(1), `LV_PRESENT` int(1), `SF_PRESENT` int(1), `RC_PRESENT` int(1),");
52 mysql_format(sqlGameConnection, query, 600, "%s `FC_PRESENT` int(1), `BS_PRESENT` int(1), `AA_PRESENT` int(1), `TBE_PRESENT` int(1), `CHI_PRESENT` int(1), `LS_PRESENT` int(1), `FINISHED_EVENT` int(1), PRIMARY KEY (`ID`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;", query);
53 mysql_tquery(sqlGameConnection, query);
54 return 1;
55}