Executing an impulse command?

Grab your favourite IDE and tinker with the innards of game engines

Executing an impulse command?

Postby TechieUK on Sun Apr 14, 2013 4:20 pm

Alright, let me explain because the title's pretty vague:

I'm not very good at source coding. The most I've been able to do without the VDC is add new playermodels to the Deathmatch code using my brain to figure out what does what.

What I'm basically trying to do is execute the impulse 200 command when a player jumps, and again when they land. This would give the impression of lowering/raising the weapon so that it's not blocking their view, but I don't have a clue where to start.

Can anyone point me in the right direction?
Also know as WILLAM; TechieUK is my old name. If you see WILLAM on Steam or ModDB, it's me.
User avatar
TechieUK
Regular
Regular
 
Joined: Sat Apr 13, 2013 4:29 pm

Re: Executing an impulse command?

Postby PhoeniX1992 on Mon Apr 15, 2013 1:57 pm

I think a better way would be to edit the code for jumping and adding a routine for lowering the weapon in that while the player is in the air. Hope that helps.
User avatar
PhoeniX1992
1337 p0st3r
1337 p0st3r
 
Joined: Sat Jun 24, 2006 7:46 pm
Location: Office Chair

Re: Executing an impulse command?

Postby TechieUK on Mon Apr 15, 2013 5:28 pm

OK, I'll remember that. Unfortunately, my limited coding knowledge holds me back in these cases, but I'm trying to learn, so hopefully I can do it soon.
Also know as WILLAM; TechieUK is my old name. If you see WILLAM on Steam or ModDB, it's me.
User avatar
TechieUK
Regular
Regular
 
Joined: Sat Apr 13, 2013 4:29 pm

Re: Executing an impulse command?

Postby Stormy on Mon Apr 15, 2013 7:57 pm

Would there be a way to bind the console command to the space key without wiping the jump command? Maybe have it fire again when you land somehow, I assume there is some kind of callback, since the game needs to know when you land...
User avatar
Stormy
May Contain Skills
May Contain Skills
 
Joined: Sun Nov 28, 2010 6:03 am
Location: Cairns, QLD, AUS

Re: Executing an impulse command?

Postby TechieUK on Wed Apr 17, 2013 2:39 pm

PhoeniX1992 wrote:I think a better way would be to edit the code for jumping and adding a routine for lowering the weapon in that while the player is in the air. Hope that helps.


Black_Stormy wrote:Would there be a way to bind the console command to the space key without wiping the jump command? Maybe have it fire again when you land somehow, I assume there is some kind of callback, since the game needs to know when you land...


Thanks for the ideas guys, but I think I found something I could do without touching the code.
When you press space, the +jump command is executed. I could create an alias for +jump that runs impulse and another for -jump. This would lower the gun on jump, and raise when you release the key. I think it might work.
Also know as WILLAM; TechieUK is my old name. If you see WILLAM on Steam or ModDB, it's me.
User avatar
TechieUK
Regular
Regular
 
Joined: Sat Apr 13, 2013 4:29 pm

Re: Executing an impulse command?

Postby ErikKiller on Wed Apr 17, 2013 2:49 pm

1) wouldn't it spam console and 2) wouldn't it require sv_cheats 1?
Image
Image
First rodeo? Use the Source SDK Documentation for reference!
User avatar
ErikKiller
May Contain Skills
May Contain Skills
 
Joined: Sun Sep 09, 2007 4:05 pm
Location: Estonia

Re: Executing an impulse command?

Postby TechieUK on Wed Apr 17, 2013 5:12 pm

I don't think alias prints commands it executes, and I don't think impulse 200 is a cheat.
Also know as WILLAM; TechieUK is my old name. If you see WILLAM on Steam or ModDB, it's me.
User avatar
TechieUK
Regular
Regular
 
Joined: Sat Apr 13, 2013 4:29 pm

Re: Executing an impulse command?

Postby PhoeniX1992 on Thu Apr 18, 2013 10:33 am

TechieUK wrote:I don't think alias prints commands it executes, and I don't think impulse 200 is a cheat.


As far as I remember all 'impulse' commands are considered cheats by the engine.

You're on the right track though! Find the code for the +jump and -jump events and add the code for 'impulse 200' there. Either rewrite the subroutine, or find out to what function or method the impulse 200 refers and make the code for +jump and -jump execute it too!
User avatar
PhoeniX1992
1337 p0st3r
1337 p0st3r
 
Joined: Sat Jun 24, 2006 7:46 pm
Location: Office Chair

Re: Executing an impulse command?

Postby zombie@computer on Thu Apr 18, 2013 4:17 pm

If TS is able to compile the code:

step 1. search for the impulse command, you get the following code

Code: Select all
CBaseCombatWeapon *pWeapon;

         pWeapon = GetActiveWeapon();
         
         if( pWeapon->IsEffectActive( EF_NODRAW ) )
         {
            pWeapon->Deploy();
         }
         else
         {
            pWeapon->Holster();
         }
This tells you exactly how to hide (holster) weapons and show them again (deploy). Knowing this, go on with:

Find the jump code we go to hl_gamemovement.cpp (around line 1000)
Code: Select all
if ( mv->m_nButtons & IN_JUMP )
   {

add these lines somewhere:
Code: Select all
CBaseCombatWeapon *pWeapon = NULL;
pWeapon = GetActiveWeapon();
if (pWeapon != NULL)
   pWeapon->Holster();


and now we only need to find the code of the 'landing' . This is problematic, as the player is just 'thrown' so different code will control when the player hits the ground again. I suggest searching for 'land' , 'crunch' and variations thereof and placing the lines
Code: Select all
pWeapon = GetActiveWeapon();
if (pWeapon != NULL)
   pWeapon->Deploy() ;
somewhere and everywhere.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Executing an impulse command?

Postby TechieUK on Fri Apr 19, 2013 2:09 pm

It looks so simple when you explain it like that! I guess I probably should have searched for the impulse and jump commands before I posted, but anyway, I'll try and implement that code tonight.

EDIT:
Compiling now, found the landing code by searching for land. I've put it in gamemovement.cpp in the Client. I'm hoping it works, I put the code everywhere it seemed to fit.

EDIT 2:
I must have done something wrong, I got quite a few undeclared identifier errors. I'll try again in hl_gamemovement.cpp in the Server.

EDIT 3:
Just got the lowering when jumping code in, I'm going to do it bit by bit. The only error I seem to be getting is:
.\shared\hl2\hl_gamemovement.cpp(1024) : error C3861: 'GetActiveWeapon': identifier not found
Also know as WILLAM; TechieUK is my old name. If you see WILLAM on Steam or ModDB, it's me.
User avatar
TechieUK
Regular
Regular
 
Joined: Sat Apr 13, 2013 4:29 pm

Return to Programming

Who is online

Users browsing this forum: No registered users