1 /*============================================
3 Wazat's Nexuiz Grappling Hook
5 Contact: Wazat1@gmail.com
8 Installation instructions:
9 --------------------------
11 1. Place hook.c in your gamec source directory with the other source files.
13 2. Add this line to the bottom of progs.src:
17 3. Open defs.h and add these lines to the very bottom:
19 // Wazat's grappling hook
21 void GrapplingHookFrame();
22 void RemoveGrapplingHook(entity pl);
23 void SetGrappleHookBindings();
25 float GRAPHOOK_FIRE = 20;
26 float GRAPHOOK_RELEASE = 21;
27 // (note: you can change the hook impulse #'s to whatever you please)
29 4. Open client.c and add this to the top of PutClientInServer():
31 RemoveGrapplingHook(self); // Wazat's Grappling Hook
33 5. Find ClientConnect() (in client.c) and add these lines to the bottom:
35 // Wazat's grappling hook
36 SetGrappleHookBindings();
38 6. Still in client.c, find PlayerPreThink and add this line just above the call to W_WeaponFrame:
42 7. Build and test the mod. You'll want to bind a key to "+hook" like this:
45 And you should be done!
48 ============================================*/
50 .string aiment_classname;
51 void SetMovetypeFollow(entity ent, entity e)
53 ent.movetype = MOVETYPE_FOLLOW; // make the hole follow
54 ent.solid = SOLID_NOT; // MOVETYPE_FOLLOW is always non-solid
55 ent.aiment = e; // make the hole follow bmodel
56 ent.punchangle = e.angles; // the original angles of bmodel
57 ent.view_ofs = ent.origin - e.origin; // relative origin
58 ent.v_angle = ent.angles - e.angles; // relative angles
59 ent.aiment_classname = strzone(e.classname);
61 float LostMovetypeFollow(entity ent)
64 if(ent.aiment.classname != ent.aiment_classname)
70 .float button6_pressed_before;
72 void RemoveGrapplingHook(entity pl)
78 if(pl.movetype == MOVETYPE_FLY)
79 pl.movetype = MOVETYPE_WALK;
81 pl.hook_time = time + 0.0;
83 //pl.disableclientprediction = FALSE;
86 void GrapplingHookThink()
88 float spd, dist, minlength, pullspeed, ropestretch, ropeairfriction, rubberforce, newlength, rubberforce_overstretch;
90 if(self.owner.health <= 0 || self.owner.hook != self) // how did that happen?
91 { // well, better fix it anyway
95 if(LostMovetypeFollow(self))
97 RemoveGrapplingHook(self.owner);
101 self.nextthink = time;
103 makevectors(self.owner.v_angle);
104 org = self.owner.origin + self.owner.view_ofs + v_forward * 8 - v_right * 8 + v_up * -12;
106 if(self.rope_length < 0)
107 self.rope_length = vlen(org - self.origin);
111 pullspeed = cvar("g_balance_grapplehook_speed_pull");//2000;
112 // speed the rope is pulled with
114 rubberforce = cvar("g_balance_grapplehook_force_rubber");//2000;
115 // force the rope will use if it is stretched
117 rubberforce_overstretch = cvar("g_balance_grapplehook_force_rubber_overstretch");//1000;
118 // force the rope will use if it is stretched
120 minlength = cvar("g_balance_grapplehook_length_min");//100;
121 // minimal rope length
122 // if the rope goes below this length, it isn't pulled any more
124 ropestretch = cvar("g_balance_grapplehook_stretch");//400;
125 // if the rope is stretched by more than this amount, more rope is
126 // given to you again
128 ropeairfriction = cvar("g_balance_grapplehook_airfriction");//0.2
129 // while hanging on the rope, this friction component will help you a
130 // bit to control the rope
132 dir = self.origin - org;
134 dir = normalize(dir);
136 if(cvar("g_grappling_hook_tarzan"))
138 newlength = self.rope_length;
140 // first pull the rope...
141 newlength = max(newlength - pullspeed * frametime, minlength);
143 if(newlength < dist - ropestretch) // overstretched?
145 newlength = dist - ropestretch;
146 if(self.owner.velocity * dir < 0) // only if not already moving in hook direction
147 self.owner.velocity = self.owner.velocity + frametime * dir * rubberforce_overstretch;
150 if(!self.owner.BUTTON_CROUCH) // crouch key = don't pull
151 self.rope_length = newlength;
153 // then pull the player
154 spd = bound(0, (dist - self.rope_length) / ropestretch, 1);
155 self.owner.velocity = self.owner.velocity * (1 - frametime * ropeairfriction);
156 self.owner.velocity = self.owner.velocity + frametime * dir * spd * rubberforce;
160 end = self.origin - dir*50;
161 dist = vlen(end - org);
163 spd = dist * (pullspeed / 200);
168 self.owner.velocity = dir*spd;
169 self.owner.movetype = MOVETYPE_FLY;
172 self.owner.flags = self.owner.flags - (self.owner.flags & FL_ONGROUND);
174 org = org + dir*50; // get the beam out of the player's eyes
177 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0');
178 te_beam(self, self.origin + v_forward * (-9), org);
181 void GrapplingHookTouch (void)
183 if (other == self.owner)
185 // altered for Nexuiz
186 //else if (pointcontents (self.origin) == CONTENT_SKY)
187 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
189 RemoveGrapplingHook(self.owner);
196 tic = self.velocity * sys_ticrate;
197 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
198 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
199 if(trace_fraction >= 1)
201 dprint("Odd... did not hit...?\n");
203 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
205 dprint("Detected and prevented the sky-grapple bug.\n");
206 RemoveGrapplingHook(self.owner);
211 pointparticles(particleeffectnum("grapple_impact"), self.origin, '0 0 0', 1);
212 sound (self, CHAN_PROJECTILE, "weapons/hook_impact.wav", VOL_BASE, ATTN_NORM);
215 self.think = GrapplingHookThink;
216 self.nextthink = time;
217 self.touch = SUB_Null;
218 self.velocity = '0 0 0';
219 self.movetype = MOVETYPE_NONE;
220 self.rope_length = -1;
223 if(other.movetype != MOVETYPE_NONE)
224 SetMovetypeFollow(self, other);
226 //self.owner.disableclientprediction = TRUE;
229 void GrapplingHook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
233 self.health = self.health - damage;
234 if (self.health <= 0)
236 if(attacker != self.owner)
238 self.owner.pusher = attacker;
239 self.owner.pushltime = time + cvar("g_maxpushtime");
241 RemoveGrapplingHook(self.owner);
246 void FireGrapplingHook (void)
248 local entity missile;
251 if((arena_roundbased && time < warmup) || (time < restart_countdown))
254 makevectors(self.v_angle);
256 sound (self, CHAN_WEAPON, "weapons/hook_fire.wav", VOL_BASE, ATTN_NORM);
257 org = self.origin + self.view_ofs + v_forward * 8 - v_right * 8 + '0 0 -12';
258 pointparticles(particleeffectnum("grapple_muzzleflash"), org, '0 0 0', 1);
261 missile.owner = self;
263 missile.classname = "grapplinghook";
265 missile.movetype = MOVETYPE_FLY;
266 missile.solid = SOLID_BBOX;
268 setmodel (missile, "models/hook.md3"); // precision set below
269 setsize (missile, '-3 -3 -3', '3 3 3');
270 setorigin (missile, org);
272 missile.state = 0; // not latched onto anything
274 missile.velocity = v_forward * cvar("g_balance_grapplehook_speed_fly");
275 W_SetupProjectileVelocity(missile);
277 missile.angles = vectoangles (missile.velocity);
278 //missile.glow_color = 250; // 244, 250
279 //missile.glow_size = 120;
280 missile.touch = GrapplingHookTouch;
281 missile.think = GrapplingHookThink;
282 missile.nextthink = time + 0.1;
284 missile.effects = /*EF_FULLBRIGHT | EF_ADDITIVE |*/ EF_LOWPRECISION;
286 missile.health = cvar("g_balance_grapplehook_health");//120
287 missile.event_damage = GrapplingHook_Damage;
288 missile.takedamage = DAMAGE_AIM;
289 missile.damageforcescale = 0;
292 void GrapplingHookFrame()
294 // this function has been modified for Nexuiz
295 if (self.BUTTON_HOOK && g_grappling_hook)
297 if (!self.hook && self.hook_time <= time && !self.button6_pressed_before)
298 if (timeoutStatus != 2) //only allow the player to fire the grappling hook if the game is not paused (timeout)
304 RemoveGrapplingHook(self);
306 self.button6_pressed_before = self.BUTTON_HOOK;
308 // if I have no hook or it's not pulling yet, make sure I'm not flying!
309 if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
311 self.movetype = MOVETYPE_WALK;
313 if(self.impulse == GRAPHOOK_FIRE && self.hook_time <= time && g_grappling_hook)
319 else if(self.hookimpulse == GRAPHOOK_RELEASE)
321 // remove hook, reset movement type
322 RemoveGrapplingHook(self);
326 /*else // make sure the player's movetype is correct
328 //if(self.hook == world && self.movetype == MOVETYPE_FLY)
329 if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
331 self.movetype = MOVETYPE_WALK;
334 // note: The hook entity does the actual pulling
337 void SetGrappleHookBindings()
339 // this function has been modified for Nexuiz
340 // don't remove these lines! old server or demos coud overwrite the new aliases
341 stuffcmd(self, "alias +hook +button6\n");
342 stuffcmd(self, "alias -hook -button6\n");