thetwistedpanda

Untitled

Sep 13th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 18.91 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. #define REQUIRE_PLUGIN
  10.  
  11. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  12. //Defines
  13. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  14. //- The default Field of Vision to apply to clients.
  15. #define cDefaultVision 90
  16.  
  17. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  18. //Handles
  19. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  20. new Handle:h_Mode = INVALID_HANDLE;             //ConVar for fov order.
  21. new Handle:h_MaxValue = INVALID_HANDLE;         //ConVar for max fov.
  22. new Handle:h_MinValue = INVALID_HANDLE;         //ConVar for min fov.
  23. new Handle:hTopMenu = INVALID_HANDLE;           //AdminMenu
  24.  
  25. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  26. //Variables
  27. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  28. new g_bEnding;                                  //Stores the state of round end.
  29. new g_bLateLoad;                                //Stores the state of load.
  30.  
  31. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  32. //Clients
  33. //* * * * * * * * * * * * * * * * * * * * * * * * * *
  34. new g_iCurrentVision[MAXPLAYERS + 1] = { cDefaultVision, ... };         //Stores current FoV.
  35. new bool:g_bActiveVision[MAXPLAYERS + 1];       //Stores whether FoV is modified.
  36. new bool:g_bForcedVision[MAXPLAYERS + 1];       //Stores whether FoV is active from admin.
  37. new bool:g_bZoomVision[MAXPLAYERS + 1];         //
  38.  
  39. public Plugin:myinfo =
  40. {
  41.     name = "Strange FoV",
  42.     author = "Benjamin",
  43.     description = "What the fuuuuuuuuuuuuuuuuu...",
  44.     version = "1.1",
  45.     url = "http://steamcommunity.com/id/BenjaminHT/"
  46. }
  47.  
  48. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
  49. {
  50.     g_bLateLoad = late;
  51.     return APLRes_Success;
  52. }
  53.  
  54. public OnPluginStart()
  55. {
  56.     LoadTranslations("common.phrases");
  57.     //LoadTranslations("sFoV_player.phrases");
  58.  
  59.     h_Mode = CreateConVar("sm_sfov_mode", "1", "Max FoV.", FCVAR_PLUGIN, true, 1.0, true, 2.0);
  60.     h_MaxValue = CreateConVar("sm_sfov_max", "170", "Max FoV.", FCVAR_PLUGIN, true, 90.0, true, 180.0);
  61.     h_MinValue = CreateConVar("sm_sfov_min", "20", "Min FoV.", FCVAR_PLUGIN, true, 0.0, true, 90.0);
  62.  
  63.     RegAdminCmd("sm_fov", Command_Vision, ADMFLAG_SLAY);
  64.  
  65.     AddCommandListener(attack2CallBack, "-attack2");
  66.  
  67.     //Client Events
  68.     HookEvent("player_spawn", Event_OnPlayerSpawn);
  69.     HookEvent("player_death", Event_OnPlayerDeath);
  70.     HookEvent("player_team", Event_OnPlayerTeam);
  71.    
  72.     //Round Events
  73.     HookEvent("teamplay_round_start", Event_OnRoundStart);
  74.     HookEvent("teamplay_round_win", Event_OnRoundEnd);
  75.     HookEvent("arena_round_start", Event_OnRoundStart);
  76.     HookEvent("arena_win_panel", Event_OnRoundEnd);
  77.  
  78.     new Handle:topmenu;
  79.     if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  80.     {
  81.         OnAdminMenuReady(topmenu);
  82.     }
  83. }
  84.  
  85. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  86. //* Fires when the plugin is unloaded.
  87. public OnPluginEnd()
  88. {
  89.     for(new i = 1; i <= MaxClients; i++)
  90.     {
  91.         if(!IsClientInGame(i) || IsFakeClient(i))
  92.             continue;
  93.        
  94.         //Disable the vision effect for anyone that has it enabled.
  95.         if(g_bActiveVision[i])
  96.         {
  97.             SetClientVision(i, 0);
  98.         }
  99.     }
  100. }
  101.  
  102. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  103. //* Fires after OnMapStart when all configs are executed.
  104. public OnConfigsExecuted()
  105. {
  106.     if(g_bLateLoad)
  107.     {
  108.         //Loop through valid clients, hook them.
  109.         for(new i = 1; i <= MaxClients; i++)
  110.         {
  111.             if(!IsClientInGame(i) || IsFakeClient(i))
  112.                 continue;
  113.                
  114.             SDKHook(i, SDKHook_PostThink, OnPostThink);
  115.         }
  116.  
  117.         g_bLateLoad = false;
  118.     }
  119. }
  120.  
  121. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  122. //* Fires at the start of a new map, or after the plugin has been loaded.
  123. public OnMapStart()
  124. {
  125.     //Set the end of the round to False.
  126.     g_bEnding = false;
  127. }
  128.  
  129. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  130. //* Fires at the end of the map, after everyone has disconnected but before map changes.
  131. public OnMapEnd()
  132. {
  133.     //Set the end of the round to True.
  134.     g_bEnding = true;
  135. }
  136.  
  137. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  138. //* Fires when a client physically disconnects or when the map is changing.
  139. public OnClientDisconnect(client)
  140. {
  141.     //Ignore if it wasn't a valid client (rare).
  142.     if(!IsClientInGame(client))
  143.         return;
  144.  
  145.     //Reset data back to defaults for next client.
  146.     g_bActiveVision[client] = false;
  147.     g_bForcedVision[client] = false;
  148. }
  149.  
  150. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  151. //* Fires when a client is officially in-game and is a valid target.
  152. public OnClientPutInServer(client)
  153. {
  154.     //Ignore if it wasn't a valid client (rare).
  155.     if(!IsClientInGame(client))
  156.         return;
  157.  
  158.     g_iCurrentVision[client] = cDefaultVision;
  159.     SDKHook(client, SDKHook_PostThink, OnPostThink);
  160. }
  161.  
  162. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  163. //* SDKHook_PostThink CallBack
  164. public OnPostThink(client)
  165. {
  166.     //Ignore if ending, their vision is disabled, they're in the process of disconnecting, or dying.
  167.     if(g_bEnding || !g_bActiveVision[client] || !IsClientInGame(client) || !IsPlayerAlive(client))
  168.         return;
  169.  
  170.     //If they're zooming, ignore.
  171.     if(TF2_IsPlayerInCondition(client, TFCond_Zoomed))
  172.         return;
  173.        
  174.     //If their current vision is negative, don't use that value!
  175.     new iVision = g_iCurrentVision[client];
  176.     if(iVision < 0)
  177.     {
  178.         iVision *= -1;
  179.     }
  180.  
  181.     //Apply the FoV.
  182.     SetEntProp(client, Prop_Send, "m_iFOV", iVision);
  183.  
  184.     //Determine FoV order
  185.     switch(GetConVarInt(h_Mode))
  186.     {
  187.         case 1:
  188.         {
  189.             //If the client is at the upper bounds, reverse.
  190.             if(iVision >= GetConVarInt(h_MaxValue))
  191.             {
  192.                 //If their vision is 170, set it to -170 so that it counts down.
  193.                 g_iCurrentVision[client] *= -1;
  194.             }
  195.  
  196.             //If the client is at the lower bounds, reverse.
  197.             if(iVision <= GetConVarInt(h_MinValue))
  198.             {
  199.                 //If their vision is -20, set it to 20 so that it counts up
  200.                 g_iCurrentVision[client] *= -1;
  201.             }
  202.         }
  203.         case 2:
  204.         {
  205.             if(g_iCurrentVision[client] >= GetConVarInt(h_MaxValue))
  206.             {
  207.                 g_iCurrentVision[client] = GetConVarInt(h_MinValue);
  208.             }
  209.         }
  210.     }
  211.  
  212.     //Increment their current FoV by one every frame.
  213.     g_iCurrentVision[client] += 1;
  214. }
  215.  
  216. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  217. //* Fires at the end of Team Play or Arena. (Can't Confirm)
  218. public Action:Event_OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  219. {
  220.     //Set the end of the round to True.
  221.     g_bEnding = true;
  222.  
  223.     //Loop through all active players in-game.
  224.     for (new i = 1; i < MaxClients; i++)
  225.     {
  226.         if(!IsClientInGame(i) || IsFakeClient(i))
  227.             continue;
  228.  
  229.         //Disable any active effects, reset their vision.
  230.         if(g_bActiveVision[i])
  231.         {
  232.             SetClientVision(i, 0);
  233.         }
  234.     }
  235. }
  236.  
  237. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  238. //* Fires at the start of Team Play or Arena. (Can't Confirm)
  239. public Action:Event_OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  240. {
  241.     //Set the end of the round to false.
  242.     g_bEnding = false;
  243. }
  244.  
  245. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  246. //* Fires on connection as well as every time a player spawns.
  247. public Action:Event_OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
  248. {
  249.     //Get the client from the event.
  250.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  251.     if(!client || !IsClientInGame(client))
  252.     {
  253.         return Plugin_Continue;
  254.     }
  255.  
  256.     //Ignore any spawning attempts while the player is not alive (i.e. connecting)
  257.     if(!IsPlayerAlive(client))
  258.     {
  259.         return Plugin_Continue;
  260.     }
  261.  
  262.     //Re-apply the FoV effect if the client has had their state enabled.
  263.     if(g_bForcedVision[client])
  264.     {
  265.         SetClientVision(client, g_iCurrentVision[client]);
  266.     }
  267.  
  268.     return Plugin_Continue;
  269. }
  270.  
  271. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  272. //* Fires whenever a player dies in-game.
  273. public Action:Event_OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  274. {
  275.     //Get the client from the event.
  276.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  277.     if(!client || !IsClientInGame(client))
  278.     {
  279.         return Plugin_Continue;
  280.     }
  281.  
  282.     //Reset the client's FoV if they had an active effect & disable it.
  283.     if(g_bActiveVision[client])
  284.     {
  285.         SetClientVision(client, 0);
  286.     }
  287.  
  288.     return Plugin_Continue;
  289. }
  290.  
  291. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  292. //* Fires whenever a player changes their team.
  293. public Action:Event_OnPlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
  294. {
  295.     //Get the client from the event.
  296.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  297.     if(!client || !IsClientInGame(client))
  298.     {
  299.         return Plugin_Continue;
  300.     }
  301.  
  302.     //Reset the client's FoV if they join Spectate.
  303.     if(GetEventInt(event, "team") == _:TFTeam_Spectator)
  304.     {
  305.         SetClientVision(client, 0);
  306.     }
  307.     //Re-apply the FoV effect on team change just to be safe.
  308.     else if(g_bForcedVision[client])
  309.     {
  310.         SetClientVision(client, g_iCurrentVision[client]);
  311.     }
  312.  
  313.     return Plugin_Continue;
  314. }
  315.  
  316. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  317. //* Simple stock for modifying the client's FoV.
  318. stock SetClientVision(client, range)
  319. {
  320.     if(range == 0)
  321.     {
  322.         g_bActiveVision[client] = false;
  323.         if(!TF2_IsPlayerInCondition(client, TFCond_Zoomed))
  324.             SetEntProp(client, Prop_Send, "m_iFOV", cDefaultVision);
  325.     }
  326.     else
  327.     {
  328.         g_bActiveVision[client] = true;
  329.         if(!TF2_IsPlayerInCondition(client, TFCond_Zoomed))
  330.             SetEntProp(client, Prop_Send, "m_iFOV", range);
  331.     }
  332. }
  333.  
  334. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  335. //* CallBack for the vision command.
  336. public Action:Command_Vision(client, args)
  337. {
  338.     //Ignore the command if it's used during the end of the round.
  339.     if(g_bEnding)
  340.     {
  341.         ReplyToCommand(client, "[SM] This command can only be used during the round!");
  342.         return Plugin_Handled;
  343.     }
  344.  
  345.     if(!args)
  346.     {
  347.         //Console has no reason to toggle effects, nor do invalid clients.
  348.         if(!client || GetClientTeam(client) <= _:TFTeam_Spectator || !IsPlayerAlive(client))
  349.         {
  350.             ReplyToCommand(client, "[SM] This command cannot be toggled on invalid clients!");
  351.             return Plugin_Handled;
  352.         }
  353.  
  354.         //Check to see if the client has self-access.
  355.         if(client && !CheckCommandAccess(client, "StrangeFoVSelf", ADMFLAG_GENERIC))
  356.         {
  357.             ReplyToCommand(client, "[SM] Usage: sm_fov");
  358.             return Plugin_Handled;
  359.         }
  360.  
  361.         g_bForcedVision[client] = !g_bForcedVision[client];
  362.         ShowActivity2(client, "[SM] ", "Set his/her StrangeFoV state to %s", g_bForcedVision[client] ? "on" : "off");
  363.         LogAction(client, client, "%L set his/her StrangeFoV state to %s", client, g_bForcedVision[client] ? "on" : "off");
  364.         if(g_bForcedVision[client])
  365.             SetClientVision(client, g_iCurrentVision[client]);
  366.         else
  367.             SetClientVision(client, 0);
  368.        
  369.         return Plugin_Handled;
  370.     }
  371.  
  372.     if(args)
  373.     {
  374.         //Notify on the event of invalid.
  375.         if(args > 2)
  376.         {
  377.             ReplyToCommand(client, "[SM] This command cannot be toggled on invalid clients!");
  378.             return Plugin_Handled;
  379.         }
  380.  
  381.         //Check to see if the client has other-access.
  382.         if(client && !CheckCommandAccess(client, "StrangeFoVOther", ADMFLAG_GENERIC))
  383.         {
  384.             ReplyToCommand(client, "[SM] Usage: sm_fov <target> [optional: 0|1]");
  385.             return Plugin_Handled;
  386.         }
  387.  
  388.         //Declare necessary information to process command; grab argument string.
  389.         decl iBreak, String:sText[192], String:sPattern[64], String:sBuffer[64];
  390.         new iTargets[MAXPLAYERS + 1], bool:bTemp, bool:bState;
  391.         GetCmdArgString(sText, sizeof(sText));
  392.  
  393.         //Store pattern, check to see if there's an additional argument.
  394.         iBreak = BreakString(sText, sPattern, sizeof(sPattern));
  395.         if(iBreak != -1)
  396.         {
  397.             iBreak += BreakString(sText[iBreak], sBuffer, sizeof(sBuffer));
  398.             bState = bool:StringToInt(sBuffer);
  399.         }
  400.  
  401.         //Only let the command target non-bots currently in-game.
  402.         new iCount = ProcessTargetString(sPattern, client, iTargets, sizeof(iTargets), COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED, sBuffer, sizeof(sBuffer), bTemp);
  403.         if(iCount)
  404.         {
  405.             //Loop through all clients currently in-game.
  406.             for (new i = 0; i < iCount; i++)
  407.             {
  408.                 if(!IsClientInGame(iTargets[i]))
  409.                 {
  410.                     continue;
  411.                 }
  412.  
  413.                 //BreakString returns -1 if there was no string to break, thus 1 parameter.
  414.                 if(iBreak == -1)
  415.                 {
  416.                     //No parameters, so toggle the client's current state.
  417.                     if(g_bForcedVision[iTargets[i]])
  418.                     {
  419.                         SetClientVision(iTargets[i], 0);
  420.                     }
  421.                     else
  422.                     {
  423.                         SetClientVision(iTargets[i], g_iCurrentVision[iTargets[i]]);
  424.                     }
  425.  
  426.                     g_bForcedVision[iTargets[i]] = !g_bForcedVision[iTargets[i]];
  427.                     LogAction(client, iTargets[i], "%L set StrangeFoV on %L to %s", client, iTargets[i], g_bForcedVision[iTargets[i]] ? "on" : "off");
  428.                     ShowActivity2(client, "[SM] ", "Set StrangeFoV on %N to %s", iTargets[i], g_bForcedVision[iTargets[i]] ? "on" : "off");
  429.                 }
  430.                 else
  431.                 {
  432.                     //Second argument was specified, force whatever values are desired.
  433.                     if(bState)
  434.                     {
  435.                         //It's being enabled, ignore anyone that already has it.
  436.                         if(g_bForcedVision[iTargets[i]])
  437.                         {
  438.                             if(!g_bActiveVision[iTargets[i]])
  439.                                 SetClientVision(iTargets[i], g_iCurrentVision[iTargets[i]]);
  440.                        
  441.                             continue;
  442.                         }
  443.  
  444.                         g_bForcedVision[iTargets[i]] = true;
  445.                         SetClientVision(iTargets[i], g_iCurrentVision[iTargets[i]]);
  446.                         LogAction(client, iTargets[i], "%L set StrangeFoV on %L to %s", client, iTargets[i], g_bForcedVision[iTargets[i]] ? "on" : "off");
  447.                         ShowActivity2(client, "[SM] ", "Set StrangeFoV on %N to %s", iTargets[i], g_bForcedVision[iTargets[i]] ? "on" : "off");
  448.                     }
  449.                     else
  450.                     {
  451.                         //It's being disabled, ignore anyone that already doesn't have it.
  452.                         if(!g_bForcedVision[iTargets[i]])
  453.                         {
  454.                             if(g_bActiveVision[iTargets[i]])
  455.                                 SetClientVision(iTargets[i], 0);
  456.                        
  457.                             continue;
  458.                         }
  459.  
  460.                         g_bForcedVision[iTargets[i]] = false;
  461.                         SetClientVision(iTargets[i], 0);
  462.                         LogAction(client, iTargets[i], "%L set StrangeFoV on %L to %s", client, iTargets[i], g_bForcedVision[iTargets[i]] ? "on" : "off");
  463.                         ShowActivity2(client, "[SM] ", "Set StrangeFoV on %N to %s", iTargets[i], g_bForcedVision[iTargets[i]] ? "on" : "off");
  464.                     }
  465.                 }
  466.             }
  467.         }
  468.     }
  469.  
  470.     return Plugin_Handled;
  471. }
  472.  
  473. public Action:attack2CallBack(client, const String:command[], argc)
  474. {
  475.     g_bForcedVision[client] = !g_bForcedVision[client];
  476.     if(GetEntProp(client, Prop_Send, "m_iFOV") == 90 && g_bForcedVision[client] == false)
  477.     {
  478.         g_bZoomVision[client] = false;
  479.     }
  480.     else
  481.     {
  482.         g_bZoomVision[client] = true;
  483.     }
  484.     if(GetEntProp(client, Prop_Send, "m_iFOV") == 90 && g_bForcedVision[client] == true)
  485.     {
  486.         g_bForcedVision[client] = !g_bForcedVision[client];
  487.     }
  488. }
  489.  
  490. public OnAdminMenuReady(Handle:topmenu)
  491. {
  492.     /* Block us from being called twice */
  493.     if (topmenu == hTopMenu)
  494.     {
  495.         return;
  496.     }
  497.  
  498.     /* Save the Handle */
  499.     hTopMenu = topmenu;
  500.  
  501.     /* Build the "Player Commands" category */
  502.     new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
  503.  
  504.     if (player_commands != INVALID_TOPMENUOBJECT)
  505.     {
  506.         AddToTopMenu(hTopMenu,
  507.             "sm_fov",
  508.             TopMenuObject_Item,
  509.             AdminMenu_FoV,
  510.             player_commands,
  511.             "sm_fov",
  512.             ADMFLAG_SLAY);
  513.     }
  514. }
  515.  
  516. public OnLibraryRemoved(const String:name[])
  517. {
  518.     if (strcmp(name, "adminmenu") == 0)
  519.     {
  520.         hTopMenu = INVALID_HANDLE;
  521.     }
  522. }
  523.  
  524. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  525. //* AdminMenu Callback - Only re-written cause of OCD.
  526. public AdminMenu_FoV(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
  527. {
  528.     switch(action)
  529.     {
  530.         case TopMenuAction_DisplayOption:
  531.         {
  532.             Format(buffer, maxlength, "Set Strange FoV", param);
  533.             //Format(buffer, maxlength, "%T", "sFoV player", param);
  534.         }
  535.         case TopMenuAction_SelectOption:
  536.         {
  537.             DisplayFoVMenu(param);
  538.         }
  539.     }
  540. }
  541.  
  542. DisplayFoVMenu(client)
  543. {
  544.     new Handle:hMenu = CreateMenu(MenuHandler_FoV);
  545.  
  546.     decl String:sBuffer[128], String:sDisplay[64], String:sUser[4];
  547.     Format(sBuffer, sizeof(sBuffer), "Select Player:", client);
  548.     //Format(sBuffer, sizeof(sBuffer), "%T:", "sFoV player", client);
  549.     SetMenuTitle(hMenu, sBuffer);
  550.     SetMenuExitBackButton(hMenu, true);
  551.  
  552.     //These should be translations, but for now, just graphics.
  553.     new String:sActive[] = "[*]";
  554.     new String:sDisabled[] = "[  ]";
  555.    
  556.     //Loop through all active clients. Ignore bots and players the admin can't target.
  557.     // We're making our own loop instad of using AddTargetsToMenu to display the state
  558.     //  of the effect prior to toggling.
  559.    
  560.     for(new i = 1; i <= MaxClients; i++)
  561.     {
  562.         if(!IsClientInGame(i) || IsFakeClient(i) || (client != i && !CanUserTarget(client, i)))
  563.             continue;
  564.        
  565.         //Format the string so it shows who has it enabled/disabled.
  566.         //1) [ ] Panda
  567.         //2) [*] Benja
  568.         Format(sDisplay, sizeof(sDisplay), "%s %N", g_bForcedVision[i] ? sActive : sDisabled, i);
  569.        
  570.         //Pass the userid along so it's available.
  571.         IntToString(GetClientUserId(i), sUser, sizeof(sUser));
  572.         AddMenuItem(hMenu, sUser, sDisplay);
  573.     }
  574.  
  575.     DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
  576. }
  577.  
  578. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  579. //* Menu Callback - Only re-written cause of OCD.
  580. public MenuHandler_FoV(Handle:menu, MenuAction:action, param1, param2)
  581. {
  582.     switch(action)
  583.     {
  584.         case MenuAction_End:
  585.         {
  586.             CloseHandle(menu);
  587.         }
  588.         case MenuAction_Cancel:
  589.         {
  590.             if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
  591.             {
  592.                 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
  593.             }
  594.         }
  595.         case MenuAction_Select:
  596.         {
  597.             decl String:info[32];
  598.             GetMenuItem(menu, param2, info, sizeof(info));
  599.  
  600.             new userid = StringToInt(info);
  601.             new target = GetClientOfUserId(userid);
  602.            
  603.             if(!target)
  604.             {
  605.                 PrintToChat(param1, "[SM] The player you were targeting is no longer available.");
  606.                 //PrintToChat(param1, "[SM] %t", "Player no longer available");
  607.             }
  608.             else if(!CanUserTarget(param1, target))
  609.             {
  610.                 PrintToChat(param1, "[SM] You are unable to target %N!", target);
  611.                 //PrintToChat(param1, "[SM] %t", "Unable to target");
  612.             }
  613.             else
  614.             {
  615.                 //Toggle the effect based on the current state.
  616.                 if(g_bForcedVision[target])
  617.                     SetClientVision(target, 0);
  618.                 else
  619.                     SetClientVision(target, g_iCurrentVision[target]);
  620.  
  621.                 g_bForcedVision[target] = !g_bForcedVision[target];
  622.                 LogAction(param1, target, "%L set StrangeFoV on %L to %s", param1, target, g_bForcedVision[target] ? "on" : "off");
  623.                 ShowActivity2(param1, "[SM] ", "Set StrangeFoV on %N to %s", target, g_bForcedVision[target] ? "on" : "off");
  624.             }
  625.  
  626.             //Display the menu back to the admin, if possible.
  627.             if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
  628.             {
  629.                 DisplayFoVMenu(param1);
  630.             }
  631.         }
  632.     }
  633. }
Advertisement
Add Comment
Please, Sign In to add comment