Author |
Message |
Guest

Last Visit:
|
Posted: Mon Jan 17, 2005 10:15 am
Subject: [Tutorial] Two weapons One button
[ IP : Logged ]
|

 
|
|
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


Joined: 12 Oct 2004
Last Visit: 4:55 ago.
Topics: 111
Posts: 1757
Location: A hole in the wall

|
|
 |
Guest

Last Visit:
|
Posted: Sat Jan 22, 2005 3:02 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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

Joined: 30 Jul 2003
Last Visit: 10 Aug 2019
Topics: 45
Posts: 510
Location: Ohio

|
Posted: Sat Jan 22, 2005 7:34 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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  |
_________________ Steam: http://steamcommunity.com/id/stormx312
|
|
 |
Guest

Last Visit:
|
Posted: Sat Jan 22, 2005 8:29 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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

Joined: 30 Jul 2003
Last Visit: 10 Aug 2019
Topics: 45
Posts: 510
Location: Ohio

|
|
 |
Guest

Last Visit:
|
Posted: Sat Jan 22, 2005 10:57 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

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


Joined: 12 Oct 2004
Last Visit: 4:55 ago.
Topics: 111
Posts: 1757
Location: A hole in the wall

|
|
 |
Guest

Last Visit:
|
Posted: Mon Jan 24, 2005 8:12 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

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


Joined: 12 Oct 2004
Last Visit: 4:55 ago.
Topics: 111
Posts: 1757
Location: A hole in the wall

|
|
 |
KyleRTCW
DieHard Officer

Joined: 30 Jul 2003
Last Visit: 10 Aug 2019
Topics: 45
Posts: 510
Location: Ohio

|
Posted: Tue Jan 25, 2005 4:03 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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:
|
Posted: Tue Jan 25, 2005 6:16 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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


Joined: 12 Oct 2004
Last Visit: 4:55 ago.
Topics: 111
Posts: 1757
Location: A hole in the wall

|
|
 |
Guest

Last Visit:
|
Posted: Thu Jan 27, 2005 7:41 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

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


Joined: 12 Oct 2004
Last Visit: 4:55 ago.
Topics: 111
Posts: 1757
Location: A hole in the wall

|
Posted: Sun Feb 06, 2005 4:28 pm
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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:
|
Posted: Mon Feb 07, 2005 7:32 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
I had already found that out by reading your new bonus sistem tutorial  |
|
|
 |
BrotherTank
Forum Administrator

Joined: 01 Mar 2003
Last Visit: 13 Sep 2017
Topics: 153
Posts: 2248
Location: Ontario

|
Posted: Mon Feb 07, 2005 10:38 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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:
|
Posted: Mon Feb 07, 2005 11:11 am
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

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

Joined: 17 Apr 2004
Last Visit: 30 Nov 2017
Topics: 24
Posts: 506

|
Posted: Tue Feb 15, 2005 6:45 pm
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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


Joined: 17 Jan 2004
Last Visit: 30 May 2018
Topics: 19
Posts: 559

|
Posted: Thu Feb 17, 2005 4:27 pm
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

  
|
|
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


Joined: 16 Mar 2003
Last Visit: 17 Jan 2019
Topics: 13
Posts: 186
Location: Yorkshire, UK

|
Posted: Fri Feb 18, 2005 8:12 pm
Subject: Re: [Tutorial] Two weapons One button
[ IP : Logged ]
|

 
|
|
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
|
|
 |
|