]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/target/changelevel.qc
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / changelevel.qc
1 #ifdef SVQC
2 .string chmap, gametype;
3 .entity chlevel_targ;
4
5
6 void target_changelevel_use()
7 {
8         SELFPARAM();
9         if(self.spawnflags & 2)
10         {
11                 // simply don't react if a non-player triggers it
12                 if(!IS_PLAYER(activator)) { return; }
13
14                 activator.chlevel_targ = self;
15
16                 int plnum = 0;
17                 int realplnum = 0;
18                 // let's not count bots
19                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
20                         ++realplnum;
21                         if(it.chlevel_targ == self)
22                                 ++plnum;
23                 ));
24                 if(plnum < ceil(realplnum * min(1, self.count))) // 70% of players
25                         return;
26         }
27
28         if(self.gametype != "")
29                 MapInfo_SwitchGameType(MapInfo_Type_FromString(self.gametype));
30
31         if (self.chmap == "")
32                 localcmd("endmatch\n");
33         else
34                 localcmd(strcat("changelevel ", self.chmap, "\n"));
35 }
36
37 spawnfunc(target_changelevel)
38 {
39         self.use = target_changelevel_use;
40
41         if(!self.count) { self.count = 0.7; }
42 }
43 #endif