From dbe19ad2f17e012dae86fc9ab4bfb29939af728e Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 13 Mar 2017 15:13:05 +1000 Subject: [PATCH] Add a spawn_range field to the spawner, to auto create a trigger field around the spawner --- qcsrc/common/monsters/sv_spawner.qc | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/qcsrc/common/monsters/sv_spawner.qc b/qcsrc/common/monsters/sv_spawner.qc index af4ce841d..7e7f13561 100644 --- a/qcsrc/common/monsters/sv_spawner.qc +++ b/qcsrc/common/monsters/sv_spawner.qc @@ -3,6 +3,7 @@ bool autocvar_g_monster_spawner_copyfields = false; // just incase this gets too nasty .bool use_trigger_origin; +.float spawn_range; // using a new field here, so as to not interfere with anything monsters might use void spawner_use(entity this, entity actor, entity trigger) { @@ -40,9 +41,41 @@ void spawner_use(entity this, entity actor, entity trigger) e = spawnmonster(e, this.spawnmob, 0, this, this, org, false, true, this.monster_moveflags); } +void spawner_trigger_touch(entity this, entity toucher) +{ + if(!toucher.iscreature || IS_DEAD(toucher) || toucher.health < 1) + return; // only players + + spawner_use(this.owner, toucher, this); +} + +void spawner_settargets(entity this) +{ + // if the spawner isn't targeted by anything, create a trigger around it based on its spawn range + if(this.spawn_range <= 0) + return; + + IFTARGETED + return; + + entity trigger = new(spawnertriggerfield); + set_movetype(trigger, MOVETYPE_NONE); + trigger.solid = SOLID_TRIGGER; + trigger.owner = this; + settouch(trigger, spawner_trigger_touch); + + vector offset = '1 1 1.5' * this.spawn_range; + setsize(trigger, this.origin - offset, this.origin + offset); +} + spawnfunc(monster_spawner) { if(!autocvar_g_monsters || !this.spawnmob || this.spawnmob == "") { delete(this); return; } this.use = spawner_use; + + if(!this.spawn_range) + this.spawn_range = 500; // default it so we can work without targets + + InitializeEntity(this, spawner_settargets, INITPRIO_FINDTARGET); } -- 2.39.2