HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Fordította: BBk
  3. */
  4.  
  5. #include <amxmodx>
  6. #include <engine>
  7.  
  8. #pragma semicolon 1
  9.  
  10. #define UPDATE_TIME 1.0
  11. #define ENTITY_CLASS "env_host_timeleft"
  12.  
  13. new bool:g_timerRunning = false;
  14. new g_MsgServerName;
  15. new g_szHostname[ 64 ];
  16. new g_pointerTimelimit;
  17. new g_pointerHostname;
  18. new g_cvarEnabled;
  19. new g_cvarStyle;
  20.  
  21. public plugin_init() {
  22. register_plugin( "Hostname Timeleft", "1.0", "xPaw" );
  23.  
  24. g_cvarEnabled = register_cvar( "sv_hostname_timeleft", "1" );
  25. g_cvarStyle = register_cvar( "sv_hostname_style", "3" );
  26. g_pointerTimelimit = get_cvar_pointer( "mp_timelimit" );
  27. g_pointerHostname = get_cvar_pointer( "hostname" );
  28.  
  29. g_MsgServerName = get_user_msgid( "ServerName" );
  30.  
  31. // Give delay to load configs...
  32. set_task( 2.5, "checkTimeleft" );
  33. }
  34.  
  35. public plugin_end( )
  36. if( g_timerRunning )
  37. if( strlen( g_szHostname ) )
  38. set_pcvar_string( g_pointerHostname, g_szHostname );
  39.  
  40. public checkTimeleft( ) {
  41. get_pcvar_string( g_pointerHostname, g_szHostname, 63 );
  42.  
  43. if( get_pcvar_num( g_cvarEnabled ) != 1 ) {
  44. g_timerRunning = false;
  45.  
  46. return;
  47. } else
  48. register_think( ENTITY_CLASS, "fwdThink_Updater" );
  49.  
  50. g_timerRunning = true;
  51.  
  52. // initialize thinking entity...
  53. new iEntityTimer = create_entity( "info_target" );
  54. entity_set_string( iEntityTimer, EV_SZ_classname, ENTITY_CLASS );
  55. entity_set_float( iEntityTimer, EV_FL_nextthink, get_gametime() + UPDATE_TIME );
  56. }
  57.  
  58. public fwdThink_Updater( iEntity ) {
  59. static szHostname[ 64 ], iStyle;
  60. iStyle = get_pcvar_num( g_cvarStyle );
  61.  
  62. if( get_pcvar_float( g_pointerTimelimit ) ) {
  63. static iHours, iMinutes, iSeconds;
  64.  
  65. iSeconds = get_timeleft( );
  66. iMinutes = iSeconds / 60;
  67. iHours = iMinutes / 60;
  68. iSeconds = iSeconds - iMinutes * 60;
  69. iMinutes = iMinutes - iHours * 60;
  70.  
  71.  
  72. if( iHours ) {
  73. switch( iStyle ) {
  74. case 1: formatex( szHostname, 63, "%s (Ido %d:%02d:%02d)", g_szHostname, iHours, iMinutes, iSeconds );
  75. case 2, 4: formatex( szHostname, 63, "%s (%d:%02d:%02d)", g_szHostname, iHours, iMinutes, iSeconds );
  76. case 3, 5: formatex( szHostname, 63, "(%d:%02d:%02d) %s", iHours, iMinutes, iSeconds, g_szHostname );
  77. }
  78. } else {
  79. switch( iStyle ) {
  80. case 1: formatex( szHostname, 63, "%s (Ido %d:%02d)", g_szHostname, iMinutes, iSeconds );
  81. case 2, 4: formatex( szHostname, 63, "%s (%d:%02d)", g_szHostname, iMinutes, iSeconds );
  82. case 3, 5: formatex( szHostname, 63, "(%d:%02d) %s", iMinutes, iSeconds, g_szHostname );
  83. }
  84. }
  85. } else {
  86. switch( iStyle ) {
  87. case 1: formatex( szHostname, 63, "%s (Nincs idolimit)", g_szHostname );
  88. case 2, 4: formatex( szHostname, 63, "%s (--:--)", g_szHostname );
  89. case 3, 5: formatex( szHostname, 63, "(--:--) %s", g_szHostname );
  90. }
  91. }
  92.  
  93. if( iStyle < 4 )
  94. set_pcvar_string( g_pointerHostname, szHostname );
  95.  
  96. message_begin( MSG_BROADCAST, g_MsgServerName );
  97. write_string( szHostname );
  98. message_end( );
  99.  
  100. entity_set_float( iEntity, EV_FL_nextthink, get_gametime() + UPDATE_TIME );
  101.  
  102. return PLUGIN_CONTINUE;
  103. }