Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 KB | None | 0 0
  1. /* =============================================================================
  2. *
  3. * Hide and Seek for Day of Defeat: Source
  4. *
  5. * =============================================================================
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License, version 3.0, as published by the
  9. * Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  14. * details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>
  18. *
  19. * =============================================================================
  20. */
  21.  
  22. #pragma semicolon 1
  23.  
  24. #include <sourcemod>
  25. #include <sdktools>
  26. #include <dodhooks>
  27.  
  28. #undef REQUIRE_EXTENSIONS
  29. #tryinclude <steamtools>
  30.  
  31. #define PL_VERSION "0.6.5"
  32.  
  33. #include "hns/offsets.sp"
  34. #include "hns/hidenseek.sp"
  35. #include "hns/convars.sp"
  36. #include "hns/config.sp"
  37. #include "hns/hooks.sp"
  38. #include "hns/commands.sp"
  39. #include "hns/events.sp"
  40.  
  41. public Plugin:myinfo =
  42. {
  43. name = "DoD:S Hide & Seek",
  44. author = "Andersso, Dave223 & Root",
  45. description = "Hide & Seek for DoD:S",
  46. version = PL_VERSION,
  47. url = "http://www.dodsplugins.com/"
  48. };
  49.  
  50. public OnPluginStart()
  51. {
  52. AutoExecConfig(true, "hidenseek_config", "hidenseek");
  53.  
  54. LoadHooks();
  55. LoadEvents();
  56. LoadOffsets();
  57. LoadConVars();
  58. LoadCommands();
  59.  
  60. CreateInfoPanel();
  61. }
  62.  
  63. public OnMapStart()
  64. {
  65. #if defined _steamtools_included
  66. if (LibraryExists("SteamTools"))
  67. {
  68. Steam_SetGameDescription("DoD:S Hide and Seek");
  69. }
  70. #endif
  71.  
  72. g_iLastMan = 0;
  73. g_iNumModels = 0;
  74. g_iRoundWins = 0;
  75.  
  76. g_bHideTime = false;
  77. g_bModRunning = false;
  78. g_bRoundActive = false;
  79.  
  80. g_hRoundTimer = INVALID_HANDLE;
  81.  
  82. PrecacheSound("buttons/blip1.wav", true);
  83.  
  84. g_iBeamSprite = PrecacheModel("materials/sprites/laser.vmt", true);
  85. g_iHaloSprite = PrecacheModel("materials/sprites/halo01.vmt", true);
  86.  
  87. LoadConfig();
  88. LoadModelsConfig();
  89. }
  90.  
  91. public OnMapEnd()
  92. {
  93. g_bModRunning = false;
  94. g_bRoundActive = false;
  95. }
  96.  
  97. public OnClientPutInServer(iClient)
  98. {
  99. if (GetConVarBool(g_ConVar[InfoPanel]))
  100. {
  101. g_hInfoPanelTimer[iClient] = CreateTimer(15.0, Timer_SendInfoPanel, iClient, TIMER_FLAG_NO_MAPCHANGE);
  102. }
  103.  
  104. g_bPlayerBlinded[iClient] = false;
  105. }
  106.  
  107. public OnClientDisconnect(iClient)
  108. {
  109. if (g_hInfoPanelTimer[iClient] != INVALID_HANDLE)
  110. {
  111. KillTimer(g_hInfoPanelTimer[iClient]);
  112. }
  113.  
  114. if (g_bModRunning && g_bRoundActive)
  115. {
  116. if (GetTeamClientCount(Team_Seekers) == 0)
  117. {
  118. if (GetTeamClientCount(Team_Hiders) >= GetConVarInt(g_ConVar[MinPlayers]))
  119. {
  120. SelectSeeker();
  121.  
  122. SetPlayerState(g_iSeeker, PlayerState_ObserverMode);
  123. ChangeClientTeam(g_iSeeker, Team_Seekers);
  124.  
  125. PrintHintText(g_iSeeker, "You're now the seeker!");
  126. PrintToChatAll("%s Player %N is now the seeker.", HIDENSEEK_PREFIX, g_iSeeker);
  127. }
  128. else
  129. {
  130. RestartRound();
  131. }
  132. }
  133. else
  134. {
  135. CheckWin();
  136. }
  137. }
  138. }
  139.  
  140. public Action:RoundTimer_Think(Handle:hTimer)
  141. {
  142. if (!g_bModRunning || !g_bRoundActive)
  143. {
  144. g_hRoundTimer = INVALID_HANDLE;
  145.  
  146. return Plugin_Stop;
  147. }
  148.  
  149. new iTimeRemaining = RoundFloat(GetTimeRemaining(g_iRoundTimer)) - 1;
  150.  
  151. if (GetConVarBool(g_ConVar[RoundTimerBeacon]))
  152. {
  153. if (iTimeRemaining < 120 && iTimeRemaining >= (120 - GetConVarInt(g_ConVar[BeaconTwoMinLeft])))
  154. {
  155. PerformBeaconAll();
  156.  
  157. return Plugin_Continue;
  158. }
  159.  
  160. if (iTimeRemaining < 60 && iTimeRemaining >= (60 - GetConVarInt(g_ConVar[BeaconOneMinLeft])))
  161. {
  162. PerformBeaconAll();
  163.  
  164. return Plugin_Continue;
  165. }
  166. }
  167.  
  168. if (GetConVarBool(g_ConVar[BeaconLastMan]) && ++g_iBeaconTicks >= GetConVarInt(g_ConVar[BeaconLastManInterval]))
  169. {
  170. g_iBeaconTicks = 0;
  171.  
  172. new iLastMan = GetClientOfUserId(g_iLastMan);
  173.  
  174. if (iLastMan != 0)
  175. {
  176. PerformBeacon(iLastMan);
  177. }
  178. }
  179.  
  180. switch (iTimeRemaining)
  181. {
  182. case 0:
  183. {
  184. if (g_bHideTime)
  185. {
  186. SetTimeRemaining(g_iRoundTimer, GetConVarInt(g_ConVar[RoundTime]));
  187.  
  188. PrintCenterTextAll(NULL_STRING);
  189. EmitSoundToAll(g_szGameSound_Start);
  190.  
  191. g_bHideTime = false;
  192.  
  193. for (new i = 1; i <= MaxClients; i++)
  194. {
  195. if (IsClientInGame(i))
  196. {
  197. if (g_bPlayerBlinded[i])
  198. {
  199. BlindPlayer(i, false);
  200. }
  201.  
  202. if (GetClientTeam(i) == Team_Seekers && GetPlayerClass(i) != Class_None)
  203. {
  204. RespawnPlayer(i, false);
  205. }
  206. }
  207. }
  208. }
  209. else
  210. {
  211. if (++g_iRoundWins >= GetConVarInt(g_ConVar[WinLimit]))
  212. {
  213. CreateTimer(10.0, Timer_EndGame, _, TIMER_FLAG_NO_MAPCHANGE);
  214. }
  215. else
  216. {
  217. for (new i = 1; i <= MaxClients; i++)
  218. {
  219. if (IsClientInGame(i))
  220. {
  221. EmitSoundToClient(i, g_szGameSound_Win);
  222. ScreenOverlay(i, g_szOverlay_HidersWin);
  223. }
  224. }
  225.  
  226. RestartRound();
  227.  
  228. g_hRoundTimer = INVALID_HANDLE;
  229. }
  230.  
  231. return Plugin_Stop;
  232. }
  233. }
  234.  
  235. case 60,120:
  236. {
  237. FlashTimer(iTimeRemaining);
  238. }
  239.  
  240. default:
  241. {
  242. if (g_bHideTime)
  243. {
  244. for (new i = 1; i <= MaxClients; i++)
  245. {
  246. if (IsClientInGame(i))
  247. {
  248. switch (GetClientTeam(i))
  249. {
  250. case Team_Hiders: PrintCenterText(i, "The seeker will spawn in %i seconds", iTimeRemaining);
  251. case Team_Seekers: PrintCenterText(i, "You will spawn in %i seconds", iTimeRemaining);
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258.  
  259. return Plugin_Continue;
  260. }
  261.  
  262. public Action:OnPlayerRespawn(iClient)
  263. {
  264. if (g_bModRunning && g_bRoundActive && g_bHideTime && GetClientTeam(iClient) == Team_Seekers)
  265. {
  266. if (IsPlayerAlive(iClient))
  267. {
  268. SetPlayerState(g_iSeeker, PlayerState_ObserverMode);
  269. }
  270.  
  271. return Plugin_Handled;
  272. }
  273.  
  274. return Plugin_Continue;
  275. }
  276.  
  277. SelectSeeker()
  278. {
  279. new iClients[MaxClients], iNumClients = 0;
  280.  
  281. for (new i = 1; i <= MaxClients; i++)
  282. {
  283. if (i != g_iSeeker && IsClientInGame(i) && GetClientTeam(i) > Team_Spectators)
  284. {
  285. iClients[iNumClients++] = i;
  286. }
  287. }
  288.  
  289. if (iNumClients >= 1)
  290. {
  291. g_iSeeker = iClients[GetRandomInt(1, iNumClients) - 1];
  292. }
  293. else
  294. {
  295. LogError("Error: Unable to select seeker!");
  296. }
  297. }
  298.  
  299. CheckWin()
  300. {
  301. if (g_bModRunning && g_bRoundActive)
  302. {
  303. switch (GetTeamClientCount(Team_Hiders))
  304. {
  305. case 0:
  306. {
  307. PauseTimer(g_iRoundTimer);
  308.  
  309. if (++g_iRoundWins >= GetConVarInt(g_ConVar[WinLimit]))
  310. {
  311. CreateTimer(10.0, Timer_EndGame, _, TIMER_FLAG_NO_MAPCHANGE);
  312. }
  313. else
  314. {
  315. new iTimePassed = GetConVarInt(g_ConVar[RoundTime]) - RoundFloat(GetTimeRemaining(g_iRoundTimer));
  316.  
  317. new iTimeMin = iTimePassed / 60;
  318. new iTimeSec = iTimePassed % 60;
  319.  
  320. for (new i = 1; i <= MaxClients; i++)
  321. {
  322. if (IsClientInGame(i))
  323. {
  324. PrintToChat(i, "%s The Seekers won the round after: %i Minutes %i Seconds.", HIDENSEEK_PREFIX, iTimeMin, iTimeSec);
  325. EmitSoundToClient(i, g_szGameSound_Win);
  326.  
  327. ScreenOverlay(i, g_szOverlay_SeekersWin);
  328. }
  329. }
  330.  
  331. RestartRound();
  332. }
  333. }
  334.  
  335. case 1:
  336. {
  337. if (g_iLastMan == 0)
  338. {
  339. for (new i = 1; i <= MaxClients; i++)
  340. {
  341. if (IsClientInGame(i))
  342. {
  343. PrintToChat(i, "%s The seekers have beaconed the last man standing!", HIDENSEEK_PREFIX);
  344.  
  345. if (GetClientTeam(i) == Team_Hiders)
  346. {
  347. g_iLastMan = GetClientUserId(i);
  348.  
  349. break;
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. }
  358.  
  359. RestartRound()
  360. {
  361. g_iLastMan = 0;
  362. g_iBeaconTicks = 0;
  363. g_bRoundActive = false;
  364.  
  365. if (g_hRoundTimer != INVALID_HANDLE)
  366. {
  367. KillTimer(g_hRoundTimer);
  368. g_hRoundTimer = INVALID_HANDLE;
  369. }
  370.  
  371. CreateTimer(10.0, Timer_RestartRound, _, TIMER_FLAG_NO_MAPCHANGE);
  372. }
  373.  
  374. public Action:Timer_RestartRound(Handle:hTimer)
  375. {
  376. if (GetTeamClientCount(Team_Hiders) + GetTeamClientCount(Team_Seekers) >= GetConVarInt(g_ConVar[MinPlayers]))
  377. {
  378. SelectSeeker();
  379. BlindPlayer(g_iSeeker, true);
  380.  
  381. g_bHideTime = true;
  382. g_bRoundActive = true;
  383.  
  384. for (new i = 1; i <= MaxClients; i++)
  385. {
  386. if (IsClientInGame(i))
  387. {
  388. RemoveScreenOverlay(i);
  389.  
  390. if (i != g_iSeeker && GetClientTeam(i) > Team_Spectators)
  391. {
  392. SetPlayerState(i, PlayerState_ObserverMode);
  393. ChangeClientTeam(i, Team_Hiders);
  394. }
  395. }
  396. }
  397.  
  398. if (GetClientTeam(g_iSeeker) != Team_Seekers)
  399. {
  400. SetPlayerState(g_iSeeker, PlayerState_ObserverMode);
  401. ChangeClientTeam(g_iSeeker, Team_Seekers);
  402. }
  403. }
  404. else
  405. {
  406. for (new i = 1; i <= MaxClients; i++)
  407. {
  408. if (IsClientInGame(i))
  409. {
  410. RemoveScreenOverlay(i);
  411. }
  412. }
  413.  
  414. g_bModRunning = false;
  415. }
  416.  
  417. SetRoundState(DoDRoundState_Restart);
  418. }
  419.  
  420. public Action:Timer_EndGame(Handle:hTimer)
  421. {
  422. g_bRoundActive = false;
  423.  
  424. new iGameEnd = CreateEntityByName("game_end");
  425.  
  426. if (iGameEnd != -1)
  427. {
  428. AcceptEntityInput(iGameEnd, "EndGame");
  429. }
  430. else
  431. {
  432. LogError("Unable to create entity: \"game_end\"!");
  433. }
  434. }
  435.  
  436. public Action:Timer_SendInfoPanel(Handle:hTimer, any:iClient)
  437. {
  438. g_hInfoPanelTimer[iClient] = INVALID_HANDLE;
  439.  
  440. SendPanelToClient(g_hInfoPanel, iClient, Handler_Dummy, 10);
  441. }
  442.  
  443. CreateInfoPanel()
  444. {
  445. g_hInfoPanel = CreatePanel();
  446.  
  447. SetPanelTitle(g_hInfoPanel, "Hide & Seek\n \n");
  448. DrawPanelText(g_hInfoPanel, "On round start, one player is chosen to be the seeker and");
  449. DrawPanelText(g_hInfoPanel, "the remaining players become hiders. The hiders disguise");
  450. DrawPanelText(g_hInfoPanel, "themselves using a wealth of frankly daft objects.\n \n");
  451. DrawPanelText(g_hInfoPanel, "Commands (Hiders):\n \n");
  452. DrawPanelText(g_hInfoPanel, "!1st - Switch to firstperson view");
  453. DrawPanelText(g_hInfoPanel, "!3rd - Switch to thirdperson view\n \n");
  454. DrawPanelItem(g_hInfoPanel, "Close");
  455. }
  456.  
  457. public Handler_Dummy(Handle:hPanel, MenuAction:MenAction, iParam1, iParam2)
  458. {
  459. return;
  460. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement