]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/misc/follow.qc
Merge branch 'master' into terencehill/spectatee_status_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / misc / follow.qc
1 #include "follow.qh"
2 // the way this entity works makes it no use to CSQC, as it removes itself instantly
3
4 #ifdef SVQC
5 void follow_init(entity this)
6 {
7         entity src, dst;
8         src = NULL;
9         dst = NULL;
10         if(this.killtarget != "")
11                 src = find(NULL, targetname, this.killtarget);
12         if(this.target != "")
13                 dst = find(NULL, targetname, this.target);
14
15         if(!src && !dst)
16         {
17                 objerror(this, "follow: could not find target/killtarget");
18                 return;
19         }
20
21         if(this.jointtype)
22         {
23                 // already done :P entity must stay
24                 this.aiment = src;
25                 this.enemy = dst;
26         }
27         else if(!src || !dst)
28         {
29                 objerror(this, "follow: could not find target/killtarget");
30                 return;
31         }
32         else if(this.spawnflags & 1)
33         {
34                 // attach
35                 if(this.spawnflags & 2)
36                 {
37                         setattachment(dst, src, this.message);
38                 }
39                 else
40                 {
41                         attach_sameorigin(dst, src, this.message);
42                 }
43
44                 dst.solid = SOLID_NOT; // solid doesn't work with attachment
45                 delete(this);
46         }
47         else
48         {
49                 if(this.spawnflags & 2)
50                 {
51                         set_movetype(dst, MOVETYPE_FOLLOW);
52                         dst.aiment = src;
53                         // dst.punchangle = '0 0 0'; // keep unchanged
54                         dst.view_ofs = dst.origin;
55                         dst.v_angle = dst.angles;
56                 }
57                 else
58                 {
59                         follow_sameorigin(dst, src);
60                 }
61
62                 delete(this);
63         }
64 }
65
66 spawnfunc(misc_follow)
67 {
68         InitializeEntity(this, follow_init, INITPRIO_FINDTARGET);
69 }
70 #endif