added variable for storing result instead of always just quering again
This commit is contained in:
parent
3d12319247
commit
40230f29c1
@ -5,6 +5,8 @@
|
||||
#include <sourcemod>
|
||||
|
||||
Database g_hDatabase;
|
||||
char sTitle[256];
|
||||
char sBuffer[16][256];
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@ -18,8 +20,13 @@ public Plugin myinfo =
|
||||
public void OnPluginStart()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "Event_notifier");
|
||||
RegConsoleCmd("sm_event", Command_Event_notifier);
|
||||
RegConsoleCmd("sm_events", Command_Event_notifier);
|
||||
RegConsoleCmd("sm_event", Command_Event_notifier, "Display infos about the next event");
|
||||
RegConsoleCmd("sm_events", Command_Event_notifier, "Display infos about the next event");
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
Event_select_query();
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
@ -30,61 +37,28 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
return;
|
||||
}
|
||||
g_hDatabase = db;
|
||||
Event_select_query();
|
||||
}
|
||||
|
||||
public Action Command_Event_notifier(int client, int args)
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "Event_notifier");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
//only 3 servers with events, none exist on jb
|
||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "select event_title, event_server, event_maps, event_date, event_time, event_reward from unloze_event.event e where e.event_server like '%s%i%s'", "%", i_port, "%");
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, GetClientSerial(client));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, int iSerial)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(iSerial)) == 0)
|
||||
return;
|
||||
Panel mSayPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio));
|
||||
char sTitle[256];
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
char sBuffer[256];
|
||||
results.FetchString(0, sTitle, sizeof(sTitle));
|
||||
Format(sTitle, sizeof(sTitle), "Title: %s", sTitle);
|
||||
mSayPanel.SetTitle(sTitle);
|
||||
results.FetchString(1, sBuffer, sizeof(sBuffer));
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
Format(sBuffer, sizeof(sBuffer), "Server: %s", sBuffer);
|
||||
mSayPanel.DrawText(sBuffer);
|
||||
results.FetchString(2, sBuffer, sizeof(sBuffer));
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
Format(sBuffer, sizeof(sBuffer), "Maps: %s", sBuffer);
|
||||
mSayPanel.DrawText(sBuffer);
|
||||
results.FetchString(3, sBuffer, sizeof(sBuffer));
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
Format(sBuffer, sizeof(sBuffer), "Date: %s", sBuffer);
|
||||
mSayPanel.DrawText(sBuffer);
|
||||
results.FetchString(4, sBuffer, sizeof(sBuffer));
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
Format(sBuffer, sizeof(sBuffer), "Time: %s", sBuffer);
|
||||
mSayPanel.DrawText(sBuffer);
|
||||
results.FetchString(5, sBuffer, sizeof(sBuffer));
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
Format(sBuffer, sizeof(sBuffer), "Reward: %s", sBuffer);
|
||||
mSayPanel.DrawText(sBuffer);
|
||||
}
|
||||
mSayPanel.SetTitle(sTitle);
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
|
||||
mSayPanel.DrawText(sBuffer[1]); //server
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
|
||||
mSayPanel.DrawText(sBuffer[2]); //maps
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
|
||||
mSayPanel.DrawText(sBuffer[3]); //date
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
|
||||
mSayPanel.DrawText(sBuffer[4]); //time
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
|
||||
mSayPanel.DrawText(sBuffer[5]); //reward
|
||||
|
||||
mSayPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
mSayPanel.DrawItem("1. Got it!", ITEMDRAW_RAWLINE);
|
||||
@ -92,6 +66,55 @@ public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[]
|
||||
mSayPanel.SetKeys(1023);
|
||||
mSayPanel.Send(client, Handler_Menu, 0);
|
||||
delete mSayPanel;
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void Event_select_query()
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "Event_notifier");
|
||||
return;
|
||||
}
|
||||
//only 3 servers with events, none exist on jb or ze2
|
||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "select event_title, event_server, event_maps, event_date, event_time, event_reward from unloze_event.event e where e.event_server like '%s%i%s'", "%", i_port, "%");
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery);
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
delete results;
|
||||
}
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
results.FetchString(0, sTitle, sizeof(sTitle));
|
||||
Format(sTitle, sizeof(sTitle), "Title: %s", sTitle);
|
||||
|
||||
results.FetchString(1, sBuffer[0], sizeof(sBuffer[]));
|
||||
|
||||
Format(sBuffer[1], sizeof(sBuffer[]), "Server: %s", sBuffer[0]);
|
||||
|
||||
results.FetchString(2, sBuffer[0], sizeof(sBuffer[]));
|
||||
|
||||
Format(sBuffer[2], sizeof(sBuffer[]), "Maps: %s", sBuffer[0]);
|
||||
|
||||
results.FetchString(3, sBuffer[0], sizeof(sBuffer[]));
|
||||
|
||||
Format(sBuffer[3], sizeof(sBuffer[]), "Date: %s", sBuffer[0]);
|
||||
|
||||
results.FetchString(4, sBuffer[0], sizeof(sBuffer[]));
|
||||
|
||||
Format(sBuffer[4], sizeof(sBuffer[]), "Time: %s", sBuffer[0]);
|
||||
|
||||
results.FetchString(5, sBuffer[0], sizeof(sBuffer[]));
|
||||
|
||||
Format(sBuffer[5], sizeof(sBuffer[]), "Reward: %s", sBuffer[0]);
|
||||
}
|
||||
delete results;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user