]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add an option to pick up thrown nades
authorMario <mario@smbclan.net>
Mon, 15 Feb 2016 01:10:10 +0000 (11:10 +1000)
committerMario <mario@smbclan.net>
Mon, 15 Feb 2016 01:10:10 +0000 (11:10 +1000)
mutators.cfg
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/server/autocvars.qh

index e5285923e103c4cae9204a0b74cd21f81d467bbc..6ff74a61ba418be83b55b8126ef94cb0309ec146 100644 (file)
@@ -182,6 +182,7 @@ set g_nades 0 "enable off-hand grenades"
 set g_nades_throw_offset "0 0 0" "nade throwing offset"
 set g_nades_spawn 1 "give nades right away when player spawns rather than delaying entire refire"
 set g_nades_client_select 0 "allow client side selection of nade type"
+set g_nades_pickup 1 "allow picking up thrown nades (not your own)"
 set g_nades_nade_lifetime 3.5
 set g_nades_nade_minforce 400
 set g_nades_nade_maxforce 2000
index 3464a7cb349ed824c06b338668b23bfca087467d..5520af7404d59216f8766e86e05f6268044f8e05 100644 (file)
@@ -671,6 +671,19 @@ void nade_boom()
        remove(self);
 }
 
+void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
+void nade_pickup(entity this, entity thenade)
+{
+       spawn_held_nade(this, thenade.realowner, thenade.wait - time, thenade.nade_type, thenade.pokenade_type);
+
+       // set refire so player can't even
+       this.nade_refire = time + autocvar_g_nades_nade_refire;
+       this.nade_timer = 0;
+
+       if(this.nade)
+               this.nade.nade_time_primed = thenade.nade_time_primed;
+}
+
 void nade_touch()
 {SELFPARAM();
        if(other)
@@ -678,6 +691,16 @@ void nade_touch()
 
        if(other == self.realowner)
                return; // no self impacts
+
+       if(autocvar_g_nades_pickup)
+       if(!other.nade)
+       if(IS_REAL_CLIENT(other) && IS_PLAYER(other))
+       {
+               nade_pickup(other, self);
+               sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
+               remove(self);
+               return;
+       }
        /*float is_weapclip = 0;
        if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
        if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
@@ -834,6 +857,7 @@ void toss_nade(entity e, vector _velocity, float _time)
        _nade.customizeentityforclient = func_null;
        _nade.exteriormodeltoclient = world;
        _nade.traileffectnum = 0;
+       _nade.realowner = e;
        _nade.teleportable = true;
        _nade.pushable = true;
        _nade.gravity = 1;
@@ -917,6 +941,42 @@ float nade_customize()
        return true;
 }
 
+void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
+{
+       entity n = new(nade), fn = new(fake_nade);
+
+       n.nade_type = bound(1, ntype, Nades_COUNT);
+       n.pokenade_type = pntype;
+
+       setmodel(n, MDL_PROJECTILE_NADE);
+       //setattachment(n, player, "bip01 l hand");
+       n.exteriormodeltoclient = player;
+       n.customizeentityforclient = nade_customize;
+       n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], player.team).eent_eff_name);
+       n.colormod = Nades_from(n.nade_type).m_color;
+       n.realowner = nowner;
+       n.colormap = player.colormap;
+       n.glowmod = player.glowmod;
+       n.wait = time + max(0, ntime);
+       n.nade_time_primed = time;
+       n.think = nade_beep;
+       n.nextthink = max(n.wait - 3, time);
+       n.projectiledeathtype = DEATH_NADE.m_id;
+
+       setmodel(fn, MDL_NADE_VIEW);
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+       setattachment(fn, player.(weaponentity), "");
+       fn.realowner = fn.owner = player;
+       fn.colormod = Nades_from(n.nade_type).m_color;
+       fn.colormap = player.colormap;
+       fn.glowmod = player.glowmod;
+       fn.think = SUB_Remove_self;
+       fn.nextthink = n.wait;
+
+       player.nade = n;
+       player.fake_nade = fn;
+}
+
 void nade_prime()
 {SELFPARAM();
        if(autocvar_g_nades_bonus_only)
@@ -929,51 +989,24 @@ void nade_prime()
        if(self.fake_nade)
                remove(self.fake_nade);
 
-       entity n = new(nade), fn = new(fake_nade);
+       int ntype;
+       string pntype = self.pokenade_type;
 
        if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
-               n.nade_type = self.nade_type;
+               ntype = self.nade_type;
        else if (self.bonus_nades >= 1)
        {
-               n.nade_type = self.nade_type;
-               n.pokenade_type = self.pokenade_type;
+               ntype = self.nade_type;
+               pntype = self.pokenade_type;
                self.bonus_nades -= 1;
        }
        else
        {
-               n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
-               n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
+               ntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
+               pntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
        }
 
-       n.nade_type = bound(1, n.nade_type, Nades_COUNT);
-
-       setmodel(n, MDL_PROJECTILE_NADE);
-       //setattachment(n, self, "bip01 l hand");
-       n.exteriormodeltoclient = self;
-       n.customizeentityforclient = nade_customize;
-       n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
-       n.colormod = Nades_from(n.nade_type).m_color;
-       n.realowner = self;
-       n.colormap = self.colormap;
-       n.glowmod = self.glowmod;
-       n.wait = time + autocvar_g_nades_nade_lifetime;
-       n.nade_time_primed = time;
-       n.think = nade_beep;
-       n.nextthink = max(n.wait - 3, time);
-       n.projectiledeathtype = DEATH_NADE.m_id;
-
-       setmodel(fn, MDL_NADE_VIEW);
-       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-       setattachment(fn, self.(weaponentity), "");
-       fn.realowner = fn.owner = self;
-       fn.colormod = Nades_from(n.nade_type).m_color;
-       fn.colormap = self.colormap;
-       fn.glowmod = self.glowmod;
-       fn.think = SUB_Remove_self;
-       fn.nextthink = n.wait;
-
-       self.nade = n;
-       self.fake_nade = fn;
+       spawn_held_nade(self, self, autocvar_g_nades_nade_lifetime, ntype, pntype);
 }
 
 float CanThrowNade()
index 3c4e4c43fbc442e0d502e3d065a5fe8cd1714b8d..05d25a0b848b629b7c64ea92803838b1d1b0ce7b 100644 (file)
@@ -465,6 +465,7 @@ vector autocvar_g_nades_throw_offset;
 bool autocvar_g_nades_spawn;
 int autocvar_g_nades_spawn_count;
 bool autocvar_g_nades_client_select;
+bool autocvar_g_nades_pickup = true;
 float autocvar_g_nades_nade_lifetime;
 float autocvar_g_nades_nade_minforce;
 float autocvar_g_nades_nade_maxforce;