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] Two weapons One button
Page 1 of 1
DieHard Wolfers Forum Index -> Code Crackers 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: Mon Jan 17, 2005 10:15 am
   Subject: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

Don`t know if you know how to do this. But here is my way of making you select two
or more different weapons with one button.

Open up wl_def.h and paste the red line.
::: CODE :::

int         ammo;
int         keys;
int      button2;
weapontype      bestweapon,weapon,chosenweapon;


Now open up wl_agent.c. In this piece of code i`ll make pistol, machinegun and chaingun wit button 2.
Find the CheckWeaponChange and change to this.

::: CODE :::

void CheckWeaponChange (void)
{
 if(!gamestate.ammo || LastScan == 0)
      return;
switch (LastScan)
  {
  case 2:
   LastScan=0;
   if (gamestate.bestweapon >= wp_knife)
   gamestate.weapon = gamestate.chosenweapon = wp_knife;
   break;
case 5:
   LastScan=0;
   if (if gamestate.bestweapon >= wp_pistol)
   {
   TOP:
   switch(gamestate.button2)
   {
   case 0:
   gamestate.button2 = 1;
   if(gamestate.bestweapon <= wp_pistol)
       goto TOP;
   gamestate.weapon = gamestate.chosenweapon = wp_pistol;
   break;
   case 1:
   gamestate.button3 = 2;
   if(gamestate.bestweapon <= wp_machinegun)
       goto TOP;
   gamestate.weapon = gamestate.chosenweapon = wp_machinegun;
   break;
   case 1:
   gamestate.button3 = 0;
   if(gamestate.bestweapon <= wp_chaingun)
       goto TOP;
   gamestate.weapon = gamestate.chosenweapon = wp_chaingun;
   break;
   }
    }
    break;
   }
   DrawAmmo();
    DrawWeapon();
}


The code uses a loop. It checks if you have that weapon.
If you don`t have it it loops back to TOP where it checks again for the next weapon in order.

Tell if there are any bugs.

EDIT:
Forgot to add a definition.
Open wl_main.c
Find STARTAMMO and add red line
::: CODE :::

gamestate.health = 100;
gamestate.ammo = STARTAMMO;
gamestate.button2= 0;

You should find the same thing in wl_game.c
Look for STARTAMMO, add red lines.
::: CODE :::

gamestate.weapon = gamestate.bestweapon
     = gamestate.chosenweapon = wp_pistol;
gamestate.ammo = STARTAMMO
gamestate.button2 = 0;


That should do it.
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 9:11 ago.

Topics: 108
Posts: 1723
Location: A hole in the wall
australia.gif

PostPosted: Sat Jan 22, 2005 2:54 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Could you also say something like:

::: CODE :::

if (Keyboard[sc_2] && gamestate.chosenweapon=wp_pistol)
{
       gamestate.chosenweapon=wp_secondhandgun
}
else
{
       gamestate.chosenweapon=wp_pistol
}

Would that work?

_________________
WolfSource - Your news source since the beginning of time (2019)
Guest




Last Visit:





PostPosted: Sat Jan 22, 2005 3:02 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

You could do it that way to except you should add a line that changes gamestate.button2.

And my code is adaptable for even 3 or more weapons with 1 button
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 10 Aug 2019

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

PostPosted: Sat Jan 22, 2005 7:34 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Deathshead wrote:
Could you also say something like:

::: CODE :::

if (Keyboard[sc_2] && gamestate.chosenweapon=wp_pistol)
{
       gamestate.chosenweapon=wp_secondhandgun
}
else
{
       gamestate.chosenweapon=wp_pistol
}

Would that work?


Yeah, I thought about this about a week ago and that's exactly how I thought the featured worked, it makes sense to me.

Quote:
And my code is adaptable for even 3 or more weapons with 1 button

So is the code Deathshead posted
You could do something liek this:

::: CODE :::

if (Keyboard[sc_2])
{
if (gamestate.weapon == wp_pistol)
 gamestate.chosenweapon = gamestate.weapon = wp_pistol2;
else if (gamestate.weapon == wp_pistol2)
 gamestate.chosenweapon = gamestate.weapon = wp_pistol3;
else if (gamestate.weapon == wp_pistol3)
gamestate.chosenweapon = gamestate.weapon = wp_pistol;
}
 


Just an idea, but I'm not sure if it works but it looks like it Wink

_________________
Steam: http://steamcommunity.com/id/stormx312
Guest




Last Visit:





PostPosted: Sat Jan 22, 2005 8:29 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

What Kyle wrote was good.
It depend on how your code works.

In my code where i have multiple ammo types and things like
ingame messages that tell you "You don`t have that weapon" the code that i prefer to use is this.

Though iit all depends on what you like so you can use Kyle`s code instead.
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 10 Aug 2019

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

PostPosted: Sat Jan 22, 2005 10:48 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yes, you can always add more to it, like checking if you have the weapon

For the weapon checks, I like to use int gotmachinegun;

then say

if (gamestate.gotmachinegun) blah

instead of bestweapon, I got rid of it and hardly use it because of the tutorial that paal wrote not to get lower weapons with a higher one.

Heres an example with the checking weapons method I liek to use.
In GiveWeapon, it make gamestate.gotpistol -1 to tell the game it has teh weapon

::: CODE :::
if (Keyboard[sc_2])
{
if (gamestate.weapon == wp_pistol)
 {
   if (gamestate.gotpistol2)
    gamestate.chosenweapon = gamestate.weapon = wp_pistol2;
   else if (gamestate.gotpistol3)
    gamestate.chosenweapon = gamestate.weapon = wp_pistol3;
   else
{
    gamestate.chosenweapon = gamestate.weapon = wp_pistol;
    GetMessage ("You don't have another pistol");
}
else if (gamestate.weapon == wp_pistol2)
 {
   if (gamestate.gotpistol3)
    gamestate.chosenweapon = gamestate.weapon = wp_pistol3;
   else if (gamestate.gotpistol)
    gamestate.chosenweapon = gamestate.weapon = wp_pistol;
   else
{
    gamestate.chosenweapon = gamestate.weapon = wp_pistol2;
GetMessage ("You don't have another pistol");
}

[....... so on.......]


But this probably takes up way more memory and might not work

_________________
Steam: http://steamcommunity.com/id/stormx312
Guest




Last Visit:





PostPosted: Sat Jan 22, 2005 10:57 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yes i guess that takes up more memory than my code but is still usefull ifor some other features.
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 9:11 ago.

Topics: 108
Posts: 1723
Location: A hole in the wall
australia.gif

PostPosted: Sun Jan 23, 2005 10:29 pm
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

YAY! I wrote something that works!!!

_________________
WolfSource - Your news source since the beginning of time (2019)
Guest




Last Visit:





PostPosted: Mon Jan 24, 2005 8:12 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I`m happy for you Deathshed. You bonus tutorial was pretty good for your first coding tutorials(I think?)
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 9:11 ago.

Topics: 108
Posts: 1723
Location: A hole in the wall
australia.gif

PostPosted: Tue Jan 25, 2005 2:34 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Just another related thing.

In a game where you started with a knife, you could write this:

::: CODE :::

case wp_pistol:
   if (gamestate.weapon = wp_pistol)
   {
         GiveWeapon(wp_pistol2);
   }
   else
   {
         GiveWeapon(wp_pistol);
   }


Of course, I'm not sure without looking at the code, whether thats how you give a weapon (cant remember), or if thats how you ask if they have a weapon. But you get the jist of it.[/code]

_________________
WolfSource - Your news source since the beginning of time (2019)
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 10 Aug 2019

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

PostPosted: Tue Jan 25, 2005 4:03 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Flamer46, did you test this code that you posted? I'm no C programmer, but why are there 2 "case 1"?

_________________
Steam: http://steamcommunity.com/id/stormx312
Guest




Last Visit:





PostPosted: Tue Jan 25, 2005 6:16 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

thank you for pointing that out Kyle. Change the second case 1 to case 2

Update: I now changed tha line int he tutorial and several other.
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 9:11 ago.

Topics: 108
Posts: 1723
Location: A hole in the wall
australia.gif

PostPosted: Wed Jan 26, 2005 3:20 pm
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Also, couldn't int be changed byte to save memory?

_________________
WolfSource - Your news source since the beginning of time (2019)
Guest




Last Visit:





PostPosted: Thu Jan 27, 2005 7:41 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I don`t really understand what byte does. Could you explain it please?. Razz
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 9:11 ago.

Topics: 108
Posts: 1723
Location: A hole in the wall
australia.gif

PostPosted: Sun Feb 06, 2005 4:28 pm
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Sorry this took so long:

int covers numbers from well beyond '-10000 and 10000' and hogs up two bytes of memory. If you use bytes, which cover numbers 0-255 inclusive, you only use one byte. So as long as your number doesn't go below 0 or above 255, you are better using a byte.

Information obtained from Dugtrio17 in Wolf-Bytes issue 3

_________________
WolfSource - Your news source since the beginning of time (2019)
Guest




Last Visit:





PostPosted: Mon Feb 07, 2005 7:32 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I had already found that out by reading your new bonus sistem tutorial Smile
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

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

PostPosted: Mon Feb 07, 2005 10:38 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Deathshead wrote:
Sorry this took so long:

int covers numbers from well beyond '-10000 and 10000' and hogs up two bytes of memory. If you use bytes, which cover numbers 0-255 inclusive, you only use one byte. So as long as your number doesn't go below 0 or above 255, you are better using a byte.

Information obtained from Dugtrio17 in Wolf-Bytes issue 3


Just for further knowledge....

::: CODE :::

Type                     Length                        Range

unsigned char       8 bits                           0 to 255
char                     8 bits                      -128 to 127
enum                 16 bits                  -32,768 to 32,767
unsigned int        16 bits                           0 to 65,535
short int              16 bits                 -32,768 to 32,767
int                      16 bits                 -32,768 to 32,767
unsigned long      32 bits                          0 to 4,294,967,295
long                    32 bits      -2,147,483,648 to 2,147,483,647
float                    32 bits     3.4 * (10**-38) to 3.4 * (10**+38)
double                64 bits    1.7 * (10**-308) to 1.7 * (10**+308)
long double         80 bits   3.4 * (10**-4932) to 1.1 * (10**+4932)


These are the variable ranges directly from C++. You will notice that there is no "byte" type... There is also no boolean type either. Those variable types are created with "typedef" statements to create the types we know in wolf. They are done with the following statements:

::: CODE :::

typedef   enum   {false=0,true=1}   boolean;
typedef   unsigned   char      byte;


I hope that helps.

Greg
BrotherTank
Guest




Last Visit:





PostPosted: Mon Feb 07, 2005 11:11 am
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks for that BT it was a pretty good general c++ tutorial.
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 30 Nov 2017

Topics: 24
Posts: 506

blank.gif

PostPosted: Tue Feb 15, 2005 6:45 pm
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

OK, I just thought I'd ask... What would be the most memory effective way to have multiple weapons for one button, with some of the weapons having different ammo types, and making sure the player doesn't switch to a weapon he doesn't have? The code I wrote worked, but it's really long and sloppy, and it probably consumes more memory than necessary.
ZuljinRaynor
DieHard Officer
DieHard Officer


Joined: 17 Jan 2004
Last Visit: 30 May 2018

Topics: 19
Posts: 559

usa.gif

PostPosted: Thu Feb 17, 2005 4:27 pm
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Good question WSJ, with all the posibilities, I wonder which saves the most memory. I'm guessing on like BrotherTank's works the best.
jamez
I am Death Incarnate
I am Death Incarnate


Joined: 16 Mar 2003
Last Visit: 17 Jan 2019

Topics: 13
Posts: 186
Location: Yorkshire, UK
uk.gif

PostPosted: Fri Feb 18, 2005 8:12 pm
   Subject: Re: [Tutorial] Two weapons One button
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

This feature doesn't seem too hard to do, although I'd use a select routine here.

I take it this is where (say in hl) where if u have 2 pistols, you switch between them with the 2 button?

_________________
~ James
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Sticky: [Info] Help for newbie coders! C++ Tutorial
Author: Dugtrio17
20 11239 Sun Jan 10, 2010 12:26 pm
Fragstein3D View latest post
No new posts [Info] Black & White Effect - Tutorial
Author: Guest
10 299 Thu Mar 17, 2005 6:24 pm
Dugtrio17 View latest post
No new posts [Info] High resolution weapons - 2 methods
Author: Guest
19 540 Sun Feb 06, 2005 12:08 am
Sporb2000 View latest post
This topic is locked: you cannot edit posts or make replies. [Info] Source code for Darkone's NewWolf Classic
Author: Raistlin
1 2079 Tue Feb 10, 2004 10:18 am
BrotherTank View latest post
No new posts [Info] Making Guards Always Face You - Rotating guards
Author: CoolMario
3 88 Wed Jul 30, 2003 9:31 am
Codetech84 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