djcev.com

//

Git Repos / fte_dogmode / qc / items / weapons.qc

Last update to this file was on 2024-03-24 at 02:40.

Show weapons.qc

//==============================================================================
// items/weapons.qc -- weapons
//==============================================================================

//======================================================================
// constants
//======================================================================

const float AMMO_CELLS_WP = 15; // cells on weapon pickup; id1 15
const float AMMO_NAILS_WP = 30; // nails on weapon pickup; id1 30
const float AMMO_ROCKETS_WP = 5; // rockets on weapon pickup; id1 5
const float AMMO_SHELLS_WP = 5; // shells on weapon pickup; id1 5

const float WEAPON_RESPAWN_TIME = 30; // as the name suggests; id1 30

//======================================================================
// forward declarations
//======================================================================

void(entity e) bound_entity_ammo;
float(entity e, float w) rank_for_weapon;
void(entity e, float old, float new) deathmatch_weapon;

// base_item_weapon
void() base_item_weapon_touch;
entity(entity src, vector org, vector vel, void(entity) init_fn)
spawn_base_item_weapon;
void(entity e) base_item_weapon_init;
strip void() base_item_weapon;

// weapon_axe
entity(entity src, vector org, vector vel) spawn_weapon_axe;
void(entity e) weapon_axe_init;
void() weapon_axe;

// weapon_shotgun
entity(entity src, vector org, vector vel) spawn_weapon_shotgun;
void(entity e) weapon_shotgun_init;
void() weapon_shotgun;

// weapon_supershotgun
entity(entity src, vector org, vector vel) spawn_weapon_supershotgun;
void(entity e) weapon_supershotgun_init;
void() weapon_supershotgun;

// weapon_nailgun
entity(entity src, vector org, vector vel) spawn_weapon_nailgun;
void(entity e) weapon_nailgun_init;
void() weapon_nailgun;

// weapon_supernailgun
entity(entity src, vector org, vector vel) spawn_weapon_supernailgun;
void(entity e) weapon_supernailgun_init;
void() weapon_supernailgun;

// weapon_grenadelauncher
entity(entity src, vector org, vector vel) spawn_weapon_grenadelauncher;
void(entity e) weapon_grenadelauncher_init;
void() weapon_grenadelauncher;

// weapon_rocketlauncher
entity(entity src, vector org, vector vel) spawn_weapon_rocketlauncher;
void(entity e) weapon_rocketlauncher_init;
void() weapon_rocketlauncher;

// weapon_lightning
void(vector p1, vector p2, entity from, float damage) fire_lightning;
entity(entity src, vector org, vector vel) spawn_weapon_lightning;
void(entity e) weapon_lightning_init;
void() weapon_lightning;

//------------------------------------------------------------------------------

//----------------------------------------------------------------------
void(entity e) bound_entity_ammo =
{
// these constants are defined in items/ammo.qc -- CEV
if (e.ammo_shells > AMMO_SHELLS_MAX)
e.ammo_shells = AMMO_SHELLS_MAX;
if (e.ammo_nails > AMMO_NAILS_MAX)
e.ammo_nails = AMMO_NAILS_MAX;
if (e.ammo_rockets > AMMO_ROCKETS_MAX)
e.ammo_rockets = AMMO_ROCKETS_MAX;
if (e.ammo_cells > AMMO_CELLS_MAX)
e.ammo_cells = AMMO_CELLS_MAX;
};

//----------------------------------------------------------------------
float(entity e, float w) rank_for_weapon =
{
// 1997-12-23 Thunderbolt fix by Maddes recognize waterlevel
if (e.waterlevel <= WATERLEVEL_FEET && w == IT_LIGHTNING)
return 1;
if (w == IT_ROCKET_LAUNCHER)
return 2;
if (w == IT_SUPER_NAILGUN)
return 3;
if (w == IT_GRENADE_LAUNCHER)
return 4;
if (w == IT_SUPER_SHOTGUN)
return 5;
if (w == IT_NAILGUN)
return 6;
if (w == IT_SHOTGUN)
return 7;
return 8;
};

//----------------------------------------------------------------------
// deathmatch_weapon -- DM weapon change rules for picking up a weapon
//----------------------------------------------------------------------
void(entity e, float old, float new) deathmatch_weapon =
{
local float or, nr;

// change self.weapon if desired
or = rank_for_weapon (e, e.weapon);
nr = rank_for_weapon (e, new);
if (nr < or)
e.weapon = new;
};

//----------------------------------------------------------------------
// class base_item_weapon: base_item
// {
//--------------------------------------------------------------
// weapon_touch
//--------------------------------------------------------------
void() base_item_weapon_touch =
{
local float hadammo, best, new, old;
local entity stemp;
local float leave;

if (sub_checkvalidtouch(other) == FALSE)
return;

if (!(other.flags & FL_CLIENT))
return;

// if the player was using his best weapon, change up to the
// new one if better
if (other.classtype == CT_PLAYER &&
autocvar(cg_autoswitch, TRUE))
{
best = sub_runfloatas (other, player_best_weapon);
}

if (deathmatch == 2 || coop)
{
leave = 1;
// fix weapon items never firing their targets in coop or
// "deathmatch 2" -- iw
activator = other;
sub_useandforgettargets ();
}
else
{
leave = 0;
}

// johnfitz added for axe, shotgun items
// -- dumptruck_ds from RRP / rubicon2
if (self.classtype == CT_ITEM_AXE)
{
if (leave && (other.items & IT_AXE))
return;
new = IT_AXE;
}
else if (self.classtype == CT_ITEM_SHOTGUN)
{
if (leave && (other.items & IT_SHOTGUN))
return;
hadammo = other.ammo_shells;
new = IT_SHOTGUN;
other.ammo_shells += AMMO_SHELLS_WP;
}
else if (self.classtype == CT_ITEM_NAILGUN)
{
// johnfitz
if (leave && (other.items & IT_NAILGUN))
return;
hadammo = other.ammo_nails;
new = IT_NAILGUN;
other.ammo_nails += AMMO_NAILS_WP;
}
else if (self.classtype == CT_ITEM_SUPER_NAILGUN)
{
if (leave && (other.items & IT_SUPER_NAILGUN))
return;
hadammo = other.ammo_rockets;
new = IT_SUPER_NAILGUN;
other.ammo_nails += AMMO_NAILS_WP;
}
else if (self.classtype == CT_ITEM_SUPER_SHOTGUN)
{
if (leave && (other.items & IT_SUPER_SHOTGUN))
return;
hadammo = other.ammo_rockets;
new = IT_SUPER_SHOTGUN;
other.ammo_shells += AMMO_SHELLS_WP;
}
else if (self.classtype == CT_ITEM_ROCKET_LAUNCHER)
{
if (leave && (other.items & IT_ROCKET_LAUNCHER))
return;
hadammo = other.ammo_rockets;
new = IT_ROCKET_LAUNCHER;
other.ammo_rockets += AMMO_ROCKETS_WP;
}
else if (self.classtype == CT_ITEM_GRENADE_LAUNCHER)
{
if (leave && (other.items & IT_GRENADE_LAUNCHER))
return;
hadammo = other.ammo_rockets;
new = IT_GRENADE_LAUNCHER;
other.ammo_rockets += AMMO_ROCKETS_WP;
}
else if (self.classtype == CT_ITEM_LIGHTNING_GUN)
{
if (leave && (other.items & IT_LIGHTNING))
return;
hadammo = other.ammo_rockets;
new = IT_LIGHTNING;
other.ammo_cells += AMMO_CELLS_WP;
}
else
{
objerror ("base_item_weapon_touch: unknown classtype");
return;
}

sprint (other, sprintf("You got the %s\n", self.netname));
// weapon touch sound
sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
stuffcmd (other, "bf\n");

bound_entity_ammo (other);

// change to the weapon
old = other.items;
other.items = other.items | new;

if (other.classtype == CT_PLAYER &&
autocvar(cg_autoswitch, TRUE))
{
// 1997-12-23 Thunderbolt fix by Maddes start
/*
// don't separate between SinglePlayer/Coop
// and Deathmatch
if (!deathmatch)
self.weapon = new;
else
*/
// 1997-12-23 Thunderbolt fix by Maddes end
deathmatch_weapon (other, old, new);
sub_runvoidas (other, player_set_current_ammo);
}

if (leave)
return;

// remove it in single player, or setup for respawning
// in deathmatch
self.model = __NULL__;
self.solid = SOLID_NOT;
// Supa, SP respawning items support
base_item_check_respawn (self,
WEAPON_RESPAWN_TIME, WEAPON_RESPAWN_TIME);

activator = other;
// fire all targets / killtargets
sub_usetargets ();
};

//--------------------------------------------------------------
entity(entity src, vector org, vector vel, void(entity) init_fn)
spawn_base_item_weapon =
{
local entity e = spawn ();
e.owner = src;
e.origin = org;
e.velocity = vel;
init_fn (e);
return e;
};

