here's my bg_weapons.h:
Code: Select all
// Filename:-	bg_weapons.h
//
// This crosses both client and server.
#ifndef __WEAPONS_H__
#define __WEAPONS_H__
enum { // weapon defines
	WP_NONE,
	WP_GAUNTLET,
	WP_MACHINEGUN,
	WP_SHOTGUN,
	WP_GRENADE_LAUNCHER,
	WP_ROCKET_LAUNCHER,
	WP_LIGHTNING,
	WP_RAILGUN,
	WP_PLASMAGUN,
	WP_BFG,
	WP_GRAPPLING_HOOK,
#ifdef MISSIONPACK
	WP_NAILGUN,
	WP_PROX_LAUNCHER,
	WP_CHAINGUN,
#endif
	WP_NUM_WEAPONS
};
typedef int weapon_t;
typedef enum // ammo defines
{
	AMMO_NONE,
	AMMO_BULLETS,
	AMMO_SHELLS,
	AMMO_GRENADES,
	AMMO_ROCKETS,
	AMMO_LIGHTNING,
	AMMO_SLUGS,
	AMMO_CELLS,
	AMMO_BFG,
#ifdef MISSIONPACK
	AMMO_NAILS,
	AMMO_PROX,
	AMMO_BELT,
#endif
	AMMO_MAX
} ammo_t;
typedef struct weaponData_s	// weaponData structure
{
//	char	classname[32];		// Spawning name
	int		ammoIndex;			// Index to proper ammo slot
	int		ammoLow;			// Count when ammo is low
	int		ammoPerShot;		// Amount of ammo used per shot
	int		fireTime;			// Amount of time between firings
} weaponData_t;
typedef struct  ammoData_s	// ammoData structure
{
//	char	icon[32];	// Name of ammo icon file
	int		max;		// Max amount player can hold of ammo
} ammoData_t;
extern weaponData_t weaponData[WP_NUM_WEAPONS];	// extern declaration of weaponData
extern ammoData_t ammoData[AMMO_MAX];	// extern declaration of ammoData
// Specific weapon information
#define DEFAULT_SHOTGUN_SPREAD	700
#define DEFAULT_SHOTGUN_COUNT	11
#define	LIGHTNING_RANGE		768
int BG_GetAmmoIndexForWeapon(int weapon);
int BG_GetAmmoIndexForWeapon2(int weapon);
int BG_GetAmmoLowForWeapon(int weapon);
int BG_GetFireTimeForWeapon(int weapon);
int BG_GetAmmoPerShotForWeapon(int weapon);
int BG_GetAmmoMaxForType(int type);
#endif//#ifndef __WEAPONS_H__
and here's my bg_weapons.c:
Code: Select all
//
// bg_weapons.c -- part of bg_pmove functionality
#include "q_shared.h"
#include "bg_public.h"
#include "bg_local.h"
weaponData_t weaponData[WP_NUM_WEAPONS] = 
{
	{	// WP_NONE
//		"No Weapon",				//	char	classname[32];		// Spawning name
		AMMO_NONE,					//	int		ammoIndex;			// Index to proper ammo slot
		0,							//	int		ammoLow;			// Count when ammo is low
		0,							//	int		ammoPerShot;		// Amount of ammo used per shot
		0							//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_GAUNTLET
//		"Gauntlet",					//	char	classname[32];		// Spawning name
		AMMO_NONE,					//	int		ammoIndex;			// Index to proper ammo slot
		0,							//	int		ammoLow;			// Count when ammo is low
		0,							//	int		ammoPerShot;		// Amount of ammo used per shot
		400							//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_MACHINEGUN
//		"Machinegun",				//	char	classname[32];		// Spawning name
		AMMO_BULLETS,				//	int		ammoIndex;			// Index to proper ammo slot
		10,							//	int		ammoLow;			// Count when ammo is low
		1,							//	int		ammoPerShot;		// Amount of ammo used per shot
		100							//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_SHOTGUN,
//		"Shotgun",					//	char	classname[32];		// Spawning name
		AMMO_SHELLS,				//	int		ammoIndex;			// Index to proper ammo slot
		10,							//	int		ammoLow;			// Count when ammo is low
		1,							//	int		ammoPerShot;		// Amount of ammo used per shot
		1000						//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_GRENADE_LAUNCHER,
//		"Grenade Launcher",			//	char	classname[32];		// Spawning name
		AMMO_GRENADES,				//	int		ammoIndex;			// Index to proper ammo slot
		5,							//	int		ammoLow;			// Count when ammo is low
		1,							//	int		ammoPerShot;		// Amount of ammo used per shot
		800							//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_ROCKET_LAUNCHER
//		"Rocket Launcher",		//	char	classname[32];		// Spawning name
		AMMO_ROCKETS,			//	int		ammoIndex;			// Index to proper ammo slot
		5,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		800						//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_LIGHTNING
//		"Lightning Gun",		//	char	classname[32];		// Spawning name
		AMMO_LIGHTNING,			//	int		ammoIndex;			// Index to proper ammo slot
		50,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		50						//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_RAILGUN
//		"Railgun",				//	char	classname[32];		// Spawning name
		AMMO_SLUGS,				//	int		ammoIndex;			// Index to proper ammo slot
		5,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		1500					//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_PLASMAGUN
//		"Plasmagun",			//	char	classname[32];		// Spawning name
		AMMO_CELLS,				//	int		ammoIndex;			// Index to proper ammo slot
		20,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		100						//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_BFG
//		"BFG10K",				//	char	classname[32];		// Spawning name
		AMMO_BFG,				//	int		ammoIndex;			// Index to proper ammo slot
		15,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		200						//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_GRAPPLING_HOOK
//		"Grappling Hook",		//	char	classname[32];		// Spawning name
		AMMO_NONE,				//	int		ammoIndex;			// Index to proper ammo slot
		0,						//	int		ammoLow;			// Count when ammo is low
		0,						//	int		ammoPerShot;		// Amount of ammo used per shot
		400						//	int		fireTime;			// Amount of time between firings
#ifdef MISSIONPACK
	},
	{	// WP_NAILGUN
//		"Nailgun",				//	char	classname[32];		// Spawning name
		AMMO_NAILS,				//	int		ammoIndex;			// Index to proper ammo slot
		10,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		1000					//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_PROX_LAUNCHER
//		"Prox Launcher",		//	char	classname[32];		// Spawning name
		AMMO_PROX,				//	int		ammoIndex;			// Index to proper ammo slot
		10,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		800						//	int		fireTime;			// Amount of time between firings
	},
	{	// WP_CHAINGUN
//		"Chaingun",				//	char	classname[32];		// Spawning name
		AMMO_BELT,				//	int		ammoIndex;			// Index to proper ammo slot
		50,						//	int		ammoLow;			// Count when ammo is low
		1,						//	int		ammoPerShot;		// Amount of ammo used per shot
		30						//	int		fireTime;			// Amount of time between firings
	}
#else
	}
#endif
};
ammoData_t ammoData[AMMO_MAX] = 
{
	{	// AMMO_NONE
//		"",				//	char	icon[32];	// Name of ammo icon file
		0				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_BULLETS
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_SHELLS
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_GRENADES
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_ROCKETS
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_LIGHTNING
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_SLUGS
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_CELLS
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_BFG
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
#ifdef MISSIONPACK
	},
	{	// AMMO_NAILS
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_PROX
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	},
	{	// AMMO_BELT
//		"",				//	char	icon[32];	// Name of ammo icon file
		200				//	int		max;		// Max amount player can hold of ammo
	}
#else
	}
#endif
};
int BG_GetAmmoIndexForWeapon(int weapon) {
	switch(weapon) {
		case WP_NONE:
			return AMMO_NONE;
		case WP_GAUNTLET:
			return AMMO_NONE;
		case WP_MACHINEGUN:
			return AMMO_BULLETS;
		case WP_SHOTGUN:
			return AMMO_SHELLS;
		case WP_GRENADE_LAUNCHER:
			return AMMO_GRENADES;
		case WP_ROCKET_LAUNCHER:
			return AMMO_ROCKETS;
		case WP_LIGHTNING:
			return AMMO_LIGHTNING;
		case WP_RAILGUN:
			return AMMO_SLUGS;
		case WP_PLASMAGUN:
			return AMMO_CELLS;
		case WP_BFG:
			return AMMO_BFG;
		case WP_GRAPPLING_HOOK:
			return AMMO_NONE;
#ifdef MISSIONPACK
		case WP_NAILGUN:
			return AMMO_NAILS;
		case WP_PROX_LAUNCHER:
			return AMMO_PROX;
		case WP_CHAINGUN:
			return AMMO_BELT;
#endif
		default:
			return AMMO_NONE;
	}
}
int BG_GetAmmoIndexForWeapon2(int weapon) {
	return weaponData[weapon].ammoIndex;
}
int BG_GetAmmoLowForWeapon(int weapon) {
	return weaponData[weapon].ammoLow;
}
int BG_GetFireTimeForWeapon(int weapon) {
	return weaponData[weapon].fireTime;
}
int BG_GetAmmoPerShotForWeapon(int weapon) {
	return weaponData[weapon].ammoPerShot;
}
int BG_GetAmmoMaxForType(int type) {
	return ammoData[type].max;
}
that code was based off of raven's bg_weapons weapon/ammo system but i modified it to use functions to return get data for me so that it is a bit neater in the rest of the code.
so for getting firetime you would do:
old way:
Code: Select all
	switch( pm->ps->weapon ) {
	default:
	case WP_GAUNTLET:
		addTime = 400;
		break;
	case WP_LIGHTNING:
		addTime = 50;
		break;
	case WP_SHOTGUN:
		addTime = 1000;
		break;
	case WP_MACHINEGUN:
		addTime = 100;
		break;
	case WP_GRENADE_LAUNCHER:
		addTime = 800;
		break;
	case WP_ROCKET_LAUNCHER:
		addTime = 800;
		break;
	case WP_PLASMAGUN:
		addTime = 100;
		break;
	case WP_RAILGUN:
		addTime = 1500;
		break;
	case WP_BFG:
		addTime = 200;
		break;
	case WP_GRAPPLING_HOOK:
		addTime = 400;
		break;
#ifdef MISSIONPACK
	case WP_NAILGUN:
		addTime = 1000;
		break;
	case WP_PROX_LAUNCHER:
		addTime = 800;
		break;
	case WP_CHAINGUN:
		addTime = 30;
		break;
#endif
	}
new way:
Code: Select all
addTime = BG_GetFireTimeForWeapon(pm->ps->weapon);
its a bit of a trick to make the ammoPershot work properly though:
so lets go to PM_Weapon in bg_pmove.c
add this to the top by int addTime:
int		amount;
now this is how i setup my code:
Code: Select all
	} else {
		PM_StartTorsoAnim( TORSO_ATTACK );
	}
// add here
	amount = BG_GetAmmoPerShotForWeapon( pm->ps->weapon );
// end add
	pm->ps->weaponstate = WEAPON_FIRING;
after that line you should comment out or remove this:
Code: Select all
	// check for out of ammo
	if ( ! pm->ps->ammo[ pm->ps->weapon ] ) {
		PM_AddEvent( EV_NOAMMO );
		pm->ps->weaponTime += 500;
		return;
	}
	// take an ammo away if not infinite
	if ( pm->ps->ammo[ pm->ps->weapon ] != -1 ) {
		pm->ps->ammo[ pm->ps->weapon ]--;
	}
now add this:
Code: Select all
	// check for out of ammo and check for not infinite
	// (AMMO_NONE and infinite dont really have ammo so dont do ev_noammo or ammo checks)
	if ( BG_GetAmmoIndexForWeapon(pm->ps->weapon) != AMMO_NONE )
	{
		// enough ammo to fire this weapon?
		if ( ! pm->ps->ammo[BG_GetAmmoIndexForWeapon(pm->ps->weapon)] )
		{ //the weapon is out of ammo essentially because it cannot fire primary or secondary, so do the switch
		  //regardless of if the player is attacking or not
			PM_AddEvent( EV_NOAMMO );
			if (pm->ps->weaponTime < 500)
			{
				pm->ps->weaponTime += 500;
			}
			return;
		}
	}
	// take an ammo away if not infinite
	if ( pm->ps->ammo[ BG_GetAmmoIndexForWeapon(pm->ps->weapon) ] != -1 )
	{
		// enough ammo to fire this weapon?
		if ((pm->ps->ammo[BG_GetAmmoIndexForWeapon(pm->ps->weapon)] - amount) >= 0) 
		{
			pm->ps->ammo[BG_GetAmmoIndexForWeapon(pm->ps->weapon)] -= amount;
		}
	}
okay so now you need to fix up bg_misc.c:
Code: Select all
/*QUAKED ammo_bullets (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_bullets",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/machinegunam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_machinegun",
/* pickup */	"Bullets",
		50,
		IT_AMMO,
		AMMO_BULLETS,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_shells (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_shells",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/shotgunam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_shotgun",
/* pickup */	"Shells",
		10,
		IT_AMMO,
		AMMO_SHELLS,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_grenades (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_grenades",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/grenadeam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_grenade",
/* pickup */	"Grenades",
		5,
		IT_AMMO,
		AMMO_GRENADES,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_rockets (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_rockets",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/rocketam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_rocket",
/* pickup */	"Rockets",
		5,
		IT_AMMO,
		AMMO_ROCKETS,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_lightning (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_lightning",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/lightningam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_lightning",
/* pickup */	"Lightning",
		60,
		IT_AMMO,
		AMMO_LIGHTNING,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_slugs (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_slugs",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/railgunam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_railgun",
/* pickup */	"Slugs",
		10,
		IT_AMMO,
		AMMO_SLUGS,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_cells (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_cells",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/plasmaam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_plasma",
/* pickup */	"Cells",
		30,
		IT_AMMO,
		AMMO_CELLS,
/* precache */ "",
/* sounds */ ""
	},
/*QUAKED ammo_bfg (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
	{
		"ammo_bfg",
		"sound/misc/am_pkup.wav",
        { "models/powerups/ammo/bfgam.md3", 
		0, 0, 0},
/* icon */		"icons/icona_bfg",
/* pickup */	"Bfg Ammo",
		15,
		IT_AMMO,
		AMMO_BFG,
/* precache */ "",
/* sounds */ ""
	},
if u reorganized it like i did, then you will need to update the order of them in inv.h and make sure you use the new inv.h in your mod.
there is much much more code that needs changing as well but thats just the basics of setting it up.