1#include "changelevel.qh"
2#ifdef SVQC
3.string chmap, gametype;
4.entity chlevel_targ;
5
6void target_changelevel_use(entity this, entity actor, entity trigger)
7{
8	if(this.spawnflags & 2)
9	{
10		// simply don't react if a non-player triggers it
11		if(!IS_PLAYER(actor)) { return; }
12
13		actor.chlevel_targ = this;
14
15		int plnum = 0;
16		int realplnum = 0;
17		// let's not count bots
18		FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
19			++realplnum;
20			if(it.chlevel_targ == this)
21				++plnum;
22		});
23		if(plnum < ceil(realplnum * min(1, this.count))) // 70% of players
24			return;
25	}
26
27	if(this.gametype != "")
28		MapInfo_SwitchGameType(MapInfo_Type_FromString(this.gametype));
29
30	if (this.chmap == "")
31		localcmd("endmatch\n");
32	else
33		localcmd(strcat("changelevel ", this.chmap, "\n"));
34}
35
36spawnfunc(target_changelevel)
37{
38	this.use = target_changelevel_use;
39
40	if(!this.count) { this.count = 0.7; }
41}
42#endif
43