DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial] Gun change bob
Page 1 of 2 Goto page 1, 2  Next
DieHard Wolfers Forum Index -> Code Tutorials View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Guest




Last Visit:





PostPosted: Sat Feb 12, 2005 1:26 am
   Subject: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

... Remember a long time ago in EOD when the weapon would go up and down when you would change it? Ever wanted to do that?

Well here is the tutorial.

First some credits. This tutorial has come out thanks to DUGTRIO17 Very Happy

In a post on the DHW forum he gave a piece of code which was incomplete. You could of tried to make it from there but if you didn`t get it here is the code.


Add the red lines in.

Open up WL_DEF.H and find gamestate structure, modify it as follows.
::: CODE :::
 
weapontype bestweapon,weapon,chosenweapon,nextweapon;
boolean changingweapon;
boolean goingdown;
int weapchange;

...


Now open WL_AGENT.C and find checkweaponchange
::: CODE :::
 

void CheckWeaponChange (void)
{
// int i,buttons;
if(!gamestate.weaponframe == 0 || !gamestate.ammo)
return;
switch (LastScan)
{
case 2:
LastScan=0;
if (gamestate.bestweapon >= wp_knife && gamestate.weapon != wp_knife)
gamestate.nextweapon = gamestate.chosenweapon = wp_knife;
gamestate.changingweapon = true;
gamestate.goingdown = true;
break;
case 3:
LastScan=0;
if (gamestate.bestweapon >= wp_pistol && gamestate.weapon !=wp_pistol)
{
gamestate.changingweapon = true;
gamestate.goingdown = true;
gamestate.nextweapon = gamestate.chosenweapon =wp_pistol;
DrawAmmo ();
}
break;
case 4:
LastScan=0;
if (gamestate.bestweapon >= wp_machinegun && gamestate.weapon != wp_machinegun)
{
gamestate.changingweapon = true;
gamestate.goingdown = true;
gamestate.nextweapon = gamestate.chosenweapon = wp_machinegun;
break;
case 5:
LastScan=0;
if (gamestate.bestweapon >= wp_chaingun)
{
gamestate.nextweapon = gamestate.chosenweapon = wp_chaingun;
gamestate.changingweapon = true;
gamestate.goingdown = true;
}
break;
}
}



You may notice that i like to use case statements instead of if statements. You can modify this routine to work with if statements.
Now find CMD_FIRE
add this line at the beginning
::: CODE :::
 
if(gamestate.changingweapon == true)
return;

Now open wl_play.c find funnyticcount until you find this.
::: CODE :::
 
#ifdef SPEAR
funnyticount += tics;
if (funnyticount > 30l*70)
{
funnyticount = 0;
StatusDrawPic (17,4,BJWAITING1PIC+(US_RndT()&1));
facecount = 0;
}
#endif

if(gamestate.changingweapon == true)
{
if(gamestate.goingdown == false)
{
gamestate.weapchange -=5;
if(gamestate.weapchange <= 0)
{
gamestate.weapchange = 0;
gamestate.changingweapon = false;
}
}
else
{
gamestate.weapchange += 5;
if(gamestate.weapchange >= 200)
{
gamestate.goingdown = false;
gamestate.weapon = gamestate.nextweapon;
}
}
}


In this routine we simply add or diminuish the weapchange variable which defines the position of the weapon.

Where it sais
gamestate.weapchange += 5;
and
gamestate.weapchange -= 5;

if you make the 5 lower the gun will bob slower, if you make it higher it will bob faster.

IN the end open WL_DRAW.c and find DrawPlayerWeapon
modify the routine to this:
::: CODE :::
 

void DrawPlayerWeapon (void)
{
int shapenum;

#ifndef SPEAR
if (gamestate.victoryflag)
{
if (player->state == &s_deathcam && (TimeCount&32) )
SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
return;
}
#endif
if (gamestate.weapon != -1)
{
shapenum = weaponscale[gamestate.weapon]+gamestate.weaponframe;
SimpleScaleShape(viewwidth/2-10,shapenum,viewheight+1+gamestate.weapchange);
}

if (demorecord || demoplayback)
SimpleScaleShape(viewwidth/2,SPR_DEMO,viewheight+1);
if (gamestate.crosshair)
SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
}


UPDATE:
Now go through all your files searching for gamestate.weapon.

When you find something like gamestate.weapon = wp_knife replace gamestate.weapon to gamestate.nextweapon and under add gamestate.changingweapon = true; and gamestate.goingdown = true;
That`s it. Wink

If you use this in you mod i`d like you to insert me and DUGTRIO17 in your credits. Be it a readme file or the ingame read this.

Have fun


Last edited by Guest on Sun Feb 13, 2005 4:26 am; edited 1 time in total
Dugtrio17
Code Master
Code Master


Joined: 11 Mar 2003
Last Visit: 03 Oct 2013

Topics: 49
Posts: 903
Location: Seattle
usa.gif

PostPosted: Sat Feb 12, 2005 8:34 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

This all looks about right! Nice to see you figured it out, man Smile

_________________
Guest




Last Visit:





PostPosted: Sat Feb 12, 2005 9:13 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

It`s all thanks to you Dugtrio Very Happy
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Sat Feb 12, 2005 9:24 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

It doesn't look that bad, but you guys really need to use an updated CheckWeaponChange routine. While what you have done is theoretically correct, it is very costly for memory as it uses too much repetative code that wastes memory.

Try looking at my CheckWeaponChange routine replacement in the Tutorials section and see if you can't clean that code up some (for everyone elses sake).

Remember: Memory is a concern for many and repetative or wasteful code just eats away at that precious memory.

Greg
BrotherTank

_________________

The probability of someone watching you is directly related to the Stupidity of your actions
&
The two most abundant things in the Universe are Hydrogen & Stupidity - H.Ellison

Which of those is more relevant to you??
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Sat Feb 12, 2005 9:41 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Re: The "CheckWeaponChange" routine replacement....

Only took a few seconds to modify it, but I think this will serve the purpose:

::: CODE :::

void CheckWeaponChange (void)

   int   i,kbuttons[5]={sc_1,sc_2,sc_3,sc_4,sc_5};
 
   if (gamestate.weaponframe != 0 || !gamestate.ammo) return;
   
   for (i=0;i<5;i++)
     if ((Keyboard[kbuttons[i]]) && (i <= gamestate.bestweapon) && (i != gamestate.weapon))
     {
        gamestate.chosenweapon = gamestate.nextweapon = i;
        gamestate.changingweapon = gamestate.goingdown = true; 
       
//  Change weapon sound ala MCS suggestion
        if(gamestate.chosenweapon > 0) SD_PlaySound(MYCHGSND); // Weapon Change Sound
        DrawWeapon ();
        DrawAmmo ();
        return;
     }
}


Anyhow, that was just a quick coding....

Greg
BrotherTank
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 09 Nov 2017

Topics: 45
Posts: 510
Location: Ohio
usa.gif

PostPosted: Sat Feb 12, 2005 1:48 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Talk about small code...

I'm using Paal's Weapon Change, do you think that one takes a lot of memory too?

_________________
Steam: http://steamcommunity.com/id/stormx312
Dugtrio17
Code Master
Code Master


Joined: 11 Mar 2003
Last Visit: 03 Oct 2013

Topics: 49
Posts: 903
Location: Seattle
usa.gif

PostPosted: Sat Feb 12, 2005 3:51 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Wow, very nice optimization there, Greg. I have to say, my code was much sloppier than flamer46's code. Of course, that source was more just a playground for different ideas I had, but that doesn't mean some optimization would have hurt.

_________________
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Sat Feb 12, 2005 6:27 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

KyleRTCW wrote:
Talk about small code...

I'm using Paal's Weapon Change, do you think that one takes a lot of memory too?


Yes Kyle... It also wastes much memory with many if statements. His is tied to the way he did his tutorial though for the rocket launcher. To fix it one would have to re-write the code or handle the rocket launcher code differently (as I did).

If you check my new thread on Working With Weapons you can see how I started things and where the code evolved from.

Dugtrio17 wrote:
Wow, very nice optimization there, Greg. I have to say, my code was much sloppier than flamer46's code. Of course, that source was more just a playground for different ideas I had, but that doesn't mean some optimization would have hurt.


Thanks Dan... And yep... I go through many variations of code before I settle on things. I've merged all the Boss spawning routines to 1 simple routine and many others like that. I figured that every line of code saved saves some of the "far" memory and sure enough it does. If you add the little bit of code that I gave for checking memory in the other thread on saving memory, you will see each time that you edit your code, just how much memory it used.

Greg
BrotherTank
Guest




Last Visit:





PostPosted: Sun Feb 13, 2005 3:57 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

BT how can you adapt your weap change code to make different weapon s with different ammo and then add a piece that sends a message like "You don`t have this weapon"?

I added a new piece to the tutorial. Look at the first post.
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Sun Feb 13, 2005 9:47 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

flamer46 wrote:
BT how can you adapt your weap change code to make different weapons with different ammo


See the Topic: Working with Weapons

flamer46 wrote:
and then add a piece that sends a message like "You don`t have this weapon"?


That requires a little change to the CheckWeaponChange routine but not that much really. Study the code and when you understand it, you will be able to make the changes.

flamer46 wrote:
I added a new piece to the tutorial. Look at the first post.


I noticed that... What you added will change other things that don't really need to be changed. The additional changes you suggest are:

Quote:

UPDATE:
Now go through all your files searching for gamestate.weapon.

When you find something like gamestate.weapon = wp_knife replace gamestate.weapon to gamestate.nextweapon and under add gamestate.changingweapon = true; and gamestate.goingdown = true;


If you do this is places like the "Died" and "NewGame" routines you will cause the game to not know which is the starting weapon. The only place these lines should be changed or added might be in the T_Attack routine as for weapon fallback... ie you run out of ammo and if falls back to the knife or you had fallen back to the knife but picked up ammo so it should go back to chosen weapon.

While your tutorial works, you need to define it more accurately as to which lines specifically need changing and then fix some of the wording so that it can be followed by everyone. Then and only then can it be moved to the "Tutorials Section" of the forums.

Greg
BrotherTank

_________________

The probability of someone watching you is directly related to the Stupidity of your actions
&
The two most abundant things in the Universe are Hydrogen & Stupidity - H.Ellison

Which of those is more relevant to you??
Guest




Last Visit:





PostPosted: Sun Feb 13, 2005 12:29 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks BT for pointing that out. I will be modifying the tutorial tomorrow.
JackaL
DieHard SS
DieHard SS


Joined: 25 Jun 2004
Last Visit: 04 Apr 2011

Topics: 30
Posts: 335
Location: Rotorua, New Zealand
newzealand.gif

PostPosted: Mon Feb 21, 2005 12:53 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hey, I have inserted this feature into my code, well, I was up a while getting rid of all those error messages I got when trying to compile and link. Finally I got it to work. But now my weapon sprites are all mixed up, the knife is the Demo Sprite and the pistol is the Deathcam Sprite, and so on, when I fire it goes through a bunch of object sprites as the fireing sprites. Also when I fire the Knife it lowers itself then raises again as if I changed weapon. I think this was due to the part
Quote:
When you find something like gamestate.weapon = wp_knife replace gamestate.weapon to gamestate.nextweapon and under add gamestate.changingweapon = true; and gamestate.goingdown = true;

Hmmm, maybe I should try this code all over again? Maybe it was caused by my heavy editing on the tutorials original code to stop the error messages.... any help or solution?
Guest




Last Visit:





PostPosted: Mon Feb 21, 2005 5:09 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Jackal:
Did you modify the tutorial in any way?

And this is for the public

Quote:

Now go through all your files searching for gamestate.weapon.

When you find something like gamestate.weapon = wp_knife replace gamestate.weapon to gamestate.nextweapon and under add gamestate.changingweapon = true; and gamestate.goingdown = true;


Do this only for the wl_agent.c file
JackaL
DieHard SS
DieHard SS


Joined: 25 Jun 2004
Last Visit: 04 Apr 2011

Topics: 30
Posts: 335
Location: Rotorua, New Zealand
newzealand.gif

PostPosted: Mon Feb 21, 2005 9:40 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yer, I did modify it, but that was due to getting error messages when trying to compile, maybe I got something slightly wrong... I'll give it another go.
Once I did modify it though It still worked fine just with the garbled sprites.
Nembo
Can I Play Daddy
Can I Play Daddy


Joined: 26 Feb 2006
Last Visit: 01 Oct 2017

Topics: 5
Posts: 35

usa.gif

PostPosted: Tue Feb 28, 2006 5:20 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Ok I had already added Dugtrio17 Gun bobbing tutorial and everything worked fine. I then added flamer46 Gun Change bob tutrorial. I could not get flamers46 "CheckWeaponChange" routine to work and kept getting errors when trying to compile. So I replaced it with BrotherTank's "CheckWeaponChange" routine and got everything working.

But thier is a strange bug, the weapon Icon on the HUD would show the right weapon when you first got that gun but once you switched weapons it would pick the wrong Icon, ie, you would pick up the MP40 and it would show a MP40, switch to the pistol and it might show a knife, switch back to the MP40 it might show a pistol and switch to the Knife and it might show the MP40.


Any Ideas on whats causing this to happen, and how to fix the problem?
Thanks,
Nembo
Can I Play Daddy
Can I Play Daddy


Joined: 26 Feb 2006
Last Visit: 01 Oct 2017

Topics: 5
Posts: 35

usa.gif

PostPosted: Thu Mar 09, 2006 4:50 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hello,

I tried putting in Flamers tutorial again on a fresh source code with no changes. But again I got bugs relating to the weapon Icon on the HUD.

With Flamer46's CheckWeaponChange, the weapon Icons never change.

With BrotherTank's CheckWeaponChange, the weapon Icons get all mixed up.

So can anybody help at all in some manner?
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 09 Dec 2017

Topics: 86
Posts: 752
Location: Wisconsin
usa.gif

PostPosted: Thu Mar 09, 2006 8:29 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

It depends where the DrawWeapon(); line is written. You should have it in the CheckWeaponChange function right before the last bracket. Maybe that would work.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Nembo
Can I Play Daddy
Can I Play Daddy


Joined: 26 Feb 2006
Last Visit: 01 Oct 2017

Topics: 5
Posts: 35

usa.gif

PostPosted: Thu Mar 09, 2006 12:22 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks Insurrectionman,

I added the missing DrawWeapon(); and now Flamer46's changes Icons but thier mixed up just like BrotherTanks's.

Any ideas anyone?
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Thu Mar 09, 2006 7:45 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Nembo wrote:
Thanks Insurrectionman,

I added the missing DrawWeapon(); and now Flamer46's changes Icons but thier mixed up just like BrotherTanks's.

Any ideas anyone?


Yep.. Here's exactly what I use:

::: CODE :::

// Checks to make sure you have ammo for weapon
// returns "true" if yes and "false" if no
int ChkAtkAmmo (int weapon)
{
  switch (weapon)
  {   
    case wp_knife: return 1;
    case wp_pistol:
    case wp_machinegun:
    case wp_chaingun:
      if (gamestate.ammo > 0 ) return 1;
      break;
#ifdef FLAMETHROWER
    case wp_flame:
      if (gamestate.gas > 0) return 1;
      break;
#endif
#ifdef ROCKETLAUNCH
    case wp_launch:
      if (gamestate.rockets > 0) return 1;
#endif
  }
  return 0;
}

void CheckWeaponChange (void)
{
   int   i,kbuttons[10]={sc_1,sc_2,sc_3,sc_4,sc_5,sc_6,sc_7,sc_8,sc_9,sc_0};
   for (i=0;i<NUMWEAPONS;i++)
      if ((Keyboard[kbuttons[i]]) && (i != gamestate.weapon))
      {
#ifdef BESTWEAPON
         if (gamestate.bestweapon & (1<<i) && ChkAtkAmmo(i))
#else           
         if (ChkAtkAmmo(i) && i <= gamestate.bestweapon)
#endif
         {
#ifdef WEAPONCHGSND
            if(gamestate.chosenweapon != i) SD_PlaySound(CHANGEWEAPONSND);
#endif
#ifdef WEAPONC
            gamestate.changingweapon = true;
            gamestate.goingdown = true;
            gamestate.nextweapon = gamestate.chosenweapon = i;
#else
            gamestate.weapon=gamestate.chosenweapon = i;
#endif
            DrawWeapon ();
            DrawAmmo ();
            return;
         }
    }
}


and then in the wl_def.h file in the gamestate defines I have this:

::: CODE :::

#ifdef WEAPONC
  weapontype  nextweapon;
  boolean     changingweapon, goingdown;
  int weapchange;
#endif


and finally in the wl_play.c file in the "Playloop function", below the #endif after the "// MAKE FUNNY FACE IF BJ DOESN'T MOVE FOR AWHILE" for the #ifdef SPEAR, I have this:

::: CODE :::

#ifdef WEAPONC
    if(gamestate.changingweapon == true)
    {
      if(gamestate.goingdown == false)
      {
        gamestate.weapchange -=5;
        if(gamestate.weapchange <= 0)
        {
          gamestate.weapchange = 0;
          gamestate.changingweapon = false;
        }
      }
      else
      {
        gamestate.weapchange += 5;
        if(gamestate.weapchange >= 200)
        {
          gamestate.goingdown = false;
          gamestate.weapon = gamestate.nextweapon;
          DrawWeapon ();
        }
      }
    }
#endif


Lastly, check the wl_draw.c file and look for the "SimpleScaleShape" calls in the "DrawPlayerWeapon" routine and make sure that the last variable looks like this:

::: CODE :::

    SimpleScaleShape(viewwidth/2,shapenum,viewheight+1+gamestate.weapchange);


or if you have Dugtrio's gun bobble installed as well, it should look like this:

::: CODE :::

SimpleScaleShape((viewwidth/2)-10+gamestate.bobber2,shapenum,viewheight+1+gamestate.bobber+gamestate.weapchange);


That works 100% here. To enable it, just add a #define WEAPONC to your version.h file and compile it. Don't worry about the other defines, as everyone will get to see them shortly when I release "QuikCode" so that people will have all of the tutorials out there installed into 1 engine and be able to select and modify the source to suit their own needs by adjusting just a few files.
Anyhow, enjoy...

Greg
BrotherTank
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 3:19 ago.

Topics: 160
Posts: 8008
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Thu Mar 09, 2006 8:40 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

BrotherTank wrote:
Don't worry about the other defines, as everyone will get to see them shortly when I release "QuikCode" so that people will have all of the tutorials out there installed into 1 engine and be able to select and modify the source to suit their own needs by adjusting just a few files.

Sounds like an excellent idea, BT. Hats off to you once again. Thumbs Up
Nembo
Can I Play Daddy
Can I Play Daddy


Joined: 26 Feb 2006
Last Visit: 01 Oct 2017

Topics: 5
Posts: 35

usa.gif

PostPosted: Fri Mar 10, 2006 8:14 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I put it in and everything works, thank You BrotherTank.

But I have a two questions first in the code should I change the green text to reflect the fact that I only have four weapons in the game?
Also the whole parts under #ifdef FLAMETHROWER and #ifdef ROCKETLAUNCH, are they needed as I don't have any Flamethrowers or Rocketlaunchers just the stock weapons.


::: CODE :::

// Checks to make sure you have ammo for weapon
// returns "true" if yes and "false" if no
int ChkAtkAmmo (int weapon)
{
  switch (weapon)
  {   
    case wp_knife: return 1;
    case wp_pistol:
    case wp_machinegun:
    case wp_chaingun:
      if (gamestate.ammo > 0 ) return 1;
      break;
#ifdef FLAMETHROWER
    case wp_flame:
      if (gamestate.gas > 0) return 1;
      break;
#endif
#ifdef ROCKETLAUNCH
    case wp_launch:
      if (gamestate.rockets > 0) return 1;
#endif
  }
  return 0;
}

void CheckWeaponChange (void)
{
   int   i,kbuttons[10]={sc_1,sc_2,sc_3,sc_4,sc_5,sc_6,sc_7,sc_8,sc_9,sc_0};
   for (i=0;i<NUMWEAPONS;i++)
      if ((Keyboard[kbuttons[i]]) && (i != gamestate.weapon))
      {
#ifdef BESTWEAPON
         if (gamestate.bestweapon & (1<<i) && ChkAtkAmmo(i))
#else           
         if (ChkAtkAmmo(i) && i <= gamestate.bestweapon)
#endif
         {
#ifdef WEAPONCHGSND
            if(gamestate.chosenweapon != i) SD_PlaySound(CHANGEWEAPONSND);
#endif
#ifdef WEAPONC
            gamestate.changingweapon = true;
            gamestate.goingdown = true;
            gamestate.nextweapon = gamestate.chosenweapon = i;
#else
            gamestate.weapon=gamestate.chosenweapon = i;
#endif
            DrawWeapon ();
            DrawAmmo ();
            return;
         }
    }
}
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Fri Mar 10, 2006 9:49 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yes and Yes. You can change the green lines to suit your mod and you may also remove those lines that are not required for your mod as well.

Glad that it worked out for you.

Note: I found one more place that you may want to change the code, that I forgot to post. That is when you are using a weapon and it runs out of ammo, then it falls back to the proper weapon and should change using this weapon changing graphic draw as well.

That code is in the T_Attack routine in the wl_agent.c file, I set the case -1: to this:

::: CODE :::

// End of firing sequence - check ammo and fall back to best possible weapon with ammo
         case -1: 
            ob->state = &s_player;
            if (!ChkAtkAmmo (gamestate.weapon) && gamestate.chosenweapon != wp_knife)
            {
               for (i=0; i<NUMWEAPONS; i++)
               {
#ifdef BESTWEAPON
                  if (ChkAtkAmmo (i) &&  gamestate.bestweapon & (1<<i))
#else
                  if (ChkAtkAmmo (i) &&  i <= gamestate.bestweapon)
#endif
                  {
#ifdef WEAPONC
                     gamestate.changingweapon = true;
                     gamestate.goingdown = true;
                     gamestate.nextweapon = gamestate.chosenweapon = i;
#else       
                     gamestate.weapon = i;
#endif                     
                  }
               }
               DrawWeapon ();
               DrawAmmo ();
            }
            else
            {
               if (gamestate.weapon != gamestate.chosenweapon)
               {
                  if (ChkAtkAmmo(gamestate.chosenweapon))
#ifdef WEAPONC
                  {
                     gamestate.changingweapon = true;
                     gamestate.goingdown = true;
                     gamestate.nextweapon = gamestate.chosenweapon;
                  }
#else
                     gamestate.weapon = gamestate.chosenweapon;
#endif                                     
                  DrawWeapon ();
               }
            }
            gamestate.attackframe = gamestate.weaponframe = 0;
            return;


Greg
BrotherTank
Nembo
Can I Play Daddy
Can I Play Daddy


Joined: 26 Feb 2006
Last Visit: 01 Oct 2017

Topics: 5
Posts: 35

usa.gif

PostPosted: Fri Mar 10, 2006 10:40 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Ok two things.

-Added the above and when I try and compile it tells me Undefined Symbol "i". I assume this symbol "i" is something that relates to you own changes what can I do to remove it.

