Hi again...! this script could need some improvements. Maybe?
The meaning of this script is to make the players Field of View go up constantly and down no more
Code:
/*Maybe some includes isn't necessary?*/
#include <sourcemod>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <adminmenu>
new RoundWin = 1;
new Adding = 1;
new TheValue = 90;
new bool:ShowFov[MAXPLAYERS + 1];
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()
{
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);
for (new i = 0; 1 < MaxClients + 1; i++)
{
ShowFov[i] = false;
}
new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
{
OnAdminMenuReady(topmenu);
}
}
public OnMapEnd()
{
for (new i = 0; i < MaxClients; i++)
{
ShowFov[i] = false;
}
}
public Action:Event_teamplay_round_win(Handle:event, const String:name[], bool:dontBroadcast)
{
for (new i = 0; 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 OnClientPutInServer(client)
{
SDKHook(client, SDKHook_PostThink, OnPostThink);
}
public OnGameFrame()
{
if(TheValue > 170)
{
Adding = -1;
}
if(TheValue < 20)
{
Adding = 1;
}
TheValue += Adding;
}
public OnPostThink(client)
{
if(IsClientInGame(client) && IsPlayerAlive(client))
{
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);
}
}
}