1 #include "modeleffects.qh"
3 REGISTER_NET_LINKED(ENT_CLIENT_MODELEFFECT)
9 bool modeleffect_SendEntity(entity this, entity to, int sf)
12 WriteHeader(MSG_ENTITY, ENT_CLIENT_MODELEFFECT);
15 if(this.velocity != '0 0 0')
17 if(this.angles != '0 0 0')
19 if(this.avelocity != '0 0 0')
22 WriteByte(MSG_ENTITY, f);
23 WriteShort(MSG_ENTITY, this.modelindex);
24 WriteByte(MSG_ENTITY, this.skin);
25 WriteByte(MSG_ENTITY, this.frame);
26 WriteVector(MSG_ENTITY, this.origin);
29 WriteVector(MSG_ENTITY, this.velocity);
33 WriteAngleVector(MSG_ENTITY, this.angles);
37 WriteAngleVector(MSG_ENTITY, this.avelocity);
39 WriteShort(MSG_ENTITY, this.scale * 256.0);
40 WriteShort(MSG_ENTITY, this.scale2 * 256.0);
41 WriteByte(MSG_ENTITY, this.teleport_time * 100.0);
42 WriteByte(MSG_ENTITY, this.fade_time * 100.0);
43 WriteByte(MSG_ENTITY, this.alpha * 255.0);
48 void modeleffect_spawn(string m, float s, float f, vector o, vector v, vector ang, vector angv, float s0, float s2, float a, float t1, float t2)
50 entity e = new(modeleffect);
62 e.scale = s0 / max6(-e.mins.x, -e.mins.y, -e.mins.z, e.maxs.x, e.maxs.y, e.maxs.z);
66 e.scale2 = s2 / max6(-e.mins.x, -e.mins.y, -e.mins.z, e.maxs.x, e.maxs.y, e.maxs.z);
69 float sz = max(e.scale, e.scale2);
70 setsize(e, e.mins * sz, e.maxs * sz);
71 Net_LinkEntity(e, false, 0.1, modeleffect_SendEntity);
78 entityclass(ModelEffect);
79 classfield(ModelEffect) .float frame1time;
80 classfield(ModelEffect) .float lifetime, fadetime;
81 classfield(ModelEffect) .float teleport_time;
82 classfield(ModelEffect) .float scale1, scale2;
88 void ModelEffect_Draw(entity this)
90 this.angles = this.angles + frametime * this.avelocity;
91 setorigin(this, this.origin + frametime * this.velocity);
92 this.scale = this.scale1 + (this.scale2 - this.scale1) * (time - this.teleport_time) / (this.lifetime + this.fadetime - this.teleport_time);
93 this.alpha = this.cnt * bound(0, 1 - (time - this.lifetime) / this.fadetime, 1);
94 if(this.alpha < ALPHA_MIN_VISIBLE)
99 this.drawmask = MASK_NORMAL;
107 NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew)
113 entity e = new(modeleffect);
114 e.model = "from network";
115 e.modelindex = ReadShort();
117 e.frame = ReadByte();
119 e.origin = ReadVector();
120 setorigin(e, e.origin);
123 e.velocity = ReadVector();
127 e.angles = ReadAngleVector();
131 e.avelocity = ReadAngleVector();
133 e.scale1 = ReadShort() / 256.0;
134 e.scale2 = ReadShort() / 256.0;
135 e.lifetime = time + ReadByte() * 0.01;
136 e.fadetime = ReadByte() * 0.01;
137 e.teleport_time = time;
138 e.cnt = ReadByte() / 255.0; // actually alpha
140 e.draw = ModelEffect_Draw;
141 if (isnew) IL_PUSH(g_drawables, e);
143 if (!isnew) delete(e); // yes, this IS stupid, but I don't need to duplicate all the read* stuff then