[Code] Adding A New Weapon There are several tutorials out there, but not all work and some are confusing. This tutorail will be good and clean.
First off, open up WL_Def.c
Now, search for "SPR_CHAIN". You should see this:
//
// player attack frames
//
SPR_KNIFEREADY,SPR_KNIFEATK1,SPR_KNIFEATK2,
SPR_KNIFEATK3,SPR_KNIFEATK4,
SPR_PISTOLREADY,SPR_PISTOLATK1,SPR_PISTOLATK2,
SPR_PISTOLATK3,SPR_PISTOLATK4,
SPR_MACHINEGUNREADY,SPR_MACHINEGUNATK1,
SPR_MACHINEGUNATK2,MACHINEGUNATK3,SPR_MACHINEGUNATK4,
SPR_CHAINREADY,SPR_CHAINATK1,SPR_CHAINATK2,
SPR_CHAINATK3,SPR_CHAINATK4,
Add this after SPR_CHAINATK4, (Or the last sprite you added):
SPR_NEWREADY,SPR_NEWATK1,SPR_NEWATK2,
SPR_NEWATK3,SPR_NEWATK4,
Those are are sprites. For more frames, add extra NEWATK* sprites, though I would advise looking into my tutorial about that first.
Now, scroll down until you find this:
#define NUMWEAPONS 5
typedef enum {
wp_knife,
wp_pistol,
wp_machinegun,
wp_chaingun
} weapontype;
Notice how NUMWeapons is already 5. So, all we have to do is change it to this:
#define NUMWEAPONS 5
typedef enum {
wp_knife,
wp_pistol,
wp_machinegun,
wp_chaingun,
wp_newgun
} weapontype;
Now it knows that there is a wp_newgun. That is all in this file, you can close it now.
Now, open WL_DRAW. Search for this:
int weaponscale[NUMWEAPONS] = {SPR_KNIFEREADY,SPR_PISTOLREADY
,SPR_MACHINEGUNREADY,SPR_CHAINREADY};
Now, change it to this:
int weaponscale[NUMWEAPONS] = {SPR_KNIFEREADY,SPR_PISTOLREADY
,SPR_MACHINEGUNREADY,SPR_CHAINREADY
,SPR_NEWREADY};
Now it knows where to start the new weapon's sprites. Spr_Newready is its ready to fire frame. That is all in this file, now open WL_Agent.c and look for this:
} attackinfo[4][14] =
{
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,0,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
};
Now, change it to this:
} attackinfo[5][14] =
{
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} }, // knife
{ {6,0,1},{6,1,2},{6,0,3},{6,-1,4} }, // pistol
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} }, // machinegun
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} }, // chaingun
{ {6,0,1},{6,1,2},{6,0,3},{6,-1,4} }, // new weapon
};
The 5 could probally also be changed to NUMWEAPONS. Now, to select your weapon, go down to the check weapon change. Now, I am not going to write another one of these, so I recomend BT's. You can find it here: http://diehardwolfers.areyep.com/viewtopic.php?t=93
Hope this helps someone.
Temp Warning! I haven't worked much with this, it may not work yet. I also need to add some extra things.
Deathshead- 10-16-2005
Very Incomplete. You missed the WL_DRAW.C changes, the DrawWeapon stuff, and pickup stuff. By the way, you need to explain that NUMWEAPONS needs to be changed for each new weapon. Also, the code gets much easier if you change:
} attackinfo[4][14] =
To read:
} attackinfo[NUMWEAPONS][14] =
Since the attackinfo is always the same as the number of weapons, it makes it much easier to do it like this.
Conner94- 10-26-2005
Hmm...I wrote this awhile back. I think I said I needed to add things, so, ya. I just never got around to finishing.
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.