Advertisement
freefiles

Untitled

Feb 28th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.24 KB | None | 0 0
  1. /**
  2. * RoundEvents Extended by Root
  3. *
  4. * Description:
  5. * Provides extended functionality for round events.
  6. *
  7. * Version 1.1
  8. * Changelog & more info at http://goo.gl/4nKhJ
  9. */
  10.  
  11. // ====[ SDKTOOLS ]=====================================================================
  12. #include <sdktools_functions>
  13.  
  14. // ====[ CONSTANTS ]====================================================================
  15. #define PLUGIN_NAME "RoundEvents Extended RUSSIAN"
  16. #define PLUGIN_VERSION "1.1"
  17.  
  18. #define UNLOCKTEAMWALL 10
  19. #define LOCKTEAMWALL 21
  20. // #define BONUSROUNDMAX 60.0
  21.  
  22. #define VOTE_YES "###yes###"
  23. #define VOTE_NO "###no###"
  24.  
  25. // ====[ VARIABLES ]====================================================================
  26. static const String:wallEnts[][] = { "func_team_wall", "func_teamblocker" };
  27.  
  28. enum
  29. {
  30. DODTeam_Unassigned,
  31. DODTeam_Spectator,
  32. DODTeam_Allies,
  33. DODTeam_Axis,
  34.  
  35. MAX_TEAMS
  36. };
  37.  
  38. enum
  39. {
  40. UnlockWall,
  41. BlockSpectators,
  42. ToggleAlltalk,
  43. SwitchTeamsAfter,
  44. SwitchAfterWins,
  45. SwitchTeamsImmunity,
  46. CallVoteForSwitch,
  47.  
  48. ConVar_Size
  49. };
  50.  
  51. enum ValueType
  52. {
  53. ValueType_Bool,
  54. ValueType_Int,
  55. ValueType_Float
  56. };
  57.  
  58. enum ConVar
  59. {
  60. Handle:ConVarHandle, // Handle of the convar
  61. ValueType:Type, // Type of value (bool, integer or a float)
  62. any:Value // The value
  63. };
  64.  
  65. new GetConVar[ConVar_Size][ConVar],
  66. Handle:SwitchVoteMenu,
  67. Handle:mp_allowspectators,
  68. Handle:sv_alltalk,
  69. // Handle:dod_bonusroundtime,
  70. RoundsPlayed,
  71. RoundsWon[MAX_TEAMS],
  72. bool:ShouldSwitch;
  73.  
  74. // ====[ PLUGIN ]=======================================================================
  75. public Plugin:myinfo =
  76. {
  77. name = PLUGIN_NAME,
  78. author = "Root,T@HK",
  79. description = "Provides extended functionality for round events RUS",
  80. version = PLUGIN_VERSION,
  81. url = "http://www.dodsplugins.com/"
  82. }
  83.  
  84.  
  85. /* OnPluginStart()
  86. *
  87. * When the plugin starts up.
  88. * ------------------------------------------------------------------------------------- */
  89. public OnPluginStart()
  90. {
  91. // Create console variables
  92. CreateConVar("dod_roundend_ex_version", PLUGIN_VERSION, PLUGIN_NAME, FCVAR_NOTIFY|FCVAR_DONTRECORD);
  93.  
  94. // New
  95. AddConVar(UnlockWall, ValueType_Bool, CreateConVar("dod_rex_unlockteamwall", "1", "Будет ли разблокировать team wall после завершения раунда\nстена будет возвращена в исходное состояние при запуске нового раунда", FCVAR_PLUGIN, true, 0.0, true, 1.0));
  96. AddConVar(BlockSpectators, ValueType_Bool, CreateConVar("dod_rex_blockspectators", "1", "Отключить переход в спектры после окончания раунда", FCVAR_PLUGIN, true, 0.0, true, 1.0));
  97. AddConVar(ToggleAlltalk, ValueType_Bool, CreateConVar("dod_rex_togglealltalk", "0", "Отключить ли голосовой чат (выключить sv_alltalk) на всём раунде и до конца, отключить его при запуске нового раунда", FCVAR_PLUGIN, true, 0.0, true, 1.0));
  98. AddConVar(SwitchTeamsAfter, ValueType_Int, CreateConVar("dod_rex_switchafterrounds", "4", "Устанавливает количество раундов, необходимых для вызова голосования или переключения команд на следующий раунд\nУстановите 0, чтобы отключить ", FCVAR_PLUGIN, true, 0.0));
  99. AddConVar(SwitchAfterWins, ValueType_Int, CreateConVar("dod_rex_switchafterwins", "0", "определяет количество побед одной из команд, необходимых для вызова голосования или переключения команд", FCVAR_PLUGIN, true, 0.0));
  100. AddConVar(SwitchTeamsImmunity, ValueType_Bool, CreateConVar("dod_rex_switchimmunity", "0", "Перемещать ли администраторов в противоположную команду после успешного голосования при запуске нового раунда", FCVAR_PLUGIN, true, 0.0, true, 1.0));
  101. AddConVar(CallVoteForSwitch, ValueType_Float, CreateConVar("dod_rex_callvotebeforswitch", "0.60", "определяет количество голосов для успешного голосования\n значение 1=100% ", FCVAR_PLUGIN, true, 0.0, true, 1.0));
  102.  
  103. // Get default ConVars
  104. mp_allowspectators = FindConVar("mp_allowspectators");
  105. sv_alltalk = FindConVar("sv_alltalk");
  106. // dod_bonusroundtime = FindConVar("dod_bonusroundtime");
  107.  
  108. // Hook events
  109. HookEvent("dod_round_win", OnRoundEnd, EventHookMode_Post);
  110. HookEvent("dod_round_start", OnRoundStart, EventHookMode_Pre);
  111. HookEvent("player_team", OnTeamChange, EventHookMode_Pre);
  112.  
  113. // Create and exec plugin's config (without version ConVar)
  114. AutoExecConfig(true, "RoundEvents_Extended");
  115.  
  116. // Load plugin's translations
  117. LoadTranslations("basevotes.phrases");
  118. LoadTranslations("common.phrases");
  119.  
  120. // Let's unlock value limits for time after round win until round restarts
  121. // SetConVarBounds(dod_bonusroundtime, ConVarBound_Upper, true, BONUSROUNDMAX);
  122. }
  123.  
  124. /* OnConfigsExecuted()
  125. *
  126. * When the map has loaded and all plugin configs are done executing.
  127. * ------------------------------------------------------------------------------------- */
  128. public OnConfigsExecuted()
  129. {
  130. // Reset everything
  131. RoundsPlayed = false;
  132. ShouldSwitch = false;
  133.  
  134. // Reset amount of wins for all existing teams
  135. for (new i; i < MAX_TEAMS; i++)
  136. {
  137. RoundsWon[i] = false;
  138. }
  139. }
  140.  
  141. /* OnConVarChange()
  142. *
  143. * Updates the stored convar value if the convar's value change.
  144. * ------------------------------------------------------------------------------------- */
  145. public OnConVarChange(Handle:conVar, const String:oldValue[], const String:newValue[])
  146. {
  147. for (new i; i < ConVar_Size; i++)
  148. {
  149. if (conVar == GetConVar[i][ConVarHandle])
  150. {
  151. UpdateConVarValue(i);
  152. }
  153. }
  154. }
  155.  
  156. /* OnRoundEnd()
  157. *
  158. * When a round ends.
  159. * ------------------------------------------------------------------------------------- */
  160. public OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  161. {
  162. // Get the round winner
  163. new WinnerTeam = GetEventInt(event, "team");
  164.  
  165. // Add +1 win count to a winner's team
  166. RoundsWon[WinnerTeam]++;
  167.  
  168. // Add amount of total rounds played
  169. RoundsPlayed++;
  170.  
  171. // If spectators should be blocked, disable it
  172. if (GetConVar[BlockSpectators][Value]) SetConVarBool(mp_allowspectators, false);
  173.  
  174. // Lets suppress 'Value of sv_alltalk changed to 1' from chat area when round ends
  175. if (GetConVar[ToggleAlltalk][Value])
  176. {
  177. // Get original flags and remove which is showing changes in chat
  178. SetConVarFlags(sv_alltalk, GetConVarFlags(sv_alltalk) & ~FCVAR_NOTIFY);
  179. SetConVarBool(sv_alltalk, true);
  180. }
  181.  
  182. if (GetConVar[UnlockWall][Value])
  183. {
  184. // Loop through and accept new collision group on wall entities of this map
  185. for (new i; i < sizeof(wallEnts); i++)
  186. {
  187. // A fix for infinite loops
  188. new entity = -1;
  189.  
  190. while ((entity = FindEntityByClassname(entity, wallEnts[i])) != -1)
  191. {
  192. SetEntProp(entity, Prop_Send, "m_CollisionGroup", UNLOCKTEAMWALL);
  193. }
  194. }
  195. }
  196.  
  197. // Make sure that we played enough amount of rounds
  198. if (GetConVar[SwitchTeamsAfter][Value] == RoundsPlayed
  199. || GetConVar[SwitchAfterWins][Value] == RoundsWon[WinnerTeam]) // Or any team got X amount of wins
  200. {
  201. // Call a vote if percent is defined
  202. if (GetConVar[CallVoteForSwitch][Value])
  203. {
  204. // Create vote handler
  205. SwitchVoteMenu = CreateMenu(SwitchTeamsVoteHandler, MenuAction:MENU_ACTIONS_ALL);
  206.  
  207. SetMenuTitle(SwitchVoteMenu, "Сменить команду после окончания раунда ?");
  208. AddMenuItem(SwitchVoteMenu, VOTE_YES, "Да");
  209. AddMenuItem(SwitchVoteMenu, VOTE_NO, "Нет");
  210.  
  211. // Dont allow client to close vote menu
  212. SetMenuExitButton(SwitchVoteMenu, false);
  213.  
  214. // Show vote menu to all during bonusround time
  215. // VoteMenuToAll(SwitchVoteMenu, GetConVarInt(dod_bonusroundtime) - 1);
  216. }
  217.  
  218. // Reset amount of played rounds when teams should be switched
  219. if (GetConVar[SwitchTeamsAfter][Value] == RoundsPlayed) RoundsPlayed = false;
  220.  
  221. // And reset amount of rounds won & rounds played in proper way at all
  222. if (GetConVar[SwitchAfterWins][Value] == RoundsWon[WinnerTeam])
  223. {
  224. for (new i; i < MAX_TEAMS; i++)
  225. {
  226. RoundsWon[i] = false;
  227. }
  228. }
  229.  
  230. ShouldSwitch = true;
  231. }
  232. }
  233.  
  234. /* OnRoundStart()
  235. *
  236. * Called when a round starts.
  237. * ------------------------------------------------------------------------------------- */
  238. public Action:OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  239. {
  240. // Enable spectators back
  241. if (GetConVar[BlockSpectators][Value]) SetConVarBool(mp_allowspectators, true);
  242.  
  243. if (GetConVar[ToggleAlltalk][Value])
  244. {
  245. // Disable alltalk and get notify flag back
  246. SetConVarBool(sv_alltalk, false);
  247. SetConVarFlags(sv_alltalk, GetConVarFlags(sv_alltalk) | FCVAR_NOTIFY);
  248. }
  249.  
  250. // Make sure that previous teamwall state should be returned to an original
  251. if (GetConVar[UnlockWall][Value])
  252. {
  253. for (new i; i < sizeof(wallEnts); i++)
  254. {
  255. // Let's get it started
  256. new entity = -1;
  257.  
  258. // Since there may be more than 2 walls, lets loop again
  259. while ((entity = FindEntityByClassname(entity, wallEnts[i])) != -1)
  260. {
  261. // Return collision group for wall entities to default (at most maps is 21)
  262. SetEntProp(entity, Prop_Send, "m_CollisionGroup", LOCKTEAMWALL);
  263. }
  264. }
  265. }
  266.  
  267. // Aren't teams should be switched?
  268. if (ShouldSwitch == true)
  269. {
  270. for (new client = 1; client <= MaxClients; client++)
  271. {
  272. // Make sure all players is in game
  273. if (IsClientInGame(client))
  274. {
  275. // Ignore admins from being switched if immunity is enabled
  276. if (GetConVar[SwitchTeamsImmunity][Value] && GetUserAdmin(client) != INVALID_ADMIN_ID) continue;
  277.  
  278. if (GetClientTeam(client) == DODTeam_Allies) // is player on allies ?
  279. {
  280. // Yep, get the other team
  281. ChangeClientTeam(client, DODTeam_Spectator);
  282. ChangeClientTeam(client, DODTeam_Axis);
  283. ShowVGUIPanel(client, "class_ger", INVALID_HANDLE, false);
  284. }
  285. else if (GetClientTeam(client) == DODTeam_Axis) // Nope.avi
  286. {
  287. // Needed to spectate players to switching teams without deaths (DoD:S bug - you dont die when you join spectators)
  288. ChangeClientTeam(client, DODTeam_Spectator);
  289. ChangeClientTeam(client, DODTeam_Allies);
  290. ShowVGUIPanel(client, "class_us", INVALID_HANDLE, false);
  291. }
  292. }
  293. }
  294.  
  295. // We no longer should be switched
  296. ShouldSwitch = false;
  297.  
  298. // Set teams score appropriately
  299. SetTeamScore(DODTeam_Allies, GetTeamScore(DODTeam_Axis));
  300. SetTeamScore(DODTeam_Axis, GetTeamScore(DODTeam_Allies));
  301. }
  302. }
  303.  
  304. /* OnTeamChange()
  305. *
  306. * Called when a player changes team.
  307. * ------------------------------------------------------------------------------------- */
  308. public Action:OnTeamChange(Handle:event, const String:name[], bool:dontBroadcast)
  309. {
  310. // This function suppress '*Player joined Wermacht/U.S' message
  311. if (ShouldSwitch) SetEventBroadcast(event, true);
  312. }
  313.  
  314. /* SwitchTeamsVoteHandler()
  315. *
  316. * Called when a menu action is completed.
  317. * ------------------------------------------------------------------------------------- */
  318. public SwitchTeamsVoteHandler(Handle:menu, MenuAction:action, client, param)
  319. {
  320. // Get MenuHandler action
  321. switch (action)
  322. {
  323. case MenuAction_DisplayItem: // Item text is being drawn to the display
  324. {
  325. decl String:display[8]; GetMenuItem(menu, param, "", 0, _, display, sizeof(display)); // Name of param
  326.  
  327. if (StrEqual(display, "Yes", false) || StrEqual(display, "No", false))
  328. {
  329. Format(display, sizeof(display), "%T", display, client);
  330. return RedrawMenuItem(display);
  331. }
  332. }
  333. case MenuAction_End: // A menu display has fully ended
  334. {
  335. CloseHandle(SwitchVoteMenu);
  336. SwitchVoteMenu = INVALID_HANDLE;
  337. }
  338. case MenuAction_VoteCancel, VoteCancel_NoVotes: // A vote sequence has been cancelled
  339. {
  340. ShouldSwitch = false;
  341. PrintToChatAll("\x04[RD_EX TeamSwitch]\x05 %t", "Никто не проголосовал");
  342. }
  343. case MenuAction_VoteEnd: // A vote sequence has succeeded
  344. {
  345. decl String:item[32], Float:percent, Float:limit, votes, totalVotes;
  346.  
  347. // Retrieve voting information
  348. GetMenuVoteInfo(param, votes, totalVotes);
  349. GetMenuItem(menu, client, item, sizeof(item));
  350.  
  351. if (StrEqual(item, VOTE_NO, false) && client == 1)
  352. {
  353. // Reverse the votes to be in relation to the Yes option
  354. votes = totalVotes - votes;
  355. }
  356.  
  357. // Get the percent
  358. percent = FloatDiv(float(votes), float(totalVotes));
  359. limit = GetConVar[CallVoteForSwitch][Value];
  360.  
  361. // Make sure that its a Yes / No vote
  362. if ((StrEqual(item, VOTE_YES, false) && FloatCompare(percent, limit) < 0 && client == 0)
  363. || (StrEqual(item, VOTE_NO, false) && client == 1))
  364. {
  365. PrintToChatAll("\x04[RD_EX TeamSwitch]\x05 %t", "Голосование Не Удалось", RoundToNearest(FloatMul(100.0, limit)), RoundToNearest(FloatMul(100.0, percent)), totalVotes);
  366. ShouldSwitch = false;
  367. }
  368. else PrintToChatAll("\x04[RD_EX TeamSwitch]\x05 %t", "Голосование Прошло Успешно", RoundToNearest(FloatMul(100.0, percent)), totalVotes);
  369. }
  370. }
  371. return 0; // Because menu handler should return a value
  372. }
  373.  
  374. /* AddConVar()
  375. *
  376. * Used to add a convar into the convar list.
  377. * ------------------------------------------------------------------------------------- */
  378. AddConVar(conVar, ValueType:type, Handle:conVarHandle)
  379. {
  380. GetConVar[conVar][ConVarHandle] = conVarHandle;
  381. GetConVar[conVar][Type] = type;
  382.  
  383. UpdateConVarValue(conVar);
  384.  
  385. HookConVarChange(conVarHandle, OnConVarChange);
  386. }
  387.  
  388. /* UpdateConVarValue()
  389. *
  390. * Updates the internal convar values.
  391. * ------------------------------------------------------------------------------------- */
  392. UpdateConVarValue(conVar)
  393. {
  394. switch (GetConVar[conVar][Type])
  395. {
  396. case ValueType_Bool: GetConVar[conVar][Value] = GetConVarBool (GetConVar[conVar][ConVarHandle]);
  397. case ValueType_Int: GetConVar[conVar][Value] = GetConVarInt (GetConVar[conVar][ConVarHandle]);
  398. case ValueType_Float: GetConVar[conVar][Value] = GetConVarFloat(GetConVar[conVar][ConVarHandle]);
  399. }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement