djcev.com

//

Git Repos / fte_dogmode / qc / items / backpacks.qc

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

Show backpacks.qc

//==============================================================================
// backpacks -- Player Backpacks
//==============================================================================

//======================================================================
// constants -- dumptruck_ds
//======================================================================

const float BACKPACK_DEFAULT = 1;
const float BACKPACK_SHELLS = 2;
const float BACKPACK_NAILS = 4;
const float BACKPACK_ROCKETS = 8;
const float BACKPACK_CELLS = 16;
const float BACKPACK_DROPPED = 32;

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

// item_backpack
void() item_backpack_touch;
entity(entity src) item_backpack_drop;
entity(entity src, vector org, vector vel) spawn_item_backpack;
void(entity e) item_backpack_init;
void() item_backpack;

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

// Some of this text is from Drake -- dumptruck_ds

/*QUAKED item_backpack (0 .5 .8) (-16 -16 0) (16 16 72) SHELLS NAILS ROCKETS CELLS 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 X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/backpack.mdl"); }
By default, gives roughly half the ammo from the 4 standard pickups:

10 Shells
12 Nails
2 Rockets
3 Cells

Or you can use the spawnflags to mix and match types.
Override the spawnflags defaults by adding custom amounts to:

ammo_shells
ammo_nails
ammo_rockets
ammo_cells

Can trigger spawn and suspend in air, but not respawn. You can set a skin
index if you are using a custom model with skins.

The default pickup message is `You got a backpack.` But you can
set a custom message with the netname key. 'You got' will be the prefix
and the mapper chooses the rest of the message.

e.g. For 'You got a bunch of rockets!' the netname key would be
'a bunch of rockets!'
*/
//----------------------------------------------------------------------
// class item_backpack: base_item
// {
//--------------------------------------------------------------
void() item_backpack_touch =
{
if (self.spawnflags & BACKPACK_DROPPED)
{
/*
if (sub_checkvalidtouch(other) == FALSE)
return;
*/

local string s;
local float acount, best, old, new;
local entity stemp;

// from Copper -- dumptruck_ds
if (other.movetype == MOVETYPE_NOCLIP)
return;
if (other.classtype != CT_PLAYER)
return;
if (other.health <= 0)
return;

acount = 0;
sprint (other, "You get ");

if (self.items)
{
if ((other.items & self.items) == 0)
{
acount = 1;
sprint (other, "the ");
sprint (other, self.netname);
}
}

// 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);
}

// change weapons
other.ammo_shells += self.ammo_shells;
other.ammo_nails += self.ammo_nails;
other.ammo_rockets += self.ammo_rockets;
other.ammo_cells += self.ammo_cells;

new = self.items;
if (!new)
new = other.weapon;
old = other.items;
other.items = other.items | new;

bound_entity_ammo (other);

// hack to fix an issue with custom Grunt, Ogre
// and Enf ammo types. - dumptruck_ds
// if (self.ammo_shells < 100)
if (self.ammo_shells)
{
if (acount)
sprint (other, ", ");
acount = 1;
s = ftos (self.ammo_shells);
sprint (other, s);
sprint (other, " shells");
}
if (self.ammo_nails)
{
if (acount)
sprint (other, ", ");
acount = 1;
s = ftos (self.ammo_nails);
sprint (other, s);
sprint (other, " nails");
}
if (self.ammo_rockets)
{
if (acount)
sprint (other, ", ");
acount = 1;
s = ftos (self.ammo_rockets);
sprint (other, s);
sprint (other, " rockets");
}
if (self.ammo_cells)
{
if (acount)
sprint (other, ", ");
acount = 1;
s = ftos (self.ammo_cells);
sprint (other, s);
sprint (other, " cells");
}

sprint (other, "\n");
// backpack touch sound
sound (other, CHAN_ITEM, "weapons/lock4.wav",
1, ATTN_NORM);
stuffcmd (other, "bf\n");

if (other.classtype == CT_PLAYER)
{
// change to the weapon
// 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

/*
// TODO CEV
self = other;
Deathmatch_Weapon (old, new);
PlayerSetCurrentAmmo ();
*/
sub_runvoidas (other, player_set_current_ammo);
}

// remove the backpack, change self to the player
remove (self);
}
else
{
// item_backpack_message -- CEV
other.ammo_shells += self.ammo_shells;
other.ammo_nails += self.ammo_nails;
other.ammo_rockets += self.ammo_rockets;
other.ammo_cells += self.ammo_cells;

if (self.netname != "")
{
sprint (other, "You got ");
sprint (other, self.netname);
sprint (other, "\n");
}
else
{
sprint (other, "You got a backpack!\n");
}

// backpack touch sound
// sound (other, CHAN_ITEM, "weapons/lock4.wav",
// 1, ATTN_NORM);
sound_misc (other, CHAN_ITEM, self.snd_misc,
1, ATTN_NORM);
remove (self);

if (other.classtype == CT_PLAYER)
{
stuffcmd (other, "bf\n");
bound_entity_ammo (other);
sub_runvoidas (other, player_set_current_ammo);
}
}
};

//--------------------------------------------------------------
// DropBackpack
//--------------------------------------------------------------
entity(entity src) item_backpack_drop =
{
local entity pack = __NULL__;
local vector vel;

if (src.ammo_shells + src.ammo_nails + src.ammo_rockets +
src.ammo_cells <= 0)
{
// nothing in it
dprint ("item_backpack_drop: empty pack!\n");
return pack;
}

vel_z = 300;
vel_x = -100 + (random() * 200);
vel_y = -100 + (random() * 200);

pack = spawn_item_backpack (src, src.origin - '0 0 24', vel);

if (pack.items == IT_AXE)
pack.netname = "Axe";
else if (pack.items == IT_SHOTGUN)
pack.netname = "Shotgun";
else if (pack.items == IT_SUPER_SHOTGUN)
pack.netname = "Double-barrelled Shotgun";
else if (pack.items == IT_NAILGUN)
pack.netname = "Nailgun";
else if (pack.items == IT_SUPER_NAILGUN)
pack.netname = "Super Nailgun";
else if (pack.items == IT_GRENADE_LAUNCHER)
pack.netname = "Grenade Launcher";
else if (pack.items == IT_ROCKET_LAUNCHER)
pack.netname = "Rocket Launcher";
else if (pack.items == IT_LIGHTNING)
pack.netname = "Thunderbolt";
else
pack.netname = "";

return pack;
};

//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_item_backpack =
{
local entity e = spawn ();
e.owner = src;
e.origin = org;
e.spawnflags = BACKPACK_DROPPED,
e.items = src.weapon;
e.ammo_shells = src.ammo_shells;
e.ammo_nails = src.ammo_nails;
e.ammo_rockets = src.ammo_rockets;
e.ammo_cells = src.ammo_cells;
item_backpack_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) item_backpack_init =
{
e.classname = "item_backpack";
e.classtype = CT_ITEM_BACKPACK;
e.touch = item_backpack_touch;
e.flags = FL_ITEM;
e.solid = SOLID_TRIGGER;
e.movetype = MOVETYPE_TOSS;

if !(e.spawnflags)
{
objerror ("\bitem_backpack_init: NO SPAWNFLAG SET "
"ON item_backpack");
return;
}

if (e.spawnflags & BACKPACK_DEFAULT)
{
e.ammo_shells = 10;
e.ammo_nails = 12;
e.ammo_rockets = 2;
e.ammo_cells = 3;
}

if (e.spawnflags & BACKPACK_SHELLS)
{
if (!e.ammo_shells)
e.ammo_shells = 10;
}
if (e.spawnflags & BACKPACK_NAILS)
{
if (!e.ammo_nails)
e.ammo_nails = 12;
}
if (e.spawnflags & BACKPACK_ROCKETS)
{
if (!e.ammo_rockets)
e.ammo_rockets = 2;
}
if (e.spawnflags & BACKPACK_CELLS)
{
if (!e.ammo_cells)
e.ammo_cells = 3;
}

// set the custom noise in editor -- dumptruck_ds
if (!e.snd_misc)
e.snd_misc = "weapons/lock4.wav";
precache_sound_misc (e, e.snd_misc);

if (e.spawnflags & BACKPACK_DROPPED)
{
precache_body_model (e, "progs/backpack.mdl");
// setmodel (e, "progs/backpack.mdl");
body_model (e, "progs/backpack.mdl");
}
else
{
precache_body_model (e, "progs/pd_bpack.mdl");
body_model (e, "progs/pd_bpack.mdl");
}

// setmodel (e, "progs/backpack.mdl");
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
if (e.spawnflags & BACKPACK_DROPPED)
{
// don't delay, spawn immediately -- CEV
setsize (e, e.pos1, e.pos2);
e.think = sub_remove;
e.nextthink = time + 120;
}
else
{
base_item_init (e);
}
};

//--------------------------------------------------------------
void() item_backpack =
{
item_backpack_init (self);
};

// };

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

Log backpacks.qc

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