Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.89 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5. #include <sdkhooks>
  6.  
  7. #undef REQUIRE_PLUGIN
  8. #include <adminmenu>
  9.  
  10. #undef REQUIRE_EXTENSIONS
  11. #include <cstrike>
  12. #define REQUIRE_EXTENSIONS
  13.  
  14. // Team indices
  15. #define TEAM_1 2
  16. #define TEAM_2 3
  17. #define TEAM_SPEC 1
  18. #define SPECTATOR_TEAM 0
  19.  
  20. #define SWAPTEAM_VERSION "1.2.6"
  21. #define TEAMSWITCH_ADMINFLAG ADMFLAG_KICK
  22. #define TEAMSWITCH_ARRAY_SIZE 64
  23.  
  24. new bool:g_TF2Arena = false;
  25. new bool:TF2 = false;
  26. new bool:CSS = false;
  27. new bool:CSGO = false;
  28.  
  29. public Plugin:myinfo = {
  30. name = "SwapTeam",
  31. author = "Rogue - Originally by MistaGee",
  32. description = "Switch people to spec or the other team immediately, at round end, on death",
  33. version = SWAPTEAM_VERSION,
  34. url = "http://www.sourcemod.net/"
  35. };
  36.  
  37. new Handle:hAdminMenu = INVALID_HANDLE,
  38. bool:onRoundEndPossible = false,
  39. bool:cstrikeExtAvail = false,
  40. String:teamName1[2],
  41. String:teamName2[3],
  42. bool:switchOnRoundEnd[TEAMSWITCH_ARRAY_SIZE],
  43. bool:switchOnDeath[TEAMSWITCH_ARRAY_SIZE];
  44.  
  45. enum TeamSwitchEvent
  46. {
  47. SwapTeamEvent_Immediately = 0,
  48. SwapTeamEvent_OnDeath = 1,
  49. SwapTeamEvent_OnRoundEnd = 2,
  50. SwapTeamEvent_ToSpec = 3
  51. };
  52.  
  53. public OnPluginStart()
  54. {
  55. CreateConVar("swapteam_version", SWAPTEAM_VERSION, "SwapTeam Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  56.  
  57. RegAdminCmd("sm_swapteam", Command_SwitchImmed, TEAMSWITCH_ADMINFLAG);
  58. RegAdminCmd("sm_swapteam_death", Command_SwitchDeath, TEAMSWITCH_ADMINFLAG);
  59. RegAdminCmd("sm_swapteam_d", Command_SwitchRend, TEAMSWITCH_ADMINFLAG);
  60. RegAdminCmd("sm_spec", Command_SwitchSpec, TEAMSWITCH_ADMINFLAG);
  61. RegAdminCmd("sm_team", Command_Team, TEAMSWITCH_ADMINFLAG);
  62.  
  63. HookEvent("player_death", Event_PlayerDeath);
  64.  
  65. // Hook game specific round end events - if none found, round end is not shown in menu
  66. decl String:theFolder[40];
  67. GetGameFolderName(theFolder, sizeof(theFolder));
  68.  
  69. PrintToServer("[SM] Hooking round end events for game: %s", theFolder);
  70.  
  71. if(StrEqual(theFolder, "dod"))
  72. {
  73. HookEvent("dod_round_win", Event_RoundEnd, EventHookMode_PostNoCopy);
  74. onRoundEndPossible = true;
  75. }
  76. else if(StrEqual(theFolder, "tf"))
  77. {
  78. decl String:mapname[128];
  79. GetCurrentMap(mapname, sizeof(mapname));
  80. HookEvent("teamplay_round_win", Event_RoundEnd, EventHookMode_PostNoCopy);
  81. HookEvent("teamplay_round_stalemate", Event_RoundEnd, EventHookMode_PostNoCopy);
  82. onRoundEndPossible = true;
  83. TF2 = true;
  84. if (strncmp(mapname, "arena_", 6, false) == 0 || strncmp(mapname, "vsh_", 4, false) == 0)
  85. {
  86. g_TF2Arena = true;
  87. }
  88. }
  89. else if(StrEqual(theFolder, "cstrike"))
  90. {
  91. HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
  92. onRoundEndPossible = true;
  93. CSS = true;
  94. }
  95. else if(StrEqual(theFolder, "csgo"))
  96. {
  97. HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
  98. onRoundEndPossible = true;
  99. CSGO = true;
  100. }
  101.  
  102. new Handle:topmenu;
  103. if(LibraryExists("adminmenu") && (( topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  104. {
  105. OnAdminMenuReady(topmenu);
  106. }
  107.  
  108. // Check for cstrike extension - if available, CS_SwitchTeam is used
  109. cstrikeExtAvail = (GetExtensionFileStatus("game.cstrike.ext") == 1);
  110.  
  111. LoadTranslations("common.phrases");
  112. LoadTranslations("swapteam.phrases");
  113. }
  114.  
  115. public OnMapStart()
  116. {
  117. GetTeamName(2, teamName1, sizeof(teamName1));
  118. GetTeamName(3, teamName2, sizeof(teamName2));
  119.  
  120. if (CSGO)
  121. {
  122. PrecacheModel("models/player/tm_leet_varianta.mdl");
  123. PrecacheModel("models/player/ctm_sas.mdl");
  124. }
  125.  
  126. PrintToServer("[SM] Team Names: %s %s - OnRoundEnd available: %s", teamName1, teamName2, (onRoundEndPossible ? "yes" : "no"));
  127. }
  128.  
  129. public Action:Command_Team(client, args)
  130. {
  131. if (args < 2)
  132. {
  133. if (cstrikeExtAvail)
  134. {
  135. ReplyToCommand(client, "[SM] %t", "team usage css");
  136. }
  137. else if (TF2)
  138. {
  139. ReplyToCommand(client, "[SM] %t", "team usage tf2");
  140. }
  141. else
  142. {
  143. ReplyToCommand(client, "[SM] %t", "team usage other");
  144. }
  145. return Plugin_Handled;
  146. }
  147.  
  148. decl String:arg[65];
  149. decl String:teamarg[65];
  150. decl teamargBuffer;
  151. GetCmdArg(1, arg, sizeof(arg));
  152. GetCmdArg(2, teamarg, sizeof(teamarg));
  153. teamargBuffer = StringToInt(teamarg);
  154.  
  155. decl String:target_name[MAX_TARGET_LENGTH];
  156. decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  157.  
  158. if ((target_count = ProcessTargetString(
  159. arg,
  160. client,
  161. target_list,
  162. MAXPLAYERS,
  163. COMMAND_TARGET_NONE,
  164. target_name,
  165. sizeof(target_name),
  166. tn_is_ml)) <= 0)
  167. {
  168. ReplyToTargetError(client, target_count);
  169. return Plugin_Handled;
  170. }
  171.  
  172. for (new i = 0; i < target_count; i++)
  173. {
  174. if (teamargBuffer == 0)
  175. {
  176. if (g_TF2Arena)
  177. {
  178. PerformSwitchToSpec(client, target_list[i]);
  179. }
  180. else
  181. {
  182. ChangeClientTeam(target_list[i], TEAM_SPEC);
  183. }
  184.  
  185. if (tn_is_ml)
  186. {
  187. ShowActivity2(client, "[SM] ", "%t", "Moved to spec", target_name);
  188. }
  189. else
  190. {
  191. ShowActivity2(client, "[SM] ", "%t", "Moved to spec", "_s", target_name);
  192. }
  193. }
  194. else if (teamargBuffer == 1)
  195. {
  196. if (g_TF2Arena)
  197. {
  198. PerformSwitchToSpec(client, target_list[i]);
  199. }
  200. else
  201. {
  202. ChangeClientTeam(target_list[i], TEAM_SPEC);
  203. }
  204.  
  205. if (tn_is_ml)
  206. {
  207. ShowActivity2(client, "[SM] ", "%t", "Moved to spec", target_name);
  208. }
  209. else
  210. {
  211. ShowActivity2(client, "[SM] ", "%t", "Moved to spec", "_s", target_name);
  212. }
  213. }
  214. else if (teamargBuffer == 2)
  215. {
  216. ChangeClientTeam(target_list[i], TEAM_1);
  217.  
  218. if (tn_is_ml)
  219. {
  220. ShowActivity2(client, "[SM] ", "%t", "Moved to team1", target_name);
  221. }
  222. else
  223. {
  224. ShowActivity2(client, "[SM] ", "%t", "Moved to team1", "_s", target_name);
  225. }
  226. }
  227. else if (teamargBuffer == 3)
  228. {
  229. ChangeClientTeam(target_list[i], TEAM_2);
  230.  
  231. if (tn_is_ml)
  232. {
  233. ShowActivity2(client, "[SM] ", "%t", "Moved to team2", target_name);
  234. }
  235. else
  236. {
  237. ShowActivity2(client, "[SM] ", "%t", "Moved to team2", "_s", target_name);
  238. }
  239. }
  240. }
  241.  
  242. return Plugin_Handled;
  243. }
  244.  
  245. public Action:Command_SwitchImmed(client, args)
  246. {
  247. if (args < 1)
  248. {
  249. ReplyToCommand(client, "[SM] %t", "swapteam usage");
  250. return Plugin_Handled;
  251. }
  252.  
  253. decl String:arg[65];
  254. GetCmdArg(1, arg, sizeof(arg));
  255.  
  256. decl String:target_name[MAX_TARGET_LENGTH];
  257. decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  258.  
  259. if ((target_count = ProcessTargetString(
  260. arg,
  261. client,
  262. target_list,
  263. MAXPLAYERS,
  264. COMMAND_TARGET_NONE,
  265. target_name,
  266. sizeof(target_name),
  267. tn_is_ml)) <= 0)
  268. {
  269. ReplyToTargetError(client, target_count);
  270. return Plugin_Handled;
  271. }
  272.  
  273. for (new i = 0; i < target_count; i++)
  274. {
  275. PerformSwitch(target_list[i]);
  276. LogAction(client, target_list[i], "\"%L\" moved (to opposite team) \"%L\"", client, target_list[i]);
  277. }
  278.  
  279. if (tn_is_ml)
  280. {
  281. ShowActivity2(client, "[SM] ", "%t", "switch by admin", target_name);
  282. }
  283. else
  284. {
  285. ShowActivity2(client, "[SM] ", "%t", "switch by admin", "_s", target_name);
  286. }
  287.  
  288. return Plugin_Handled;
  289. }
  290.  
  291. public Action:Command_SwitchDeath(client, args)
  292. {
  293. if (args < 1)
  294. {
  295. ReplyToCommand(client, "[SM] %t", "swapteam death usage");
  296. return Plugin_Handled;
  297. }
  298.  
  299. decl String:arg[65];
  300. GetCmdArg(1, arg, sizeof(arg));
  301.  
  302. decl String:target_name[MAX_TARGET_LENGTH];
  303. decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  304.  
  305. if ((target_count = ProcessTargetString(
  306. arg,
  307. client,
  308. target_list,
  309. MAXPLAYERS,
  310. COMMAND_FILTER_ALIVE,
  311. target_name,
  312. sizeof(target_name),
  313. tn_is_ml)) <= 0)
  314. {
  315. ReplyToTargetError(client, target_count);
  316. return Plugin_Handled;
  317. }
  318.  
  319. for (new i = 0; i < target_count; i++)
  320. {
  321. switchOnDeath[target_list[i]] = !switchOnDeath[target_list[i]];
  322. LogAction(client, target_list[i], "\"%L\" executed sm_swapteam_death on \"%L\"", client, target_list[i]);
  323.  
  324. if(switchOnDeath[target_list[i]])
  325. {
  326. if (tn_is_ml)
  327. {
  328. ShowActivity2(client, "[SM] ", "%t", "swap death", target_name);
  329. }
  330. else
  331. {
  332. ShowActivity2(client, "[SM] ", "%t", "swap death", "_s", target_name);
  333. }
  334. }
  335. else
  336. {
  337. if (tn_is_ml)
  338. {
  339. ShowActivity2(client, "[SM] ", "%t", "dont swap death", target_name);
  340. }
  341. else
  342. {
  343. ShowActivity2(client, "[SM] ", "%t", "dont swap death", "_s", target_name);
  344. }
  345. }
  346. }
  347.  
  348. return Plugin_Handled;
  349. }
  350.  
  351. public Action:Command_SwitchRend(client, args)
  352. {
  353. if (args < 1)
  354. {
  355. ReplyToCommand(client, "[SM] %t", "swapteam rend usage");
  356. return Plugin_Handled;
  357. }
  358.  
  359. if(!onRoundEndPossible)
  360. {
  361. ReplyToCommand(client, "[SM] %t", "swapteam rend error");
  362. return Plugin_Handled;
  363. }
  364.  
  365. decl String:arg[65];
  366. GetCmdArg(1, arg, sizeof(arg));
  367.  
  368. decl String:target_name[MAX_TARGET_LENGTH];
  369. decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  370.  
  371. if ((target_count = ProcessTargetString(
  372. arg,
  373. client,
  374. target_list,
  375. MAXPLAYERS,
  376. COMMAND_TARGET_NONE,
  377. target_name,
  378. sizeof(target_name),
  379. tn_is_ml)) <= 0)
  380. {
  381. ReplyToTargetError(client, target_count);
  382. return Plugin_Handled;
  383. }
  384.  
  385. for (new i = 0; i < target_count; i++)
  386. {
  387. switchOnRoundEnd[target_list[i]] = !switchOnRoundEnd[target_list[i]];
  388. LogAction(client, target_list[i], "\"%L\" executed sm_swapteam_d on \"%L\"", client, target_list[i]);
  389.  
  390. if(switchOnRoundEnd[target_list[i]])
  391. {
  392. if (tn_is_ml)
  393. {
  394. ShowActivity2(client, "[SM] ", "%t", "swap rend", target_name);
  395. }
  396. else
  397. {
  398. ShowActivity2(client, "[SM] ", "%t", "swap rend", "_s", target_name);
  399. }
  400. }
  401. else
  402. {
  403. if (tn_is_ml)
  404. {
  405. ShowActivity2(client, "[SM] ", "%t", "dont swap rend", target_name);
  406. }
  407. else
  408. {
  409. ShowActivity2(client, "[SM] ", "%t", "dont swap rend", "_s", target_name);
  410. }
  411. }
  412. }
  413.  
  414. return Plugin_Handled;
  415. }
  416.  
  417. public Action:Command_SwitchSpec(client, args)
  418. {
  419. if (args < 1)
  420. {
  421. ReplyToCommand(client, "[SM] %t", "swapteam spec usage");
  422. return Plugin_Handled;
  423. }
  424.  
  425. decl String:arg[65];
  426. GetCmdArg(1, arg, sizeof(arg));
  427.  
  428. decl String:target_name[MAX_TARGET_LENGTH];
  429. decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  430.  
  431. if ((target_count = ProcessTargetString(
  432. arg,
  433. client,
  434. target_list,
  435. MAXPLAYERS,
  436. COMMAND_TARGET_NONE,
  437. target_name,
  438. sizeof(target_name),
  439. tn_is_ml)) <= 0)
  440. {
  441. ReplyToTargetError(client, target_count);
  442. return Plugin_Handled;
  443. }
  444.  
  445. for (new i = 0; i < target_count; i++)
  446. {
  447. PerformSwitchToSpec(client, target_list[i]);
  448. }
  449.  
  450. if (tn_is_ml)
  451. {
  452. ShowActivity2(client, "[SM] ", "%t", "moved to spec", target_name);
  453. }
  454. else
  455. {
  456. ShowActivity2(client, "[SM] ", "%t", "moved to spec", "_s", target_name);
  457. }
  458.  
  459. return Plugin_Handled;
  460. }
  461.  
  462. public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  463. {
  464. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  465.  
  466. if(switchOnDeath[client])
  467. {
  468. PerformTimedSwitch(client);
  469. switchOnDeath[client] = false;
  470. }
  471. }
  472.  
  473. public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  474. {
  475. if(!onRoundEndPossible)
  476. return;
  477.  
  478. for(new i = 0; i < TEAMSWITCH_ARRAY_SIZE; i++)
  479. {
  480. if(switchOnRoundEnd[i])
  481. {
  482. PerformTimedSwitch(i);
  483. switchOnRoundEnd[i] = false;
  484. }
  485. }
  486. }
  487.  
  488.  
  489. /******************************************************************************************
  490. * ADMIN MENU HANDLERS *
  491. ******************************************************************************************/
  492.  
  493. public OnLibraryRemoved(const String:name[])
  494. {
  495. if(StrEqual(name, "adminmenu"))
  496. {
  497. hAdminMenu = INVALID_HANDLE;
  498. }
  499. }
  500.  
  501. public OnAdminMenuReady(Handle:topmenu)
  502. {
  503. // ?????????? ?????? ???? ??????
  504. if(topmenu == hAdminMenu)
  505. {
  506. return;
  507. }
  508. hAdminMenu = topmenu;
  509.  
  510. // Now add stuff to the menu: My very own category *yay*
  511. new TopMenuObject:menu_category = AddToTopMenu(
  512. hAdminMenu, // Menu
  513. "commands", // Name
  514. TopMenuObject_Category, // Type
  515. Handle_Category, // Callback
  516. INVALID_TOPMENUOBJECT // Parent
  517. );
  518.  
  519. if(menu_category == INVALID_TOPMENUOBJECT)
  520. {
  521. // Error... lame...
  522. return;
  523. }
  524.  
  525. // Now add items to it
  526. AddToTopMenu(
  527. hAdminMenu, // Menu
  528. "immed", // Name
  529. TopMenuObject_Item, // Type
  530. Handle_ModeImmed, // Callback
  531. menu_category, // Parent
  532. "immed", // cmdName
  533. TEAMSWITCH_ADMINFLAG // Admin flag
  534. );
  535.  
  536. AddToTopMenu(
  537. hAdminMenu, // Menu
  538. "on_death", // Name
  539. TopMenuObject_Item, // Type
  540. Handle_ModeDeath, // Callback
  541. menu_category, // Parent
  542. "on_death", // cmdName
  543. TEAMSWITCH_ADMINFLAG // Admin flag
  544. );
  545.  
  546. if(onRoundEndPossible)
  547. {
  548. AddToTopMenu(
  549. hAdminMenu, // Menu
  550. "on_rend", // Name
  551. TopMenuObject_Item, // Type
  552. Handle_ModeRend, // Callback
  553. menu_category, // Parent
  554. "on_rend", // cmdName
  555. TEAMSWITCH_ADMINFLAG // Admin flag
  556. );
  557. }
  558.  
  559. AddToTopMenu(
  560. hAdminMenu, // Menu
  561. "o_spec", // Name
  562. TopMenuObject_Item, // Type
  563. Handle_ModeSpec, // Callback
  564. menu_category, // Parent
  565. "to_spec", // cmdName
  566. TEAMSWITCH_ADMINFLAG // Admin flag
  567. );
  568.  
  569. }
  570.  
  571. public Handle_Category(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  572. {
  573. switch(action)
  574. {
  575. case TopMenuAction_DisplayTitle:
  576. Format(buffer, maxlength, "%t", "when move");
  577. case TopMenuAction_DisplayOption:
  578. Format(buffer, maxlength, "%t", "commands");
  579. }
  580. }
  581.  
  582. public Handle_ModeImmed(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  583. {
  584. if (action == TopMenuAction_DisplayOption)
  585. {
  586. Format(buffer, maxlength, "%t", "immediately");
  587. }
  588. else if(action == TopMenuAction_SelectOption)
  589. {
  590. ShowPlayerSelectionMenu(param, SwapTeamEvent_Immediately);
  591. }
  592. }
  593.  
  594. public Handle_ModeDeath(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  595. {
  596. if (action == TopMenuAction_DisplayOption)
  597. {
  598. Format(buffer, maxlength, "%t", "on death");
  599. }
  600. else if(action == TopMenuAction_SelectOption)
  601. {
  602. ShowPlayerSelectionMenu(param, SwapTeamEvent_OnDeath);
  603. }
  604. }
  605.  
  606. public Handle_ModeRend(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  607. {
  608. if (action == TopMenuAction_DisplayOption)
  609. {
  610. Format(buffer, maxlength, "%t", "on rend");
  611. }
  612. else if(action == TopMenuAction_SelectOption)
  613. {
  614. ShowPlayerSelectionMenu(param, SwapTeamEvent_OnRoundEnd);
  615. }
  616. }
  617.  
  618. public Handle_ModeSpec(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  619. {
  620. if (action == TopMenuAction_DisplayOption)
  621. {
  622. Format(buffer, maxlength, "%t", "to spec");
  623. }
  624. else if(action == TopMenuAction_SelectOption)
  625. {
  626. ShowPlayerSelectionMenu(param, SwapTeamEvent_ToSpec);
  627. }
  628. }
  629.  
  630.  
  631. /******************************************************************************************
  632. * PLAYER SELECTION MENU HANDLERS *
  633. ******************************************************************************************/
  634.  
  635. void:ShowPlayerSelectionMenu(client, TeamSwitchEvent:event, item = 0)
  636. {
  637. new Handle:playerMenu = INVALID_HANDLE;
  638.  
  639. // Create Menu with the correct Handler, so I don't have to store which player chose
  640. // which action...
  641. switch(event)
  642. {
  643. case SwapTeamEvent_Immediately:
  644. playerMenu = CreateMenu(Handle_SwitchImmed);
  645. case SwapTeamEvent_OnDeath:
  646. playerMenu = CreateMenu(Handle_SwitchDeath);
  647. case SwapTeamEvent_OnRoundEnd:
  648. playerMenu = CreateMenu(Handle_SwitchRend);
  649. case SwapTeamEvent_ToSpec:
  650. playerMenu = CreateMenu(Handle_SwitchSpec);
  651. }
  652.  
  653. SetMenuTitle(playerMenu, "%t", "select player");
  654. SetMenuExitButton(playerMenu, true);
  655. SetMenuExitBackButton(playerMenu, true);
  656.  
  657. // Now add players to it
  658. // I'm aware there is a function AddTargetsToMenu in the SourceMod API, but I don't
  659. // use that one because it does not display the team the clients are in.
  660. new cTeam = 0,
  661. mc = GetMaxClients();
  662.  
  663. decl String:cName[45],
  664. String:buffer[50],
  665. String:cBuffer[5];
  666.  
  667. for(new i = 1; i < mc; i++)
  668. {
  669. if(IsClientInGame(i) && (CanUserTarget(client, i)))
  670. {
  671. cTeam = GetClientTeam(i);
  672. if(cTeam < 2)
  673. continue;
  674.  
  675. GetClientName(i, cName, sizeof(cName));
  676.  
  677. switch(event)
  678. {
  679. case SwapTeamEvent_Immediately,
  680. SwapTeamEvent_ToSpec:
  681. Format(buffer, sizeof(buffer),
  682. "[%s] %s",
  683. (cTeam == 2 ? teamName1 : teamName2),
  684. cName
  685. );
  686. case SwapTeamEvent_OnDeath:
  687. {
  688. Format(buffer, sizeof(buffer),
  689. "[%s] [%s] %s",
  690. (switchOnDeath[i] ? 'x' : ' '),
  691. (cTeam == 2 ? teamName1 : teamName2),
  692. cName
  693. );
  694. }
  695. case SwapTeamEvent_OnRoundEnd:
  696. {
  697. Format(buffer, sizeof(buffer),
  698. "[%s] [%s] %s",
  699. (switchOnRoundEnd[i] ? 'x' : ' '),
  700. (cTeam == 2 ? teamName1 : teamName2),
  701. cName
  702. );
  703. }
  704. }
  705.  
  706. IntToString(i, cBuffer, sizeof(cBuffer));
  707.  
  708. AddMenuItem(playerMenu, cBuffer, buffer);
  709. }
  710. }
  711.  
  712. // ????????? ???? ??? ????? ???????
  713. if(item == 0)
  714. DisplayMenu(playerMenu, client, 30);
  715. else DisplayMenuAtItem(playerMenu, client, item-1, 30);
  716. }
  717.  
  718. public Handle_SwitchImmed(Handle:playerMenu, MenuAction:action, client, target)
  719. {
  720. Handle_Switch(SwapTeamEvent_Immediately, playerMenu, action, client, target);
  721. }
  722.  
  723. public Handle_SwitchDeath(Handle:playerMenu, MenuAction:action, client, target)
  724. {
  725. Handle_Switch(SwapTeamEvent_OnDeath, playerMenu, action, client, target);
  726. }
  727.  
  728. public Handle_SwitchRend(Handle:playerMenu, MenuAction:action, client, target)
  729. {
  730. Handle_Switch(SwapTeamEvent_OnRoundEnd, playerMenu, action, client, target);
  731. }
  732.  
  733. public Handle_SwitchSpec(Handle:playerMenu, MenuAction:action, client, target)
  734. {
  735. Handle_Switch(SwapTeamEvent_ToSpec, playerMenu, action, client, target);
  736. }
  737.  
  738. void:Handle_Switch(TeamSwitchEvent:event, Handle:playerMenu, MenuAction:action, client, param)
  739. {
  740. switch(action)
  741. {
  742. case MenuAction_Select:
  743. {
  744. decl String:info[5];
  745. GetMenuItem(playerMenu, param, info, sizeof(info));
  746. new target = StringToInt(info);
  747.  
  748. switch(event)
  749. {
  750. case SwapTeamEvent_Immediately:
  751. {
  752. PerformSwitch(target);
  753. decl String:name[50];
  754. GetClientName(target, name, sizeof(name));
  755. ShowActivity(client, "%t", "switch by admin2", name);
  756. }
  757. case SwapTeamEvent_OnDeath:
  758. {
  759. // If alive: player must be listed in OnDeath array
  760. if(IsPlayerAlive(target))
  761. {
  762. // If alive, toggle status
  763. switchOnDeath[target] = !switchOnDeath[target];
  764. }
  765. else // Switch right away
  766. PerformSwitch(target);
  767. if(switchOnDeath[target])
  768. {
  769. decl String:name[50];
  770. GetClientName(target, name, sizeof(name));
  771. ShowActivity(client, "%t", "swap death2", name);
  772. LogAction(client, target, "\"%L\" requested to change client team on death \"%L\"", client, target);
  773. }
  774. else
  775. {
  776. decl String:name[50];
  777. GetClientName(target, name, sizeof(name));
  778. ShowActivity(client, "%t", "dont swap death2", name);
  779. LogAction(client, target, "\"%L\" removed the request to change client team on death \"%L\"", client, target);
  780. }
  781. }
  782. case SwapTeamEvent_OnRoundEnd:
  783. {
  784. // Toggle status
  785. switchOnRoundEnd[target] = !switchOnRoundEnd[target];
  786. LogAction(client, target, "\"%L\" executed sm_swapteam_d on \"%L\"", client, target);
  787.  
  788. if(switchOnRoundEnd[target])
  789. {
  790. decl String:name[50];
  791. GetClientName(target, name, sizeof(name));
  792. ShowActivity(client, "%t", "swap rend2", name);
  793. LogAction(client, target, "\"%L\" requested to change client team on round end \"%L\"", client, target);
  794. }
  795. else
  796. {
  797. decl String:name[50];
  798. GetClientName(target, name, sizeof(name));
  799. ShowActivity(client, "%t", "dont swap rend2", name);
  800. LogAction(client, target, "\"%L\" removed the request to change client team on round end \"%L\"", client, target);
  801. }
  802. }
  803. case SwapTeamEvent_ToSpec:
  804. {
  805. PerformSwitchToSpec(client, target);
  806. PerformSwitch(target);
  807. decl String:name[50];
  808. GetClientName(target, name, sizeof(name));
  809. ShowActivity(client, "%t", "moved to spec2", name);
  810. }
  811. }
  812. // Now display the menu again
  813. ShowPlayerSelectionMenu(client, event, target);
  814. }
  815.  
  816. case MenuAction_Cancel:
  817. // param gives us the reason why the menu was cancelled
  818. if(param == MenuCancel_ExitBack)
  819. RedisplayAdminMenu(hAdminMenu, client);
  820.  
  821. case MenuAction_End:
  822. CloseHandle(playerMenu);
  823. }
  824. }
  825.  
  826.  
  827. void:PerformTimedSwitch(client)
  828. {
  829. CreateTimer(0.5, Timer_TeamSwitch, client);
  830. }
  831.  
  832. public Action:Timer_TeamSwitch(Handle:timer, any:client)
  833. {
  834. if (IsClientInGame(client))
  835. PerformSwitch(client);
  836. return Plugin_Stop;
  837. }
  838.  
  839. void:PerformSwitch(client, bool:toSpec = false)
  840. {
  841. new cTeam = GetClientTeam(client),
  842. toTeam = (toSpec ? TEAM_SPEC : TEAM_1 + TEAM_2 - cTeam);
  843.  
  844. if (cstrikeExtAvail && !toSpec)
  845. {
  846. CS_SwitchTeam(client, toTeam);
  847.  
  848. if (CSS)
  849. {
  850. if (cTeam == TEAM_2)
  851. {
  852. SetEntityModel(client, "models/player/t_leet.mdl");
  853. }
  854. else
  855. {
  856. SetEntityModel(client, "models/player/ct_sas.mdl");
  857. }
  858. }
  859.  
  860. if (CSGO)
  861. {
  862. if (cTeam == TEAM_2)
  863. {
  864. SetEntityModel(client, "models/player/tm_leet_varianta.mdl");
  865. }
  866. else
  867. {
  868. SetEntityModel(client, "models/player/ctm_sas.mdl");
  869. }
  870. }
  871.  
  872. if (GetPlayerWeaponSlot(client, CS_SLOT_C4) != -1)
  873. {
  874. new ent;
  875. if ((ent = GetPlayerWeaponSlot(client, CS_SLOT_C4)) != -1)
  876. SDKHooks_DropWeapon(client, ent);
  877. }
  878. }
  879.  
  880. else
  881. ChangeClientTeam(client, toTeam);
  882. }
  883.  
  884. PerformSwitchToSpec(client, target)
  885. {
  886. LogAction(client, target, "\"%L\" moved (to spectate) \"%L\"", client, target);
  887.  
  888. if (TF2)
  889. {
  890. if (g_TF2Arena)
  891. {
  892. // Arena Spectator Fix by Rothgar
  893. SetEntProp(target, Prop_Send, "m_nNextThinkTick", -1);
  894. SetEntProp(target, Prop_Send, "m_iDesiredPlayerClass", 0);
  895. SetEntProp(target, Prop_Send, "m_bArenaSpectator", 1);
  896. }
  897. ChangeClientTeam(target, TEAM_SPEC);
  898. }
  899. else
  900. {
  901. ChangeClientTeam(target, TEAM_SPEC);
  902. }
  903. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement