Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <freak_fortress_2>
  3. #include <clientprefs.inc>
  4. #include <morecolors>
  5.  
  6. #define VERSION "1.0.1"
  7.  
  8. #define TOGGLE_UNDEF -1
  9. #define TOGGLE_ON 1
  10. #define TOGGLE_OFF 2
  11.  
  12. new Handle:g_ff2bossCookie= INVALID_HANDLE;
  13. new g_ClientCookies[MAXPLAYERS+1];
  14. new g_ClientPoints[MAXPLAYERS+1];
  15. new g_ClientIDs[MAXPLAYERS+1];
  16. new g_ClientQueue[MAXPLAYERS+1][2];
  17. new Handle:g_hCvarPreferenceQuestionDelay = INVALID_HANDLE;
  18.  
  19. public Plugin:myinfo = {
  20. name = "Freak Fortress 2: Boss Toggle",
  21. description = "Allows players to toggle being selected as a Boss",
  22. author = "frog",
  23. version = VERSION
  24. };
  25.  
  26. public OnPluginStart()
  27. {
  28. CreateConVar("ff2_boss_toggle_version", VERSION, "Freak Fortress 2: Boss Toggle Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  29. g_hCvarPreferenceQuestionDelay = CreateConVar("ff2_boss_toggle_delay", "45.0", "Delay between joining the server and asking the player for their preference, if it is not set.");
  30. AutoExecConfig(true, "plugin.ff2_boss_toggle")
  31.  
  32. g_ff2bossCookie = RegClientCookie("ff2_boss_toggle", "Players FF2 Boss Toggle", CookieAccess_Public);
  33. RegConsoleCmd("ff2toggle", BossMenu);
  34.  
  35. for(new i = 0; i < MAXPLAYERS; i++)
  36. {
  37. g_ClientCookies[i] = TOGGLE_UNDEF;
  38. }
  39.  
  40. HookEvent("arena_round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  41. HookEvent("arena_win_panel", Event_RoundEnd, EventHookMode_PostNoCopy);
  42.  
  43. LoadTranslations("ff2_boss_toggle.phrases");
  44. }
  45.  
  46. public OnClientDisconnect(client)
  47. {
  48. g_ClientCookies[client] = TOGGLE_UNDEF;
  49. }
  50.  
  51. public OnClientCookiesCached(client)
  52. {
  53. decl String:sEnabled[2];
  54. GetClientCookie(client, g_ff2bossCookie, sEnabled, sizeof(sEnabled));
  55. new enabled = StringToInt(sEnabled);
  56.  
  57. if( 1 > enabled || 2 < enabled)
  58. {
  59. g_ClientCookies[client] = TOGGLE_UNDEF;
  60. new Handle:clientPack = CreateDataPack();
  61. WritePackCell(clientPack, client);
  62. CreateTimer(GetConVarFloat(g_hCvarPreferenceQuestionDelay), BossMenuTimer, clientPack);
  63. }
  64. else
  65. {
  66. g_ClientCookies[client] = enabled;
  67. }
  68. }
  69.  
  70. public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  71. {
  72. for(new client=1;client<=MaxClients;client++)
  73. {
  74. g_ClientQueue[client][0] = client;
  75. g_ClientQueue[client][1] = FF2_GetQueuePoints(client);
  76. }
  77.  
  78. SortCustom2D(g_ClientQueue, sizeof(g_ClientQueue), SortQueueDesc);
  79.  
  80. for(new client=1;client<=MaxClients;client++)
  81. {
  82. g_ClientIDs[client] = g_ClientQueue[client][0];
  83. g_ClientPoints[client] = g_ClientQueue[client][1];
  84. }
  85.  
  86. for(new client=0;client<=MaxClients;client++)
  87. { if (client>0 && IsValidEntity(client) && IsClientConnected(client))
  88. {
  89. if (g_ClientCookies[client] == TOGGLE_ON)
  90. {
  91. new index = -1;
  92. for (new i = 1; i < MAXPLAYERS+1; i++)
  93. {
  94. if (g_ClientIDs[i] == client)
  95. {
  96. index = i;
  97. break;
  98. }
  99. }
  100. if (index > 0)
  101. {
  102. CPrintToChat(client, "{olive}[FF2]{default} %t", "toggle_enabled_points", index, g_ClientPoints[index]);
  103. } else {
  104. CPrintToChat(client, "{olive}[FF2]{default} %t", "toggle_enabled");
  105. }
  106. }
  107. else if (g_ClientCookies[client] == TOGGLE_OFF)
  108. {
  109. FF2_SetQueuePoints(client,-10);
  110. decl String:nick[64];
  111. GetClientName(client, nick, sizeof(nick));
  112. CPrintToChat(client, "{olive}[FF2]{default} %t", "toggle_disabled");
  113. }
  114. else if (g_ClientCookies[client] == TOGGLE_UNDEF || g_ClientCookies[client] == 0)
  115. {
  116. decl String:nick[64];
  117. GetClientName(client, nick, sizeof(nick));
  118. new Handle:clientPack = CreateDataPack();
  119. WritePackCell(clientPack, client);
  120. CreateTimer(GetConVarFloat(g_hCvarPreferenceQuestionDelay), BossMenuTimer, clientPack);
  121. }
  122. }
  123. }
  124. CreateTimer(5.0, CommandRemind);
  125. }
  126.  
  127. public Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  128. {
  129. for(new client=0;client<=MaxClients;client++)
  130. { if (client>0 && IsValidEntity(client) && IsClientConnected(client))
  131. {
  132. if (g_ClientCookies[client] == TOGGLE_OFF)
  133. {
  134. FF2_SetQueuePoints(client,-10);
  135. decl String:nick[64];
  136. GetClientName(client, nick, sizeof(nick));
  137. }
  138. }
  139. }
  140. }
  141.  
  142. public Action:CommandRemind(Handle:timer)
  143. {
  144. CPrintToChatAll("{olive}[FF2]{default} %t", "toggle_command");
  145. }
  146.  
  147. public Action:BossMenuTimer(Handle:timer, any:clientpack)
  148. {
  149. decl clientId;
  150. ResetPack(clientpack);
  151. clientId = ReadPackCell(clientpack);
  152. CloseHandle(clientpack);
  153. if (g_ClientCookies[clientId] == TOGGLE_UNDEF)
  154. {
  155. BossMenu(clientId, 0);
  156. }
  157. }
  158.  
  159. public Action:BossMenu(client, args)
  160. {
  161. if (IsValidClient(client))
  162. {
  163. CPrintToChat(client, "{olive}[FF2]{default} %t", "set_preference");
  164.  
  165. decl String:sEnabled[2];
  166. GetClientCookie(client, g_ff2bossCookie, sEnabled, sizeof(sEnabled));
  167. g_ClientCookies[client] = StringToInt(sEnabled);
  168.  
  169. new Handle:menu = CreateMenu(MenuHandlerBoss);
  170. SetMenuTitle(menu, "%t", "toggle_menu_title");
  171.  
  172. new String:menuoption[128];
  173. Format(menuoption,sizeof(menuoption),"%t","toggle_on_menu_option");
  174. AddMenuItem(menu, "Boss Toggle", menuoption);
  175. Format(menuoption,sizeof(menuoption),"%t","toggle_off_menu_option");
  176. AddMenuItem(menu, "Boss Toggle", menuoption);
  177.  
  178. SetMenuExitButton(menu, true);
  179.  
  180. DisplayMenu(menu, client, 20);
  181. }
  182. return Plugin_Handled;
  183. }
  184.  
  185. public MenuHandlerBoss(Handle:menu, MenuAction:action, param1, param2)
  186. {
  187. if(action == MenuAction_Select)
  188. {
  189. decl String:sEnabled[2];
  190. new choice = param2 + 1;
  191.  
  192. g_ClientCookies[param1] = choice;
  193. IntToString(choice, sEnabled, sizeof(sEnabled));
  194.  
  195. SetClientCookie(param1, g_ff2bossCookie, sEnabled);
  196.  
  197. if(1 == choice)
  198. {
  199. CPrintToChat(param1, "{olive}[FF2]{default} %t", "toggle_enabled");
  200. }
  201. else if(2 == choice)
  202. {
  203. CPrintToChat(param1, "{olive}[FF2]{default} %t", "toggle_disabled");
  204. }
  205. }
  206. else if(action == MenuAction_End)
  207. {
  208. CloseHandle(menu);
  209. }
  210. }
  211.  
  212. public SortQueueDesc(x[], y[], array[][], Handle:data)
  213. {
  214. if (x[1] > y[1])
  215. return -1;
  216. else if (x[1] < y[1])
  217. return 1;
  218. return 0;
  219. }
  220.  
  221. stock bool:IsValidClient(client)
  222. {
  223. if (client <= 0 || client > MaxClients) return false;
  224. if (!IsClientInGame(client)) return false;
  225. if (IsClientSourceTV(client) || IsClientReplay(client)) return false;
  226. return true;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement