Raised This Month: $32 Target: $400
 8% 

Help Setting A Weapons Zoom FOV


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exino
Junior Member
Join Date: Mar 2008
Old 04-18-2008 , 04:08   Help Setting A Weapons Zoom FOV
Reply With Quote #1

So what I want to do is essentially change the fov value of weapons that can zoom. I'm not even sure if this is possible since it might be entirely client side but I just thought I'd ask some of the "experts" around here.

I'm pretty sure that "zooming" with a weapon, in CSS at least, is essentially just the users fov value being lowered from the default 90, a screen overlay being added, muzzle flash sprites being disabled or set transparent, and a mouse sensitivity reduction. From what I've gathered, all the sniper rifles first zoom fov is 30, and the second 15. The aug and sg552 rifles is 55.

My coding experience is well, not much. I know a bit of programing concepts I've just never really put them to use. I know some java from a college course I've taken recently, have been messing around with eventscripts for a while now, and just recently got interrested in python but thats about it.

Anyways, I put together some rough skeleton code

Code:
/**
 * ====================
 *        Weapon Zoom
 *   Author: ----
 * ==================== 
 */

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

#define VERSION "0.1"

// Variables will go here


public Plugin:myinfo =
{
    name = "Weapon Zoom",
    author = "Gabe B",
    description = "Sets a custom Fov and Overlay on weapons that can zoom",
    version = VERSION,
    url = ""
};

public OnPluginStart()
{
    // ======================================================================
    
    HookEvent("weapon_zoom", PlayerZoom);
    
    // ======================================================================
    
    CreateConVar("gs_weaponzoom_version",VERSION,"[WeaponZoom] Current version of this plugin",FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_UNLOGGED|FCVAR_DONTRECORD|FCVAR_REPLICATED|FCVAR_NOTIFY);
}

public Action:PlayerZoom(Handle:event, const String:name[], bool:dontBroadcast)
{
    GetClientWeapon(client , String:Weapon ,MaxLength)
    
    decl String:weaponName[8];

    GetEventString(event, "weapon", weaponName, sizeof(weaponName));

    if (WeaponCheck(weaponName))
    {
        
    }
}

public WeaponCheck(String:weapon[])
{
    if(strcmp(weapon, "aug") == 0 || strcmp(weapon, "sg552") == 0 || strcmp(weapon, "scout") == 0 || strcmp(weapon, "sg550") == 0 || strcmp(weapon, "g3sg1") == 0 || strcmp(weapon, "awp") == 0)
    {
        return 1;
    }

    return 0;
}
At this point I'm sort of completely in the dark.
I'm not really sure where to go.....
Should I hook into the weapon_zoom event and change the value when its fired?

Also, theres no source for me to reference because obviously css source code has never been released so I'm not sure what value i'll be changing. Iv'e been looking at weapon_crossbow.cpp from the source sdk base though.

Any help anyone can give would be greatly appreciated.
Exino is offline
BAILOPAN
Join Date: Jan 2004
Old 04-18-2008 , 12:48   Re: Help Setting A Weapons Zoom FOV
Reply With Quote #2

Take a look at the m_iFOV and m_flFOVRate network properties of players.
__________________
egg
BAILOPAN is offline
Exino
Junior Member
Join Date: Mar 2008
Old 04-21-2008 , 16:11   Re: Help Setting A Weapons Zoom FOV
Reply With Quote #3

Thanks for the info Bail.

So in the last few days I've read up on the docs for sourcepawn and sourcemod and I think Ive got the hang of the basics in coding for it now.

I've been looking for some examples in other plugins on retrieving a weapon string name and checking that string to determine what weapon it is but I haven't quite found what I'm looking for. I think the knifesyphon plugin checks for a weapon but it just returns a true if any of the strings match and false if none of them do. I want to check for a weapon string and execute specific code depending on what string it is.

I was wondering if I could get an example from anyone willing to help.

Heres what I got right now:
Code:
public OnPluginStart()
{
    // ======================================================================
    HookEvent("weapon_zoom", PlayerZoomed);
    // ======================================================================
    
    CreateConVar("gs_weaponzoom_version",VERSION,"[WeaponZoom] Current version of this plugin",FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_UNLOGGED|FCVAR_DONTRECORD|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
    // Precache Material Overlays Here
}

public Action:PlayerZoomed(Handle:event, const String:weaponName[], bool:dontBroadcast)
{
    new user_id = (GetEventInt(event, "userid")
    new player_who_zoomed = GetClientOfUserId(GetEventInt(event, "userid"))

    new String:weaponName[12]

    GetClientWeapon(user_id , String:weaponName , sizeof(weaponName))

    if (Weapon(weaponName) == "aug")
    {
        // code to change the zoom fov
    }
    else if (Weapon(weaponName) == "sg552")
    {
        // code to change the zoom fov
    }
    else if (Weapon(weaponName) == "scout")
    {
        // code to change the zoom fov
    }
    else if (Weapon(weaponName) == "sg550")
    {
        // code to change the zoom fov
    }
    else if (Weapon(weaponName) == "g3sg1")
    {
        // code to change the zoom fov
    }
    else if (Weapon(weaponName) == "awp")
    {
        // code to change the zoom fov
    }
    
    return
}
Exino is offline
pRED*
Join Date: Dec 2006
Old 04-21-2008 , 18:05   Re: Help Setting A Weapons Zoom FOV
Reply With Quote #4

The most efficient way to do something like this would be.. :

http://wiki.alliedmods.net/Counter-S...Source_Weapons

Copy the enum from there into your plugin.

Create a 'trie' (see adt_trie.inc).
When your plugin starts add trie items linking the weapon name string to the enum definition.

Eg. SetTrieValue(trie, "awp", Weapon_AWP);

When your PlayerZoom event fires lookup the weapon name string in the trie to retrieve the enum constant value. This is much faster than comparing strings.

You now have an integer number representing your weapon and can use a switch statement to execute the correct block of code.
pRED* 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 13:34.


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