7 #include "sv_monsters.qh"
8 #include <server/autocvars.qh>
9 #include <server/defs.qh>
11 entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
13 e.spawnflags = MONSTERFLAG_SPAWNED;
15 if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; }
16 //if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
19 bool allow_any = boolean(monster == "anyrandom");
21 if(monster == "random" || allow_any)
23 RandomSelection_Init();
24 FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
26 RandomSelection_AddEnt(it, 1, 1);
29 monster_id = RandomSelection_chosen_ent.monsterid;
31 else if(monster != "")
34 FOREACH(Monsters, it != MON_Null,
36 if(it.netname == monster)
39 monster_id = it.monsterid; // we have the monster, old monster id is no longer required
44 if(!found && !monster_id)
49 return NULL; // no good
52 monster_id = MON_FIRST;
56 e.realowner = spawnedby;
59 e.monster_moveflags = moveflag;
61 if(IS_PLAYER(spawnedby))
63 if(teamplay && autocvar_g_monsters_teams)
64 e.team = spawnedby.team; // colors handled in spawn code
66 if(autocvar_g_monsters_owners)
67 e.monster_follow = own; // using .owner makes the monster non-solid for its master
69 e.angles_y = spawnedby.angles_y;
72 // Monster_Spawn checks if monster is valid
73 if(!Monster_Spawn(e, false, monster_id))
76 return NULL; // remove even if told not to, as we didn't spawn any kind of monster