HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <console>
  5. #include <events>
  6. #include <entity>
  7. #include <string>
  8. #include <clients>
  9.  
  10. #define TEXTMSG_PRINTNOTIFY 1
  11. #define TEXTMSG_PRINTCONSOLE 2
  12. #define TEXTMSG_PRINTTALK 3
  13. #define TEXTMSG_PRINTCENTER 4
  14.  
  15.  
  16. public Plugin:myinfo =
  17. {
  18. name = "C4 Countdown Timer",
  19. author = "sslice",
  20. description = "Ez a kis plugin, visszaszamol a robbanas pillanataig. Ezt az sm_c4timer hatarozza meg.",
  21. version = "1.0.0.0",
  22. url = "http://www.gameconnect.info/"
  23. };
  24.  
  25.  
  26. new Handle:sm_c4timer;
  27. new Handle:mp_c4timer;
  28.  
  29. new g_explosionTime;
  30. new g_lastCountdown;
  31.  
  32. // so we can unhook events when sm_c4timer is zero (disabled)
  33. new bool:g_isHooked;
  34.  
  35. // Stock written by jopmako
  36. stock SendMsg_TextMsg(client, type, const String:szMsg[], any:...)
  37. {
  38. if (strlen(szMsg) > 191){
  39. LogError("Disallow string len(%d) > 191", strlen(szMsg));
  40. return;
  41. }
  42.  
  43. decl String:buffer[192];
  44. VFormat(buffer, sizeof(buffer), szMsg, 4);
  45.  
  46. new Handle:hBf;
  47. if (!client)
  48. hBf = StartMessageAll("TextMsg");
  49. else hBf = StartMessageOne("TextMsg", client);
  50.  
  51. if (hBf != INVALID_HANDLE)
  52. {
  53. BfWriteByte(hBf, type);
  54. BfWriteString(hBf, buffer);
  55. EndMessage();
  56. }
  57. }
  58.  
  59.  
  60. public OnPluginStart()
  61. {
  62. mp_c4timer = FindConVar("mp_c4timer");
  63. if (mp_c4timer == INVALID_HANDLE)
  64. {
  65. g_isHooked = false;
  66. PrintToServer("* FATAL ERROR: Failed to find ConVar 'mp_c4timer'");
  67. }
  68. else
  69. {
  70. g_isHooked = true;
  71. HookEvent("bomb_planted", OnBombPlanted, EventHookMode_Post);
  72. HookEvent("bomb_beep", OnBombBeep, EventHookMode_Post);
  73.  
  74. sm_c4timer = CreateConVar("sm_c4timer", "5", "Ez az ido hatarozza meg, mikortol szamoljon vissza; A 0 ertek, kikapcsolja a plugint.", FCVAR_PLUGIN, true, 0.0, true, 30.0);
  75. HookConVarChange(sm_c4timer, OnC4TimerChange);
  76. }
  77. }
  78.  
  79. public OnPluginEnd()
  80. {
  81. if (g_isHooked == true)
  82. {
  83. UnhookEvent("bomb_planted", OnBombPlanted, EventHookMode_Post);
  84. UnhookEvent("bomb_beep", OnBombBeep, EventHookMode_Post);
  85. }
  86.  
  87. UnhookConVarChange(sm_c4timer, OnC4TimerChange);
  88. }
  89.  
  90. // This way we can remove the event hooks when sm_c4timer is 0 (disabled)
  91. public OnC4TimerChange(Handle:convar, const String:oldValue[], const String:newValue[])
  92. {
  93. new timer = StringToInt(newValue);
  94. if (timer == 0)
  95. {
  96. if (g_isHooked == true)
  97. {
  98. g_isHooked = false;
  99.  
  100. UnhookEvent("bomb_planted", OnBombPlanted, EventHookMode_Post);
  101. UnhookEvent("bomb_beep", OnBombBeep, EventHookMode_Post);
  102. }
  103. }
  104. else if (g_isHooked == false)
  105. {
  106. g_isHooked = true;
  107.  
  108. HookEvent("bomb_planted", OnBombPlanted, EventHookMode_Post);
  109. HookEvent("bomb_beep", OnBombBeep, EventHookMode_Post);
  110. }
  111. }
  112.  
  113.  
  114. public OnBombPlanted(Handle:event, const String:name[], bool:dontBroadcast)
  115. {
  116. g_explosionTime = GetTime() + GetConVarInt(mp_c4timer);
  117. }
  118.  
  119. public OnBombBeep(Handle:event, const String:name[], bool:dontBroadcast)
  120. {
  121. new now = GetTime();
  122. new timer = GetConVarInt(sm_c4timer);
  123. new diff = g_explosionTime - now;
  124. if (diff <= timer && g_lastCountdown != now && diff >= 0)
  125. {
  126. SendMsg_TextMsg(0, TEXTMSG_PRINTCENTER, "%d", diff);
  127. g_lastCountdown = GetTime();
  128. }
  129. }
  130.