From 611ca3ef85a52d3272aeca943f0b3a97e3aa52bb Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 22 Oct 2016 02:15:29 +1000 Subject: [PATCH] Spawner: Spawn nothing if it's set to an invalid monster --- qcsrc/common/monsters/spawner.qc | 2 +- qcsrc/common/monsters/sv_spawn.qc | 17 +++++++++++++---- qcsrc/common/monsters/sv_spawn.qh | 2 +- qcsrc/server/command/common.qc | 8 ++++---- .../mutators/mutator/gamemode_invasion.qc | 5 +---- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/qcsrc/common/monsters/spawner.qc b/qcsrc/common/monsters/spawner.qc index 235a24b43..0b34d13e6 100644 --- a/qcsrc/common/monsters/spawner.qc +++ b/qcsrc/common/monsters/spawner.qc @@ -15,7 +15,7 @@ void spawner_use(entity this, entity actor, entity trigger) e.noalign = this.noalign; e.angles = this.angles; e.monster_skill = this.monster_skill; - e = spawnmonster(e, this.spawnmob, 0, this, this, this.origin, false, false, this.monster_moveflags); + e = spawnmonster(e, this.spawnmob, 0, this, this, this.origin, false, true, this.monster_moveflags); } spawnfunc(monster_spawner) diff --git a/qcsrc/common/monsters/sv_spawn.qc b/qcsrc/common/monsters/sv_spawn.qc index 056379dbc..6d9daa296 100644 --- a/qcsrc/common/monsters/sv_spawn.qc +++ b/qcsrc/common/monsters/sv_spawn.qc @@ -8,12 +8,12 @@ #include #include #endif -entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, int moveflag) +entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) { e.spawnflags = MONSTERFLAG_SPAWNED; if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; } - if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; } + //if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; } setorigin(e, orig); @@ -39,8 +39,17 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, break; } }); - if(!found) - monster_id = ((monster_id > 0) ? monster_id : MON_FIRST); + + if(!found && !monster_id) + { + if(removeifinvalid) + { + delete(e); + return NULL; // no good + } + else + monster_id = MON_FIRST; + } } e.realowner = spawnedby; diff --git a/qcsrc/common/monsters/sv_spawn.qh b/qcsrc/common/monsters/sv_spawn.qh index 8e4d480cd..983676db8 100644 --- a/qcsrc/common/monsters/sv_spawn.qh +++ b/qcsrc/common/monsters/sv_spawn.qh @@ -1,3 +1,3 @@ #pragma once -entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, int moveflag); +entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag); diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 01997d903..5b01f1349 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -381,11 +381,11 @@ void CommonCommand_editmob(int request, entity caller, int argc) if (tmp_moncount >= autocvar_g_monsters_max_perplayer) { print_to(caller, "You can't spawn any more monsters"); return; } bool found = false; - for (int i = MON_FIRST; i <= MON_LAST; ++i) + FOREACH(Monsters, it != MON_Null && it.netname == arg_lower, { - mon = get_monsterinfo(i); - if (mon.netname == arg_lower) { found = true; break; } - } + found = true; + break; + }); if (!found && arg_lower != "random") { print_to(caller, "Invalid monster"); return; } diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index 4c0976fe8..efed23a5d 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -77,11 +77,8 @@ void invasion_SpawnChosenMonster(Monster mon) setsize(e, mon.mins, mon.maxs); if(MoveToRandomMapLocation(e, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256)) - monster = spawnmonster(spawn(), "", mon.m_id, NULL, NULL, e.origin, false, false, 2); + monster = spawnmonster(e, "", mon.m_id, NULL, NULL, e.origin, false, false, 2); else return; - - setthink(e, SUB_Remove); - e.nextthink = time + 0.1; } else // if spawnmob field falls through (unset), fallback to mon (relying on spawnmonster for that behaviour) monster = spawnmonster(spawn(), spawn_point.spawnmob, mon.m_id, spawn_point, spawn_point, spawn_point.origin, false, false, 2); -- 2.39.2