BenjaminsCodes

Untitled

Sep 13th, 2013
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdkhooks>
  3. #include <tf2>
  4. #include <tf2_stocks>
  5. #include <sdktools>
  6.  
  7. #undef REQUIRE_PLUGIN
  8. #include <adminmenu>
  9.  
  10. new Handle:h_Mode = INVALID_HANDLE;
  11. new Handle:h_MaxValue = INVALID_HANDLE;
  12. new Handle:h_MinValue = INVALID_HANDLE;
  13.  
  14. new RoundWin = 1;
  15. new Adding = 1;
  16. new TheValue = 90;
  17. new bool:ShowFov[MAXPLAYERS + 1];
  18.  
  19. new bool:sfov_check[MAXPLAYERS + 1];
  20. new bool:sfov_on[MAXPLAYERS + 1];
  21. new sfovmode;
  22. new Max;
  23. new Min;
  24.  
  25. new Handle:hTopMenu = INVALID_HANDLE;
  26.  
  27. public Plugin:myinfo =
  28. {
  29. name = "Strange FoV",
  30. author = "Benjamin",
  31. description = "What the fuuuuuuuuuuuuuuuuu...",
  32. version = "1.1",
  33. url = "http://steamcommunity.com/id/BenjaminHT/"
  34. }
  35.  
  36. public OnPluginStart()
  37. {
  38. RegAdminCmd("sm_sfov_reload", Command_reload, ADMFLAG_GENERIC);
  39. h_Mode = CreateConVar("sm_sfov_mode", "1", "Max FoV.", FCVAR_PLUGIN, true, 1.0, true, 2.0);
  40. h_MaxValue = CreateConVar("sm_sfov_max", "170", "Max FoV.", FCVAR_PLUGIN, true, 90.0, true, 180.0);
  41. h_MinValue = CreateConVar("sm_sfov_min", "20", "Min FoV.", FCVAR_PLUGIN, true, 0.0, true, 90.0);
  42. LoadTranslations("common.phrases");
  43. LoadTranslations("sFoV_player.phrases");
  44. RegAdminCmd("sm_fov", CmdFovStrange, ADMFLAG_SLAY);
  45. HookEvent("teamplay_round_win", Event_teamplay_round_win);
  46. HookEvent("arena_round_start", Event_teamplay_round_start);
  47. AddCommandListener(attack2CallBack, "-attack2");
  48.  
  49. for(new i = 1; i <= MaxClients; i++)
  50. {
  51. ShowFov[i] = false;
  52. }
  53. for(new i = 1; i <= MaxClients; i++)
  54. {
  55. sfov_on[i] = false;
  56. }
  57. for(new i = 1; i <= MaxClients; i++)
  58. {
  59. sfov_check[i] = false;
  60. }
  61.  
  62. new Handle:topmenu;
  63. if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  64. {
  65. OnAdminMenuReady(topmenu);
  66. }
  67. }
  68.  
  69. public OnMapStart()
  70. {
  71. sfovmode = GetConVarInt(h_Mode);
  72. Max = GetConVarInt(h_MaxValue);
  73. Min = GetConVarInt(h_MinValue);
  74. }
  75.  
  76. public OnMapEnd()
  77. {
  78. for(new i = 1; i <= MaxClients; i++)
  79. {
  80. ShowFov[i] = false;
  81. }
  82. for(new i = 1; i <= MaxClients; i++)
  83. {
  84. sfov_on[i] = false;
  85. }
  86. }
  87.  
  88. public Action:Event_teamplay_round_win(Handle:event, const String:name[], bool:dontBroadcast)
  89. {
  90. for (new i = 1; i < MaxClients; i++)
  91. {
  92. ShowFov[i] = false;
  93. }
  94. RoundWin = 2;
  95. }
  96.  
  97. public Action:Event_teamplay_round_start(Handle:event, const String:name[], bool:dontBroadcast)
  98. {
  99. RoundWin = 1;
  100. }
  101.  
  102. public OnClientDisconnect(client)
  103. {
  104. ShowFov[client] = false;
  105. }
  106.  
  107. public Action:CmdFovStrange(client, args) {
  108. if(RoundWin == 1)
  109. {
  110. if(args != 0 && args != 1 && args != 2) {
  111. ReplyToCommand(client, "[SM] Usage: sm_fov <target> [1/0]");
  112. return Plugin_Handled;
  113. }
  114. if(args == 0) {
  115. if(ShowFov[client]) {
  116. ShowFov[client] = false;
  117. } else {
  118. ShowFov[client] = true;
  119. }
  120. ShowActivity2(client, "[SM] ", "Toggled StrangeFoV on self.");
  121. LogAction(client, client, "%L toggled StrangeFoV on themself", client);
  122. return Plugin_Handled;
  123. }
  124. if(!CheckCommandAccess(client, "StrangeFoVOther", ADMFLAG_GENERIC)) {
  125. ReplyToCommand(client, "[SM] Usage: sm_fov");
  126. return Plugin_Handled;
  127. }
  128. if(args == 1) {
  129. decl String:target_name[MAX_NAME_LENGTH];
  130. new target_list[MAXPLAYERS];
  131. new target_count;
  132. new bool:tn_is_ml;
  133. decl String:arg1[MAX_NAME_LENGTH];
  134. GetCmdArg(1, arg1, sizeof(arg1));
  135. if((target_count = ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_NO_BOTS, target_name, sizeof(target_name), tn_is_ml)) <= 0) {
  136. ReplyToTargetError(client, target_count);
  137. return Plugin_Handled;
  138. }
  139. for(new i = 0; i < target_count; i++) {
  140. if(ShowFov[target_list[i]]) {
  141. ShowFov[target_list[i]] = false;
  142. } else {
  143. ShowFov[target_list[i]] = true;
  144. }
  145. LogAction(client, target_list[i], "%L toggled StrangeFoV on %L", client, target_list[i]);
  146. }
  147. ShowActivity2(client, "[SM] ", "Toggled StrangeFoV on %s.", target_name);
  148. return Plugin_Handled;
  149. }
  150. if(args == 2) {
  151. decl String:target_name[MAX_NAME_LENGTH];
  152. new target_list[MAXPLAYERS];
  153. new target_count;
  154. new bool:tn_is_ml;
  155. decl String:arg1[MAX_NAME_LENGTH], String:arg2[4];
  156. GetCmdArg(1, arg1, sizeof(arg1));
  157. GetCmdArg(2, arg2, sizeof(arg2));
  158. new iState = StringToInt(arg2);
  159. if(iState != 0 && iState != 1) {
  160. ReplyToCommand(client, "[SM] Usage: sm_fov <target> [1/0]");
  161. return Plugin_Handled;
  162. }
  163. new bool:bState = false;
  164. if(iState == 1) {
  165. bState = true;
  166. }
  167. decl String:sState[8];
  168. if(bState) {
  169. strcopy(sState, sizeof(sState), "on");
  170. } else {
  171. strcopy(sState, sizeof(sState), "off");
  172. }
  173. if((target_count = ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_NO_BOTS, target_name, sizeof(target_name), tn_is_ml)) <= 0) {
  174. ReplyToTargetError(client, target_count);
  175. return Plugin_Handled;
  176. }
  177. for(new i = 0; i < target_count; i++) {
  178. ShowFov[target_list[i]] = bState;
  179. LogAction(client, target_list[i], "%L set StrangeFoV on %L %s", client, target_list[i], sState);
  180. }
  181. ShowActivity2(client, "[SM] ", "Set StrangeFoV on %s %s", target_name, sState);
  182. return Plugin_Handled;
  183. }
  184. ReplyToCommand(client, "[SM] An unknown error occurred.");
  185. }
  186. return Plugin_Handled;
  187. }
  188.  
  189.  
  190.  
  191. public Action:Command_reload(client, args)
  192. {
  193. sfovmode = GetConVarInt(h_Mode);
  194. Max = GetConVarInt(h_MaxValue);
  195. Min = GetConVarInt(h_MinValue);
  196. ReplyToCommand(client, "[SM] Reloaded sFoV successfully")
  197. }
  198.  
  199. public OnClientPutInServer(client)
  200. {
  201. SDKHook(client, SDKHook_PostThink, OnPostThink);
  202. }
  203.  
  204. public OnGameFrame()
  205. {
  206. if(sfovmode == 1)
  207. {
  208. if(TheValue > Max)
  209. {
  210. Adding = -1;
  211. }
  212. if(TheValue < Min)
  213. {
  214. Adding = 1;
  215. }
  216. TheValue += Adding;
  217. }
  218. if(sfovmode == 2)
  219. {
  220. Adding = 1;
  221. if(TheValue > 180)
  222. {
  223. TheValue = 0;
  224. }
  225. TheValue += Adding;
  226. }
  227. }
  228.  
  229. /*public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  230. {
  231. if (buttons & IN_ATTACK2 && sfov_check[client] == false)
  232. {
  233. sfov_on[client] = true;
  234. }
  235. }*/
  236. public Action:attack2CallBack(client, const String:command[], argc)
  237. {
  238. sfov_check[client] = !sfov_check[client];
  239. if(GetEntProp(client, Prop_Send, "m_iFOV") == 90 && sfov_check[client] == false)
  240. {
  241. sfov_on[client] = false;
  242. }
  243. else
  244. {
  245. sfov_on[client] = true;
  246. }
  247. if(GetEntProp(client, Prop_Send, "m_iFOV") == 90 && sfov_check[client] == true)
  248. {
  249. sfov_check[client] = !sfov_check[client];
  250. }
  251. }
  252.  
  253. public OnPostThink(client)
  254. {
  255. if(IsClientInGame(client) && IsPlayerAlive(client) && sfov_on[client] == false)
  256. {
  257. if(ShowFov[client])
  258. {
  259. SetEntProp(client, Prop_Send, "m_iFOV", TheValue);
  260. }
  261. else
  262. {
  263. SetEntProp(client, Prop_Send, "m_iFOV", 90);
  264. }
  265. }
  266. if(IsClientInGame(client) && !IsPlayerAlive(client))
  267. {
  268. if(ShowFov[client])
  269. {
  270. ShowFov[client] = !ShowFov[client];
  271. PrintToChat(client, "");
  272. SetEntProp(client, Prop_Send, "m_iFOV", 90);
  273. }
  274. }
  275. }
  276.  
  277. public OnAdminMenuReady(Handle:topmenu)
  278. {
  279. /* Block us from being called twice */
  280. if (topmenu == hTopMenu)
  281. {
  282. return;
  283. }
  284.  
  285. /* Save the Handle */
  286. hTopMenu = topmenu;
  287.  
  288. /* Build the "Player Commands" category */
  289. new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
  290.  
  291. if (player_commands != INVALID_TOPMENUOBJECT)
  292. {
  293. AddToTopMenu(hTopMenu,
  294. "sm_fov",
  295. TopMenuObject_Item,
  296. AdminMenu_FoV,
  297. player_commands,
  298. "sm_fov",
  299. ADMFLAG_SLAY);
  300. }
  301. }
  302.  
  303.  
  304. PerformFoV(client, target)
  305. {
  306. if(ShowFov[target] == true)
  307. {
  308. LogAction(client, target, "\"%L\" set a Strange Field of View on \"%L\"", client, target);
  309. ShowFov[target] = false;
  310. }
  311. else
  312. {
  313. ShowFov[target] = true;
  314. LogAction(client, target, "\"%L\" removed the Strange Field of View from \"%L\"", client, target);
  315. }
  316. }
  317.  
  318. public OnLibraryRemoved(const String:name[])
  319. {
  320. if (strcmp(name, "adminmenu") == 0)
  321. {
  322. hTopMenu = INVALID_HANDLE;
  323. }
  324. }
  325.  
  326. public AdminMenu_FoV(Handle:topmenu,
  327. TopMenuAction:action,
  328. TopMenuObject:object_id,
  329. param,
  330. String:buffer[],
  331. maxlength)
  332. {
  333. if (action == TopMenuAction_DisplayOption)
  334. {
  335. Format(buffer, maxlength, "%T", "sFoV player", param);
  336. }
  337. else if (action == TopMenuAction_SelectOption)
  338. {
  339. DisplayFoVMenu(param);
  340. }
  341. }
  342.  
  343. DisplayFoVMenu(client)
  344. {
  345. new Handle:menu = CreateMenu(MenuHandler_FoV);
  346.  
  347. decl String:title[100];
  348. Format(title, sizeof(title), "%T:", "sFoV player", client);
  349. SetMenuTitle(menu, title);
  350. SetMenuExitBackButton(menu, true);
  351.  
  352. AddTargetsToMenu(menu, client, true, true);
  353.  
  354. DisplayMenu(menu, client, MENU_TIME_FOREVER);
  355. }
  356.  
  357. public MenuHandler_FoV(Handle:menu, MenuAction:action, param1, param2)
  358. {
  359. if (action == MenuAction_End)
  360. {
  361. CloseHandle(menu);
  362. }
  363. else if (action == MenuAction_Cancel)
  364. {
  365. if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
  366. {
  367. DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
  368. }
  369. }
  370. else if (action == MenuAction_Select)
  371. {
  372. decl String:info[32];
  373. new userid, target;
  374.  
  375. GetMenuItem(menu, param2, info, sizeof(info));
  376. userid = StringToInt(info);
  377.  
  378. if ((target = GetClientOfUserId(userid)) == 0)
  379. {
  380. PrintToChat(param1, "[SM] %t", "Player no longer available");
  381. }
  382. else if (!CanUserTarget(param1, target))
  383. {
  384. PrintToChat(param1, "[SM] %t", "Unable to target");
  385. }
  386. else
  387. {
  388. new String:name[32];
  389. GetClientName(target, name, sizeof(name));
  390.  
  391. PerformFoV(param1, target);
  392. ShowActivity2(param1, "[SM] ", "%t", "Toggled Strange Field of View on target", "_s", name);
  393. }
  394.  
  395. /* Re-draw the menu if they're still valid */
  396. if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
  397. {
  398. DisplayFoVMenu(param1);
  399. }
  400. }
  401. }
Advertisement
Add Comment
Please, Sign In to add comment