-During Gameplay when you run out of ammo and have to knife a guard. After every stab it repicks the knife, slowing you down. If you have some ammo this doesn't occour any. Any idea what would be causing this?

Thanks.
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Fri Mar 10, 2006 8:05 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Make the top of your T_Attack routine look like this:

::: CODE :::
void   T_Attack (objtype *ob)
{
   struct   atkinf   *cur;
   int i;


I haven't noticed the second problem that you posted, but will look into it.

Greg
BrotherTank
Nembo
Can I Play Daddy
Can I Play Daddy


Joined: 26 Feb 2006
Last Visit: 01 Oct 2017

Topics: 5
Posts: 35

usa.gif

PostPosted: Fri Mar 10, 2006 9:37 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Added that little bit and compiled it succesfully, check it and the Knife reloading bug has gone away, thanks to the extra code.

Thank You BrotherTank.
ronwolf1705
Moderator
<B>Moderator</B>


Joined: 31 Jul 2006
Last Visit: 6:15 ago.

Topics: 69
Posts: 3673

blank.gif

PostPosted: Fri Sep 15, 2006 10:10 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

How do I let the gun bob when it changes a weapon when I use the MLI code or TAB+I, and I how do I enable gun bob when I pick up a higher weapon? I use the code Brothertank posted. Can someone help me?
ronwolf1705
Moderator
<B>Moderator</B>


Joined: 31 Jul 2006
Last Visit: 6:15 ago.

Topics: 69
Posts: 3673

blank.gif

PostPosted: Sat Sep 16, 2006 3:44 am
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

What I want is, when you have a pistol and you pick up a machine gun, the pistol goes down and the machine gun comes up. The same is for TAB+I and MLI-code. When you get a better weapon, the current weapon goes down and the new weapon goes up.
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 09 Dec 2017

Topics: 86
Posts: 752
Location: Wisconsin
usa.gif

PostPosted: Sat Sep 16, 2006 12:31 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

In the MLI code just add this before the GiveWeapon piece:

gamestate.changingweapon = gamestate.goingdown = true;
gamestate.nextweapon = wp_chaingun;

wp_chaingun can be changed to whatever weapon you are receiving.

For the Tab-I i have to figure it out a bit, i can't remember offhand.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
ronwolf1705
Moderator
<B>Moderator</B>


Joined: 31 Jul 2006
Last Visit: 6:15 ago.

Topics: 69
Posts: 3673

blank.gif

PostPosted: Sat Sep 16, 2006 12:37 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I added your code to the MLI part in WL_PLAY, but when i press the MLI code in Wolf3d, you see the chaingun go down and come up again.
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 09 Dec 2017

Topics: 86
Posts: 752
Location: Wisconsin
usa.gif

PostPosted: Sat Sep 16, 2006 12:43 pm
   Subject: Re: [Tutorial] Gun change bob
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

try putting the code after the GiveWeapon(); that is what i have in my code

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> Code Tutorials View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 2 Goto page 1, 2  Next
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts [Code] Blood Splatz Tutorial - Blood Splatters
Author: Dugtrio17
45 11220 Tue Mar 11, 2008 12:02 am
AlumiuN View latest post
No new posts [Code] Display Different Ammo Types on Statusbar-BrotherTank
Author: BrotherTank
1 2381 Fri Feb 11, 2005 9:18 pm
Zombie_Plan View latest post
No new posts [Code] Adding a Frames per Second Counter - Darkone
Author: BrotherTank
0 1703 Sat Mar 13, 2004 2:07 pm
BrotherTank View latest post
No new posts [Code] Changing an Enemies Attack Strength - BrotherTank
Author: BrotherTank
0 1969 Tue Jan 27, 2004 10:29 am
BrotherTank View latest post
No new posts [Code] Changing Weapons -CheckWeaponChange- BrotherTank
Author: BrotherTank
2 2700 Sun Oct 26, 2003 1:21 am
Guest View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group