6 #include <common/monsters/all.qh>
7 #include <common/monsters/sv_monsters.qh>
8 #include <common/stats.qh>
9 #include <common/util.qh>
10 #include <common/weapons/_all.qh>
11 #include <server/weapons/common.qh>
14 entity spawnmonster (entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
16 e.spawnflags = MONSTERFLAG_SPAWNED;
18 if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; }
19 //if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
22 bool allow_any = boolean(monster == "anyrandom");
24 if(monster == "random" || allow_any)
26 RandomSelection_Init();
27 FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
29 RandomSelection_AddEnt(it, 1, 1);
32 monster_id = RandomSelection_chosen_ent;
34 else if(monster != "")
37 FOREACH(Monsters, it != MON_Null,
39 if(it.netname == monster)
42 monster_id = it; // we have the monster, old monster id is no longer required
47 if(!found && monster_id == MON_Null)
52 return NULL; // no good
56 // select a random valid monster type if no valid monster was provided
57 return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
62 e.realowner = spawnedby;
65 e.monster_moveflags = moveflag;
67 if(IS_PLAYER(spawnedby))
69 if(teamplay && autocvar_g_monsters_teams)
70 e.team = spawnedby.team; // colors handled in spawn code
72 if(autocvar_g_monsters_owners)
73 e.monster_follow = own; // using .owner makes the monster non-solid for its master
75 e.angles_y = spawnedby.angles_y;
78 // Monster_Spawn checks if monster is valid
79 if(!Monster_Spawn(e, false, monster_id))
82 return NULL; // remove even if told not to, as we didn't spawn any kind of monster