//--------------------------------------------------------------
void(entity e) base_item_weapon_init =
{
e.classgroup |= CG_ITEM_WEAPON;
e.touch = base_item_weapon_touch;
base_item_init (e);
};

//--------------------------------------------------------------
strip void() base_item_weapon =
{
base_item_weapon_init (self);
};
// };

//======================================================================
// Weapon 1: Ranger's Axe -- johnfitz -- dumptruck_ds from RRP and rubicon2
//======================================================================

/*QUAKED weapon_axe (0 .5 .8) (-16 -16 0) (16 16 32)
Axe
*/
//----------------------------------------------------------------------
// class weapon_axe: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_axe =
{
return spawn_base_item_weapon (src, org, vel, weapon_axe_init);
};

//--------------------------------------------------------------
void(entity e) weapon_axe_init =
{
e.classname = "weapon_axe";
e.classtype = CT_ITEM_AXE;

precache_model ("progs/g_axe.mdl");
setmodel (e, "progs/g_axe.mdl");
e.weapon = IT_AXE;
e.netname = "Axe";

e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_axe =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_axe_init (self);
};
// };

//======================================================================
// Weapon 2: Shotgun -- johnfitz -- dumptruck_ds from RRP and rubicon2
//======================================================================

/*QUAKED weapon_shotgun (0 .5 .8) (-16 -16 0) (16 16 32) X STYLE_1 STYLE_2 X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_shotgn.mdl"); }
This is a pickup model that should be used when you want a player to spawn with only an axe and then later get the shotgun: (trigger_take_weapon or reset_items 2 in worldspawn). There are two models to choose from. Spawnflag 2 (the default) selects an unused “classic look” model from Rubicon 2 by metlslime. Spawnflag 4 is an alternate from Slapmap and has been used in a few mods.
Single-barrelled Shotgun
Shotgun
*/
//----------------------------------------------------------------------
// class weapon_shotgun: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_shotgun =
{
return spawn_base_item_weapon (src, org, vel,
weapon_shotgun_init);
};

//--------------------------------------------------------------
void(entity e) weapon_shotgun_init =
{
e.classname = "weapon_shotgun";
e.classtype = CT_ITEM_SHOTGUN;

precache_model ("progs/g_shotgu.mdl");
// new shotgun model by Starshipwaters
// - dumptruck_ds - removed 2 older shotguns that used spawnflags
setmodel (e, "progs/g_shotgu.mdl");
e.weapon = IT_SHOTGUN;
e.netname = "Shotgun";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_shotgun =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_shotgun_init (self);
};
// };

//======================================================================
// Weapon 3: Super Shotgun
//======================================================================

/*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_shot.mdl"); }
Double-barrelled Shotgun
*/
//----------------------------------------------------------------------
// class weapon_supershotgun: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_supershotgun =
{
return spawn_base_item_weapon (src, org, vel,
weapon_supershotgun_init);
};

//--------------------------------------------------------------
void(entity e) weapon_supershotgun_init =
{
e.classname = "weapon_supershotgun";
e.classtype = CT_ITEM_SUPER_SHOTGUN;

precache_model ("progs/g_shot.mdl");
setmodel (e, "progs/g_shot.mdl");
e.weapon = IT_SUPER_SHOTGUN;
e.netname = "Double-barrelled Shotgun";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

e.particles_offset = '0 0 33';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_supershotgun =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_supershotgun_init (self);
};
// };

//======================================================================
// Weapon 4: Nailgun
//======================================================================

/*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_nail.mdl"); }
Nailgun
*/
//----------------------------------------------------------------------
// class weapon_nailgun: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_nailgun =
{
return spawn_base_item_weapon (src, org, vel,
weapon_nailgun_init);
};

//--------------------------------------------------------------
void(entity e) weapon_nailgun_init =
{
e.classname = "weapon_nailgun";
e.classtype = CT_ITEM_NAILGUN;

precache_model ("progs/g_nail.mdl");
setmodel (e, "progs/g_nail.mdl");
e.weapon = IT_NAILGUN;
e.netname = "nailgun";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

e.particles_offset = '0 0 31';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_nailgun =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_nailgun_init (self);
};
// };

//======================================================================
// Weapon 5: Super Nailgun
//======================================================================

/*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_nail2.mdl"); }
Perforator
*/
//----------------------------------------------------------------------
// class weapon_supernailgun: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_supernailgun =
{
return spawn_base_item_weapon (src, org, vel,
weapon_supernailgun_init);
};

//--------------------------------------------------------------
void(entity e) weapon_supernailgun_init =
{
e.classname = "weapon_supernailgun";
e.classtype = CT_ITEM_SUPER_NAILGUN;

precache_model ("progs/g_nail2.mdl");
setmodel (e, "progs/g_nail2.mdl");
e.weapon = IT_SUPER_NAILGUN;
e.netname = "Super Nailgun";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

e.particles_offset = '0 0 34';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_supernailgun =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_supernailgun_init (self);
};
// };

//======================================================================
// Weapon 6: Grenade Launcher
//======================================================================

/*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_rock.mdl"); }
Grenade Launcher
*/
//----------------------------------------------------------------------
// class weapon_grenadelauncher: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel)
spawn_weapon_grenadelauncher =
{
return spawn_base_item_weapon (src, org, vel,
weapon_grenadelauncher_init);
};

//--------------------------------------------------------------
void(entity e) weapon_grenadelauncher_init =
{
e.classname = "weapon_grenadelauncher";
e.classtype = CT_ITEM_GRENADE_LAUNCHER;

precache_model ("progs/g_rock.mdl");
setmodel (e, "progs/g_rock.mdl");
e.weapon = 3;
e.netname = "Grenade Launcher";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

e.particles_offset = '0 0 28';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_grenadelauncher =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_grenadelauncher_init (self);
};
// };

//======================================================================
// Weapon 7: Rocket Launcher
//======================================================================

/*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_rock2.mdl"); }
Rocket Launcher
*/
//----------------------------------------------------------------------
// class weapon_rocketlauncher: base_item_weapon
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_rocketlauncher =
{
return spawn_base_item_weapon (src, org, vel,
weapon_rocketlauncher_init);
};

//--------------------------------------------------------------
void(entity e) weapon_rocketlauncher_init =
{
e.classname = "weapon_rocketlauncher";
e.classtype = CT_ITEM_ROCKET_LAUNCHER;

precache_model ("progs/g_rock2.mdl");
setmodel (e, "progs/g_rock2.mdl");
e.weapon = 3;
e.netname = "Rocket Launcher";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

e.particles_offset = '0 0 32';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_rocketlauncher =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_rocketlauncher_init (self);
};
// };

//======================================================================
// Weapon 8: Lightning Gun
//======================================================================

/*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/g_light.mdl"); }
Thunderbolt
*/
//----------------------------------------------------------------------
// class weapon_lightning: base_item_weapon
// {
//--------------------------------------------------------------
// this is here 'cause LG doesn't create a projectile... -- CEV
//--------------------------------------------------------------
void(vector p1, vector p2, entity from, float damage) fire_lightning =
{
local entity e1, e2;
local vector f;

f = p2 - p1;
normalize (f);
f_x = 0 - f_y;
f_y = f_x;
f_z = 0;
f = f * 16;

e1 = e2 = world;

traceline (p1, p2, FALSE, from);
if (trace_ent.takedamage)
{
particle (trace_endpos, '0 0 100', 225, damage * 4);
t_damage2 (trace_ent, from, from, damage);
if (from.classtype == CT_PLAYER)
{
if (other.classtype == CT_PLAYER)
// fly me to the moon
trace_ent.velocity_z += 400;
}
}
e1 = trace_ent;

traceline (p1 + f, p2 + f, FALSE, from);
if (trace_ent != e1 && trace_ent.takedamage)
{
particle (trace_endpos, '0 0 100', 225, damage * 4);
t_damage2 (trace_ent, from, from, damage);
}
e2 = trace_ent;

traceline (p1 - f, p2 - f, FALSE, from);
if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
{
particle (trace_endpos, '0 0 100', 225, damage * 4);
t_damage2 (trace_ent, from, from, damage);
}
};

//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_weapon_lightning =
{
return spawn_base_item_weapon (src, org, vel,
weapon_lightning_init);
};

//--------------------------------------------------------------
void(entity e) weapon_lightning_init =
{
e.classname = "weapon_lightning";
e.classtype = CT_ITEM_LIGHTNING_GUN;

precache_model ("progs/g_light.mdl");
setmodel (e, "progs/g_light.mdl");
e.weapon = 3;
e.netname = "Thunderbolt";
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

e.particles_offset = '0 0 31';

// StartItem
base_item_weapon_init (e);
};

//--------------------------------------------------------------
void() weapon_lightning =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

weapon_lightning_init (self);
};
// };

Return to the top of this page or return to the overview of this repo.

Log weapons.qc

Return to the top of this page or return to the overview of this repo.