Results 1 to 7 of 7

Thread: Set Client Cvars while ADS

  1. #1
    Private
    Join Date
    Jan 2015
    Posts
    112
    Thanks
    22
    Thanked 32 Times in 17 Posts

    Set Client Cvars while ADS

    Hi guys,

    First of all, this is my first attempt at making my own script modifications, so sorry if there's any dumb mistakes I made.

    I'm trying to imitate MW2's weapon bob by changing bob-related client cvars:

    At the end of spawnPlayer() in tdm.gsc, I inserted this:
    Code:
    self setClientCvar("bg_bobAmplitudeStanding", "0.028");
    self setClientCvar("bg_bobAmplitudeDucked", "0.025");
    self setClientCvar("bg_bobMax", "1");
    This works. In game, the weapon bobs much more (approximately as much as in MW2). Only thing is that this amount of bobbing will make aiming very difficult if the player moves while ADS.

    So I'm gonna try to check if the player is ADS, and if he is, the script will set those bob-related client cvars back to default values.

    Clearly this should be done with a simple if/else statement right? I know it should, but I have not idea how to go about doing it.

  2. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Code:
    if(self playerAds() == 0 )
    no aim, bigger than 0 means its going from ads to not or from not to ads.
    Code:
    if(self playerAds() == 1 )
    highest point in ads

  3. #3
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    You should check out https://znation.nl/cod4script/ for a list of different functions and how they are used (Some functions are cod4 only though).

  4. #4
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    You need a thread to constantly watch the player ads, this snippet is untested, but kinda like this it should work (insert default values for deactivateBob()):

    PHP Code:
        // put this line in your spawnPlayer()
        
    self thread watchAimAndDecreaseBob();

        
    activateBob() {
            if (
    isDefined(self.bob))
                return;
            
    self setClientCvar("bg_bobAmplitudeStanding""0.028");
            
    self setClientCvar("bg_bobAmplitudeDucked""0.025");
            
    self setClientCvar("bg_bobMax""1");
            
    self.bob true;
        }
        
    deactivateBob() {
            if ( ! 
    isDefined(self.bob))
                return;
            
    self setClientCvar("bg_bobAmplitudeStanding""??? todo ???");
            
    self setClientCvar("bg_bobAmplitudeDucked""??? todo ???");
            
    self setClientCvar("bg_bobMax""??? todo ???");
            
    self.bob undefined;
        }

        
    watchAimAndDecreaseBob() {
            
    self endon("spawned");
            
    self activateBob(); // initially activate bob
            
    while (1) {
                if (
    self playerAds() > 0) {
                    
    self activateBob();
                } else {
                    
    self deactivateBob();
                }
                
    wait 0.05;
            }
        } 

    If you want some easy intro to threads, you could also try my "first scripted map" video (from 2012 ^^): http://killtube.org/showthread.php?3...ng-brushmodels
    timescale 0.01

  5. #5
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by the_law View Post
    Hi guys,

    First of all, this is my first attempt at making my own script modifications, so sorry if there's any dumb mistakes I made.

    I'm trying to imitate MW2's weapon bob by changing bob-related client cvars:

    At the end of spawnPlayer() in tdm.gsc, I inserted this:
    Code:
    self setClientCvar("bg_bobAmplitudeStanding", "0.028");
    self setClientCvar("bg_bobAmplitudeDucked", "0.025");
    self setClientCvar("bg_bobMax", "1");
    This works. In game, the weapon bobs much more (approximately as much as in MW2). Only thing is that this amount of bobbing will make aiming very difficult if the player moves while ADS.

    So I'm gonna try to check if the player is ADS, and if he is, the script will set those bob-related client cvars back to default values.

    Clearly this should be done with a simple if/else statement right? I know it should, but I have not idea how to go about doing it.
    Which game? Because those cvars are COD1's and don't work in COD2 (COD2 does not have a way to bob the head while running or walking).

    Also, if it is COD1, there is no native way to check ADS. Unless you are modifying UO - in which case The function is:

    Code:
    self isAds()
    If it's COD1, here is my method to find ADS (I am the first to do this):

    Code:
    spawnThumbMarker()
    {	
    	// wait until the player model is solid on spawn ( otherwise it will return an invalid player model )
    	wait( 1 );
    	
    	if( !isDefined( self.thumbmarker ) )
    	{		
    		self.thumbmarker = spawn( "script_origin", (0,0,0) );
    		self.thumbmarker linkto( self, "TAG_WEAPON_LEFT", (0,0,0) , (0,0,0) );
    	}
    
    	if( !isDefined( self.headmarker ) )
    	{
    		self.headmarker = spawn( "script_origin", (0,0,0) );
    		self.headmarker linkto( self, "TAG_HELMET", (0,0,0) , (0,0,0) );
    	}
    }
    
    /*
    	METHOD TO FIND PLAYER ADS
    	-------------------------
    	Origin of the script_origins is relative to character model's origin. So, when 
    	the arm is raised, the thumbmarker is moving further away and so registers as true.
    */
    MonitorforADS()
    {
    	self endon( "disconnect" );
    	self endon( "kill_threads" );
    	
    	self.isADS = undefined;
    	while( isAlive( self ) )
    	{
    		if( isdefined( self.headmarker ) && isDefined( self.thumbmarker ) )
    		{
    			// check for stance changes because the hud elements flash on while changing
    			while( self getStance() != "stand" )
    			{
    				wait( 1.75 );
    				continue;
    			}
    				
    			// I can only find a workable distance if the player is standing
    			while( self getStance() == "stand" )
    			{			
    				if( distance2d( self.thumbmarker.origin, self.headmarker.origin ) >= 17 )
    					self.isADS = true;
    				else
    					self.isADS = undefined;
    				
    				wait( 0.05 );
    			}
    		}
    		
    		wait( 0.05 );
    	}
    }
    
    distance2d( a, b )
    {
    	return( distance( (a[0],a[1],0), (b[0],b[1],0) ) );
    }
    run both functions from player spawn.
    Last edited by Tally; 15th June 2015 at 09:07.

  6. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Tally, would be nice to have that code modified to use distance2dsquared instead of distance2d, as you are comparing it with a pre-set value
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  7. #7
    Private
    Join Date
    Jan 2015
    Posts
    112
    Thanks
    22
    Thanked 32 Times in 17 Posts
    Oops. Sorry Tally, I forgot to mention that I was doing this in CoD2 (and yes, it works xD)

    @kung foo man: I'll try the thread you provided. I never thought of a nice trick with the setting of self.bob like that. :P Guess I still have a lot to learn about scripting.

    Besides, I've never watched/read a single tutorial on scripting (maybe it's time to read some? :P). Everything I got so far comes from messing with downloaded mods and comparing them to stock gametype files. I'll also admit that I did some noobish things like copy-pasting from other people's scripts, but at least I don't pass them off as my own.


    EDIT: Thanks guys! I made a small change and then it worked. xD

    kung foo man had it right, only thing I had to change was this part in WatchAimAndDecreaseBob()
    PHP Code:
                if (self playerAds() < 0)        //changed > to <, that's all 
    Last edited by the_law; 15th June 2015 at 17:37.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •