From: Mario Date: Mon, 15 Feb 2016 01:10:10 +0000 (+1000) Subject: Add an option to pick up thrown nades X-Git-Tag: xonotic-v0.8.2~1189 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f215024d23872f3801bf63b762e896bf2f5f8b2d;p=xonotic%2Fxonotic-data.pk3dir.git Add an option to pick up thrown nades --- diff --git a/mutators.cfg b/mutators.cfg index e5285923e..6ff74a61b 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -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 diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 3464a7cb3..5520af740 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -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() diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 3c4e4c43f..05d25a0b8 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -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;