Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdkhooks>
- #include <tf2>
- #include <tf2_stocks>
- #include <sdktools>
- #undef REQUIRE_PLUGIN
- #include <adminmenu>
- new Handle:h_Mode = INVALID_HANDLE;
- new Handle:h_MaxValue = INVALID_HANDLE;
- new Handle:h_MinValue = INVALID_HANDLE;
- new RoundWin = 1;
- new Adding = 1;
- new TheValue = 90;
- new bool:ShowFov[MAXPLAYERS + 1];
- new bool:sfov_check[MAXPLAYERS + 1];
- new bool:sfov_on[MAXPLAYERS + 1];
- new sfovmode;
- new Max;
- new Min;
- new Handle:hTopMenu = INVALID_HANDLE;
- public Plugin:myinfo =
- {
- name = "Strange FoV",
- author = "Benjamin",
- description = "What the fuuuuuuuuuuuuuuuuu...",
- version = "1.1",
- url = "http://steamcommunity.com/id/BenjaminHT/"
- }
- public OnPluginStart()
- {
- RegAdminCmd("sm_sfov_reload", Command_reload, ADMFLAG_GENERIC);
- h_Mode = CreateConVar("sm_sfov_mode", "1", "Max FoV.", FCVAR_PLUGIN, true, 1.0, true, 2.0);
- h_MaxValue = CreateConVar("sm_sfov_max", "170", "Max FoV.", FCVAR_PLUGIN, true, 90.0, true, 180.0);
- h_MinValue = CreateConVar("sm_sfov_min", "20", "Min FoV.", FCVAR_PLUGIN, true, 0.0, true, 90.0);
- LoadTranslations("common.phrases");
- LoadTranslations("sFoV_player.phrases");
- RegAdminCmd("sm_fov", CmdFovStrange, ADMFLAG_SLAY);
- HookEvent("teamplay_round_win", Event_teamplay_round_win);
- HookEvent("arena_round_start", Event_teamplay_round_start);
- AddCommandListener(attack2CallBack, "-attack2");
- for(new i = 1; i <= MaxClients; i++)
- {
- ShowFov[i] = false;
- }
- for(new i = 1; i <= MaxClients; i++)
- {
- sfov_on[i] = false;
- }
- for(new i = 1; i <= MaxClients; i++)
- {
- sfov_check[i] = false;
- }
- new Handle:topmenu;
- if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
- {
- OnAdminMenuReady(topmenu);
- }
- }
- public OnMapStart()
- {
- sfovmode = GetConVarInt(h_Mode);
- Max = GetConVarInt(h_MaxValue);
- Min = GetConVarInt(h_MinValue);
- }
- public OnMapEnd()
- {
- for(new i = 1; i <= MaxClients; i++)
- {
- ShowFov[i] = false;
- }
- for(new i = 1; i <= MaxClients; i++)
- {
- sfov_on[i] = false;
- }
- }
- public Action:Event_teamplay_round_win(Handle:event, const String:name[], bool:dontBroadcast)
- {
- for (new i = 1; i < MaxClients; i++)
- {
- ShowFov[i] = false;
- }
- RoundWin = 2;
- }
- public Action:Event_teamplay_round_start(Handle:event, const String:name[], bool:dontBroadcast)
- {
- RoundWin = 1;
- }
- public OnClientDisconnect(client)
- {
- ShowFov[client] = false;
- }
- public Action:CmdFovStrange(client, args) {
- if(RoundWin == 1)
- {
- if(args != 0 && args != 1 && args != 2) {
- ReplyToCommand(client, "[SM] Usage: sm_fov <target> [1/0]");
- return Plugin_Handled;
- }
- if(args == 0) {
- if(ShowFov[client]) {
- ShowFov[client] = false;
- } else {
- ShowFov[client] = true;
- }
- ShowActivity2(client, "[SM] ", "Toggled StrangeFoV on self.");
- LogAction(client, client, "%L toggled StrangeFoV on themself", client);
- return Plugin_Handled;
- }
- if(!CheckCommandAccess(client, "StrangeFoVOther", ADMFLAG_GENERIC)) {
- ReplyToCommand(client, "[SM] Usage: sm_fov");
- return Plugin_Handled;
- }
- if(args == 1) {
- decl String:target_name[MAX_NAME_LENGTH];
- new target_list[MAXPLAYERS];
- new target_count;
- new bool:tn_is_ml;
- decl String:arg1[MAX_NAME_LENGTH];
- GetCmdArg(1, arg1, sizeof(arg1));
- if((target_count = ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_NO_BOTS, target_name, sizeof(target_name), tn_is_ml)) <= 0) {
- ReplyToTargetError(client, target_count);
- return Plugin_Handled;
- }
- for(new i = 0; i < target_count; i++) {
- if(ShowFov[target_list[i]]) {
- ShowFov[target_list[i]] = false;
- } else {
- ShowFov[target_list[i]] = true;
- }
- LogAction(client, target_list[i], "%L toggled StrangeFoV on %L", client, target_list[i]);
- }
- ShowActivity2(client, "[SM] ", "Toggled StrangeFoV on %s.", target_name);
- return Plugin_Handled;
- }
- if(args == 2) {
- decl String:target_name[MAX_NAME_LENGTH];
- new target_list[MAXPLAYERS];
- new target_count;
- new bool:tn_is_ml;
- decl String:arg1[MAX_NAME_LENGTH], String:arg2[4];
- GetCmdArg(1, arg1, sizeof(arg1));
- GetCmdArg(2, arg2, sizeof(arg2));
- new iState = StringToInt(arg2);
- if(iState != 0 && iState != 1) {
- ReplyToCommand(client, "[SM] Usage: sm_fov <target> [1/0]");
- return Plugin_Handled;
- }
- new bool:bState = false;
- if(iState == 1) {
- bState = true;
- }
- decl String:sState[8];
- if(bState) {
- strcopy(sState, sizeof(sState), "on");
- } else {
- strcopy(sState, sizeof(sState), "off");
- }
- if((target_count = ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_NO_BOTS, target_name, sizeof(target_name), tn_is_ml)) <= 0) {
- ReplyToTargetError(client, target_count);
- return Plugin_Handled;
- }
- for(new i = 0; i < target_count; i++) {
- ShowFov[target_list[i]] = bState;
- LogAction(client, target_list[i], "%L set StrangeFoV on %L %s", client, target_list[i], sState);
- }
- ShowActivity2(client, "[SM] ", "Set StrangeFoV on %s %s", target_name, sState);
- return Plugin_Handled;
- }
- ReplyToCommand(client, "[SM] An unknown error occurred.");
- }
- return Plugin_Handled;
- }
- public Action:Command_reload(client, args)
- {
- sfovmode = GetConVarInt(h_Mode);
- Max = GetConVarInt(h_MaxValue);
- Min = GetConVarInt(h_MinValue);
- ReplyToCommand(client, "[SM] Reloaded sFoV successfully")
- }
- public OnClientPutInServer(client)
- {
- SDKHook(client, SDKHook_PostThink, OnPostThink);
- }
- public OnGameFrame()
- {
- if(sfovmode == 1)
- {
- if(TheValue > Max)
- {
- Adding = -1;
- }
- if(TheValue < Min)
- {
- Adding = 1;
- }
- TheValue += Adding;
- }
- if(sfovmode == 2)
- {
- Adding = 1;
- if(TheValue > 180)
- {
- TheValue = 0;
- }
- TheValue += Adding;
- }
- }
- /*public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
- {
- if (buttons & IN_ATTACK2 && sfov_check[client] == false)
- {
- sfov_on[client] = true;
- }
- }*/
- public Action:attack2CallBack(client, const String:command[], argc)
- {
- sfov_check[client] = !sfov_check[client];
- if(GetEntProp(client, Prop_Send, "m_iFOV") == 90 && sfov_check[client] == false)
- {
- sfov_on[client] = false;
- }
- else
- {
- sfov_on[client] = true;
- }
- if(GetEntProp(client, Prop_Send, "m_iFOV") == 90 && sfov_check[client] == true)
- {
- sfov_check[client] = !sfov_check[client];
- }
- }
- public OnPostThink(client)
- {
- if(IsClientInGame(client) && IsPlayerAlive(client) && sfov_on[client] == false)
- {
- if(ShowFov[client])
- {
- SetEntProp(client, Prop_Send, "m_iFOV", TheValue);
- }
- else
- {
- SetEntProp(client, Prop_Send, "m_iFOV", 90);
- }
- }
- if(IsClientInGame(client) && !IsPlayerAlive(client))
- {
- if(ShowFov[client])
- {
- ShowFov[client] = !ShowFov[client];
- PrintToChat(client, "");
- SetEntProp(client, Prop_Send, "m_iFOV", 90);
- }
- }
- }
- public OnAdminMenuReady(Handle:topmenu)
- {
- /* Block us from being called twice */
- if (topmenu == hTopMenu)
- {
- return;
- }
- /* Save the Handle */
- hTopMenu = topmenu;
- /* Build the "Player Commands" category */
- new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
- if (player_commands != INVALID_TOPMENUOBJECT)
- {
- AddToTopMenu(hTopMenu,
- "sm_fov",
- TopMenuObject_Item,
- AdminMenu_FoV,
- player_commands,
- "sm_fov",
- ADMFLAG_SLAY);
- }
- }
- PerformFoV(client, target)
- {
- if(ShowFov[target] == true)
- {
- LogAction(client, target, "\"%L\" set a Strange Field of View on \"%L\"", client, target);
- ShowFov[target] = false;
- }
- else
- {
- ShowFov[target] = true;
- LogAction(client, target, "\"%L\" removed the Strange Field of View from \"%L\"", client, target);
- }
- }
- public OnLibraryRemoved(const String:name[])
- {
- if (strcmp(name, "adminmenu") == 0)
- {
- hTopMenu = INVALID_HANDLE;
- }
- }
- public AdminMenu_FoV(Handle:topmenu,
- TopMenuAction:action,
- TopMenuObject:object_id,
- param,
- String:buffer[],
- maxlength)
- {
- if (action == TopMenuAction_DisplayOption)
- {
- Format(buffer, maxlength, "%T", "sFoV player", param);
- }
- else if (action == TopMenuAction_SelectOption)
- {
- DisplayFoVMenu(param);
- }
- }
- DisplayFoVMenu(client)
- {
- new Handle:menu = CreateMenu(MenuHandler_FoV);
- decl String:title[100];
- Format(title, sizeof(title), "%T:", "sFoV player", client);
- SetMenuTitle(menu, title);
- SetMenuExitBackButton(menu, true);
- AddTargetsToMenu(menu, client, true, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- public MenuHandler_FoV(Handle:menu, MenuAction:action, param1, param2)
- {
- if (action == MenuAction_End)
- {
- CloseHandle(menu);
- }
- else if (action == MenuAction_Cancel)
- {
- if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
- {
- DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
- }
- }
- else if (action == MenuAction_Select)
- {
- decl String:info[32];
- new userid, target;
- GetMenuItem(menu, param2, info, sizeof(info));
- userid = StringToInt(info);
- if ((target = GetClientOfUserId(userid)) == 0)
- {
- PrintToChat(param1, "[SM] %t", "Player no longer available");
- }
- else if (!CanUserTarget(param1, target))
- {
- PrintToChat(param1, "[SM] %t", "Unable to target");
- }
- else
- {
- new String:name[32];
- GetClientName(target, name, sizeof(name));
- PerformFoV(param1, target);
- ShowActivity2(param1, "[SM] ", "%t", "Toggled Strange Field of View on target", "_s", name);
- }
- /* Re-draw the menu if they're still valid */
- if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
- {
- DisplayFoVMenu(param1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment