#pragma semicolon 1 #define PLUGIN_AUTHOR "jenz" #define PLUGIN_VERSION "1.0" #pragma newdecls required #include Database g_hDatabase; public Plugin myinfo = { name = "event notifier ingame", author = PLUGIN_AUTHOR, description = "plugin simply tells information about the last announced event on this server", version = PLUGIN_VERSION, url = "www.unloze.com" }; public void OnPluginStart() { Database.Connect(SQL_OnDatabaseConnect, "Event_notifier"); RegConsoleCmd("sm_event", Command_Event_notifier); RegConsoleCmd("sm_events", Command_Event_notifier); } public void SQL_OnDatabaseConnect(Database db, const char[] error, any data) { if(!db || strlen(error)) { LogError("Database error: %s", error); return; } g_hDatabase = db; } 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.DrawItem("", ITEMDRAW_SPACER); mSayPanel.DrawItem("1. Got it!", ITEMDRAW_RAWLINE); mSayPanel.SetKeys(1023); mSayPanel.Send(client, Handler_Menu, 0); delete mSayPanel; delete results; } public int Handler_Menu(Menu menu, MenuAction action, int param1, int param2) { switch(action) { case MenuAction_Select, MenuAction_Cancel: delete menu; } }