PDA

View Full Version : Set Client Cvars while ADS



the_law
15th June 2015, 05:26
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:


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.

Ni3ls
15th June 2015, 05:35
if(self playerAds() == 0 ) no aim, bigger than 0 means its going from ads to not or from not to ads.

if(self playerAds() == 1 ) highest point in ads

filthy_freak_
15th June 2015, 06:13
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).

kung foo man
15th June 2015, 07:24
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()):



// 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?359-VIDEO-rotating-brushmodels

Tally
15th June 2015, 09:01
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:


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:


self isAds()

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


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.

IzNoGoD
15th June 2015, 09:13
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

the_law
15th June 2015, 17:09
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()


if (self playerAds() < 0) //changed > to <, that's all