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 ============================================*/
51 .float button6_pressed_before;
53 void RemoveGrapplingHook(entity pl)
59 if(pl.movetype == MOVETYPE_FLY)
60 pl.movetype = MOVETYPE_WALK;
62 pl.hook_time = time + 0.0;
64 //pl.disableclientprediction = FALSE;
67 void GrapplingHookThink()
69 float spd, dist, minlength, pullspeed, ropestretch, ropeairfriction, rubberforce, newlength, rubberforce_overstretch;
71 if(self.owner.health <= 0 || self.owner.hook != self) // how did that happen?
72 { // well, better fix it anyway
77 self.nextthink = time;
79 makevectors(self.owner.v_angle);
80 org = self.owner.origin + self.owner.view_ofs + v_forward * 8 - v_right * 8 + v_up * -12;
82 if(self.rope_length < 0)
83 self.rope_length = vlen(org - self.origin);
87 pullspeed = cvar("g_balance_grapplehook_speed_pull");//2000;
88 // speed the rope is pulled with
90 rubberforce = cvar("g_balance_grapplehook_force_rubber");//2000;
91 // force the rope will use if it is stretched
93 rubberforce_overstretch = cvar("g_balance_grapplehook_force_rubber_overstretch");//1000;
94 // force the rope will use if it is stretched
96 minlength = cvar("g_balance_grapplehook_length_min");//100;
97 // minimal rope length
98 // if the rope goes below this length, it isn't pulled any more
100 ropestretch = cvar("g_balance_grapplehook_stretch");//400;
101 // if the rope is stretched by more than this amount, more rope is
102 // given to you again
104 ropeairfriction = cvar("g_balance_grapplehook_airfriction");//0.2
105 // while hanging on the rope, this friction component will help you a
106 // bit to control the rope
108 dir = self.origin - org;
110 dir = normalize(dir);
112 if(cvar("g_grappling_hook_tarzan"))
114 newlength = self.rope_length;
116 // first pull the rope...
117 newlength = max(newlength - pullspeed * frametime, minlength);
119 if(newlength < dist - ropestretch) // overstretched?
121 newlength = dist - ropestretch;
122 if(self.owner.velocity * dir < 0) // only if not already moving in hook direction
123 self.owner.velocity = self.owner.velocity + frametime * dir * rubberforce_overstretch;
126 if(!self.owner.button5) // crouch key = don't pull
127 self.rope_length = newlength;
129 // then pull the player
130 spd = bound(0, (dist - self.rope_length) / ropestretch, 1);
131 self.owner.velocity = self.owner.velocity * (1 - frametime * ropeairfriction);
132 self.owner.velocity = self.owner.velocity + frametime * dir * spd * rubberforce;
136 end = self.origin - dir*50;
137 dist = vlen(end - org);
139 spd = dist * (pullspeed / 200);
144 self.owner.velocity = dir*spd;
145 self.owner.movetype = MOVETYPE_FLY;
148 self.owner.flags = self.owner.flags - (self.owner.flags & FL_ONGROUND);
150 org = org + dir*50; // get the beam out of the player's eyes
153 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
154 WriteByte (MSG_BROADCAST, TE_BEAM);
155 WriteEntity (MSG_BROADCAST, self);
156 WriteCoord (MSG_BROADCAST, self.origin_x);
157 WriteCoord (MSG_BROADCAST, self.origin_y);
158 WriteCoord (MSG_BROADCAST, self.origin_z);
159 WriteCoord (MSG_BROADCAST, org_x);
160 WriteCoord (MSG_BROADCAST, org_y);
161 WriteCoord (MSG_BROADCAST, org_z);
164 void GrapplingHookTouch (void)
166 if (other == self.owner)
168 // altered for Nexuiz
169 //else if (pointcontents (self.origin) == CONTENT_SKY)
170 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
172 RemoveGrapplingHook(self.owner);
176 sound (self, CHAN_BODY, "weapons/hook_impact.wav", 1, ATTN_NORM);
179 self.think = GrapplingHookThink;
180 self.nextthink = time;
181 self.touch = SUB_Null;
182 self.velocity = '0 0 0';
183 self.movetype = MOVETYPE_NONE;
184 self.rope_length = -1;
186 //self.owner.disableclientprediction = TRUE;
189 void GrapplingHook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
193 self.health = self.health - damage;
194 if (self.health <= 0)
196 if(attacker != self.owner)
198 self.owner.pusher = attacker;
199 self.owner.pushltime = time + cvar("g_maxpushtime");
201 RemoveGrapplingHook(self.owner);
206 void FireGrapplingHook (void)
208 local entity missile;
215 makevectors(self.v_angle);
217 sound (self, CHAN_WEAPON, "weapons/hook_fire.wav", 1, ATTN_NORM);
218 org = self.origin + self.view_ofs + v_forward * 8 - v_right * 8 + '0 0 -12';
219 te_customflash(org, 160, 0.2, '1 0 0');
222 missile.owner = self;
224 missile.classname = "grapplinghook";
226 missile.movetype = MOVETYPE_FLY;
227 missile.solid = SOLID_BBOX;
229 setmodel (missile, "models/ebomb.mdl"); // precision set below
230 setsize (missile, '-3 -3 -3', '3 3 3');
231 setorigin (missile, org);
233 missile.state = 0; // not latched onto anything
235 missile.velocity = v_forward * cvar("g_balance_grapplehook_speed_fly");
236 W_SetupProjectileVelocity(missile);
238 missile.angles = vectoangles (missile.velocity);
239 //missile.glow_color = 250; // 244, 250
240 //missile.glow_size = 120;
241 missile.touch = GrapplingHookTouch;
242 missile.think = GrapplingHookThink;
243 missile.nextthink = time + 0.1;
245 missile.effects = EF_FULLBRIGHT | EF_ADDITIVE | EF_LOWPRECISION;
247 missile.health = cvar("g_balance_grapplehook_health");//120
248 missile.event_damage = GrapplingHook_Damage;
249 missile.takedamage = DAMAGE_AIM;
250 missile.damageforcescale = 0;
253 void GrapplingHookFrame()
255 // this function has been modified for Nexuiz
256 if (self.button6 && cvar("g_grappling_hook"))
258 if (!self.hook && self.hook_time <= time && !self.button6_pressed_before)
264 RemoveGrapplingHook(self);
266 self.button6_pressed_before = self.button6;
268 // if I have no hook or it's not pulling yet, make sure I'm not flying!
269 if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
271 self.movetype = MOVETYPE_WALK;
273 if(self.impulse == GRAPHOOK_FIRE && self.hook_time <= time && cvar("g_grappling_hook"))
279 else if(self.hookimpulse == GRAPHOOK_RELEASE)
281 // remove hook, reset movement type
282 RemoveGrapplingHook(self);
286 /*else // make sure the player's movetype is correct
288 //if(self.hook == world && self.movetype == MOVETYPE_FLY)
289 if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
291 self.movetype = MOVETYPE_WALK;
294 // note: The hook entity does the actual pulling
297 void SetGrappleHookBindings()
299 // this function has been modified for Nexuiz
300 // don't remove these lines! old server or demos coud overwrite the new aliases
301 stuffcmd(self, "alias +hook +button6\n");
302 stuffcmd(self, "alias -hook -button6\n");