Raised This Month: $51 Target: $400
 12% 

[TF2] Help to modify the FOV


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tournevis_man
Junior Member
Join Date: Apr 2008
Old 07-12-2008 , 06:56   [TF2] Help to modify the FOV
Reply With Quote #1

Hello, I'm new in SourcePawn scripting and I request help to make a script :
I want to set a new FOV for the players.
I tried to use CBasePlayer::SetFOV from the http://forums.alliedmods.net/showthread.php?t=55565
This is my scripts who don't work

PHP Code:
public Plugin:myinfo 
{
    
name "FOV Changer",
    
author "HRG Team - Tournevis_man and Pinguinman",
    
description "Set the FOV to a player",
    
version "1.0.0",
    
url "http://www.sourcemod.net/"
};

#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#include <sigoffset>
new Handle:g_cvar INVALID_HANDLE;

public 
OnPluginStart()
{
    
g_cvar FindConVar ("fov_desired")

    
RegAdminCmd("sm_fov"SetFOVADMFLAG_CUSTOM1"sm_fov <FOV> Sets the FOV of given value. Default: 90");
}
    

public 
CBasePlayer::SetFOV(clientsargs)
{
    if (
args 1)
    {        
ReplyToCommand(client"[SM] Usage: sm_fov <fov>");
        return 
Plugin_Handled;
    }
    
decl String:arg[64];
    
GetCmdArg(1argsizeof(arg));

    
SetConVarInt(g_cvarStringToInt(arg));
    
PrintToChatAll("[SM] FOV set to: %s"arg);                    
    
LogMessage("Chat: %L FOV set to: %s"clientarg);
    return 
Plugin_Handled;

Thanks for help
Tournevis_man is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-12-2008 , 13:45   Re: [TF2] Help to modify the FOV
Reply With Quote #2

Ok, CBasePlayer::SetFov is a signature. Signature scanning is handled in sdktools.inc.

But rather than explain all that I'll show you another way to change FOV that is a lot easier.

Code:
new offsFOV;

public OnPluginStart()
{
    offsFOV = FindSendPropInfo("CBasePlayer", "m_iDefaultFOV");
    if (offsFOV == -1)
    {
        SetFailState("Couldn't find \"m_iDefaultFOV\"!");
    }
    RegAdminCmd("sm_fov", SetFOV, ADMFLAG_CUSTOM1, "sm_fov <#userid|name> <FOV> Sets the FOV of given value. Default: 90");
}

public Action:SetFOV(client, args)
{
    if (argc < 2)
    {
        ReplyToCommand(client, " sm_fov <#userid|name> <FOV> Sets the FOV of given value. Default: 90");
    
        return Plugin_Handled;
    }

    decl String:arg1[32];
    decl String:arg2[8];
    
    GetCmdArg(1, arg1, sizeof(arg1));
    GetCmdArg(2, arg2, sizeof(arg2));
    
    new fov = StringToInt(arg2);
    
    decl String:target_name[MAX_TARGET_LENGTH];
    new targets[MAXPLAYERS];
    new bool:tn_is_ml;
    
    new tcount = ProcessTargetString(arg1, client, targets, MAXPLAYERS, COMMAND_FILTER_ALIVE, target_name, sizeof(target_name), tn_is_ml);
    if (tcount <= 0)
    {
        ReplyToTargetError(client, tcount);
        return Plugin_Handled;
    }
    
    for (new x = 0; x < tcount; x++)
    {
        SetEntData(targets[x], offsFOV, fov, 1);
    }
    
    if (tn_is_ml)
    {
        ShowActivity2(client, "[SM] ", "%t", "Toggled dizziness on target", target_name);
    }
    else
    {
        ShowActivity2(client, "[SM] ", "%t", "Toggled dizziness on target", "_s", target_name);
    }

    return Plugin_Handled;
}
public Action:SetFOV is referred to as a "cmd callback." It means that I hooked the function in OnPluginStart (RegAdminCmd) and now this function is called whenever an admin uses the sm_fov command.

offsFOV is a global variable used to store the m_iDefaultFOV offset. In OnPluginLoad I used FindSendPropInfo to find the offset. (http://bailopan.net/table_dump.txt)
The FindSendPropInfo function is nested, which means that all you need is the classname and property. If you look at that page you will find

Quote:
CBasePlayer:
Sub-Class Table (1 Deep): DT_BasePlayer
Sub-Class Table (2 Deep): DT_BaseCombatCharacter
Sub-Class Table (3 Deep): DT_BaseFlex
Sub-Class Table (4 Deep): DT_BaseAnimatingOverlay
Sub-Class Table (5 Deep): DT_BaseAnimating
Sub-Class Table (6 Deep): DT_BaseEntity
Sub-Class Table (7 Deep): DT_AnimTimeMustBeFirst
-Member: m_flAnimTime (offset 40)
-Member: AnimTimeMustBeFirst (offset 0)
-Member: m_flSimulationTime (offset 44)
...
So FindSendPropInfo, being nested, will check through alll those sub-classes under CBasePlayer looking for the property you gave it. It will return -1 if it doesn't exist for that game.

Hope that helped
__________________
Greyscale is offline
Tournevis_man
Junior Member
Join Date: Apr 2008
Old 07-16-2008 , 08:39   Re: [TF2] Help to modify the FOV
Reply With Quote #3

Thanks a lot for your help
__________________
[IMG]http://img147.**************/img147/953/2398ka6.png[/IMG]
Tournevis_man is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode