2022-06-19 13:40:27 +02:00
# pragma semicolon 1
# define PLUGIN_AUTHOR "jenz"
# define PLUGIN_VERSION "1.0"
# pragma newdecls required
# include <sourcemod>
Database g_hDatabase ;
2023-04-01 20:48:54 +02:00
char sTitle [ 256 ] ;
char sBuffer [ 16 ] [ 256 ] ;
2022-06-19 13:40:27 +02:00
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 " ) ;
2023-04-01 20:48:54 +02:00
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 ( ) ;
2022-06-19 13:40:27 +02:00
}
public void SQL_OnDatabaseConnect ( Database db , const char [ ] error , any data )
{
if ( ! db | | strlen ( error ) )
{
LogError ( " Database error: %s " , error ) ;
return ;
}
g_hDatabase = db ;
2023-04-01 20:48:54 +02:00
Event_select_query ( ) ;
2022-06-19 13:40:27 +02:00
}
public Action Command_Event_notifier ( int client , int args )
2023-04-01 20:48:54 +02:00
{
Panel mSayPanel = new Panel ( GetMenuStyleHandle ( MenuStyle_Radio ) ) ;
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 ) ;
mSayPanel . SetKeys ( 1023 ) ;
mSayPanel . Send ( client , Handler_Menu , 0 ) ;
delete mSayPanel ;
return Plugin_Handled ;
}
public void Event_select_query ( )
2022-06-19 13:40:27 +02:00
{
if ( ! g_hDatabase )
{
Database . Connect ( SQL_OnDatabaseConnect , " Event_notifier " ) ;
2023-04-01 20:48:54 +02:00
return ;
2022-06-19 13:40:27 +02:00
}
2023-04-01 20:48:54 +02:00
//only 3 servers with events, none exist on jb or ze2
2022-06-19 13:40:27 +02:00
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 , " % " ) ;
2023-04-01 20:48:54 +02:00
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery ) ;
2022-06-19 13:40:27 +02:00
}
2023-04-01 20:48:54 +02:00
public void SQL_OnQueryCompleted ( Database db , DBResultSet results , const char [ ] error , DataPack data )
2022-06-19 13:40:27 +02:00
{
if ( ! db | | strlen ( error ) )
{
LogError ( " Query error 3: %s " , error ) ;
2023-04-01 20:48:54 +02:00
delete results ;
2022-06-19 13:40:27 +02:00
}
if ( results . RowCount & & results . FetchRow ( ) )
{
results . FetchString ( 0 , sTitle , sizeof ( sTitle ) ) ;
Format ( sTitle , sizeof ( sTitle ) , " Title: %s " , sTitle ) ;
2023-04-01 20:48:54 +02:00
results . FetchString ( 1 , sBuffer [ 0 ] , sizeof ( sBuffer [ ] ) ) ;
2022-06-19 13:40:27 +02:00
2023-04-01 20:48:54 +02:00
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 ] ) ;
}
2022-06-19 13:40:27 +02:00
delete results ;
}
public int Handler_Menu ( Menu menu , MenuAction action , int param1 , int param2 )
{
switch ( action )
{
case MenuAction_Select , MenuAction_Cancel :
delete menu ;
}
}