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 void RemoveGrapplingHook(entity pl)
56 if(pl.movetype == MOVETYPE_FLY)
57 pl.movetype = MOVETYPE_WALK;
59 pl.hook_time = time + 0.0;
62 void GrapplingHookThink()
64 float spd, dist, minlength, pullspeed;
66 if(self.owner.health <= 0 || self.owner.hook != self) // how did that happen?
67 { // well, better fix it anyway
72 self.nextthink = time + 0.1;
74 makevectors(self.owner.v_angle);
75 org = self.owner.origin + self.owner.view_ofs + v_forward * 15 - v_right * 5 + v_up * -12;
79 pullspeed = cvar("g_balance_grapplehook_speed_pull");//1000;
81 dir = self.origin - org;
85 end = self.origin - dir*minlength;
87 dist = vlen(end - org);
90 spd = dist * (pullspeed / 200);
96 self.owner.velocity = dir*spd;
97 self.owner.movetype = MOVETYPE_FLY;
98 self.owner.flags = self.owner.flags - (self.owner.flags & FL_ONGROUND);
100 org = org + dir*50; // get the beam out of the player's eyes
103 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
104 WriteByte (MSG_BROADCAST, TE_BEAM);
105 WriteEntity (MSG_BROADCAST, self);
106 WriteCoord (MSG_BROADCAST, self.origin_x);
107 WriteCoord (MSG_BROADCAST, self.origin_y);
108 WriteCoord (MSG_BROADCAST, self.origin_z);
109 WriteCoord (MSG_BROADCAST, org_x);
110 WriteCoord (MSG_BROADCAST, org_y);
111 WriteCoord (MSG_BROADCAST, org_z);
114 void GrapplingHookTouch (void)
116 if (other == self.owner)
118 else if (pointcontents (self.origin) == CONTENT_SKY)
120 RemoveGrapplingHook(self.owner);
124 self.event_damage = SUB_Null; // fixme: ability to dislodge a player by damaging hook?
125 sound (self, CHAN_BODY, "weapons/hook_impact.ogg", 1, ATTN_NORM);
128 self.think = GrapplingHookThink;
129 self.nextthink = time + 0.1;
130 self.touch = SUB_Null;
131 self.velocity = '0 0 0';
132 self.movetype = MOVETYPE_NONE;
135 void FireGrapplingHook (void)
137 local entity missile;
140 makevectors(self.v_angle);
142 sound (self, CHAN_WEAPON, "weapons/hook_fire.ogg", 1, ATTN_NORM);
143 org = self.origin + self.view_ofs + v_forward * 15 - v_right * 5 + v_up * -12;
144 te_customflash(org, 160, 0.2, '1 0 0');
147 missile.owner = self;
149 missile.classname = "laserbolt";
151 missile.movetype = MOVETYPE_FLY;
152 missile.solid = SOLID_BBOX;
154 setmodel (missile, "models/ebomb.mdl");//laser.mdl");
155 setsize (missile, '0 0 0', '0 0 0');
156 setorigin (missile, org);
158 missile.state = 0; // not latched onto anything
160 missile.velocity = v_forward * cvar("g_balance_grapplehook_speed_fly");
161 missile.angles = vectoangles (missile.velocity);
162 //missile.glow_color = 250; // 244, 250
163 //missile.glow_size = 120;
164 missile.touch = GrapplingHookTouch;
165 missile.think = GrapplingHookThink;
166 missile.nextthink = time + 0.1;
168 missile.effects = EF_FULLBRIGHT | EF_ADDITIVE | EF_LOWPRECISION;
171 void GrapplingHookFrame()
173 // if I have no hook or it's not pulling yet, make sure I'm not flying!
174 if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
176 self.movetype = MOVETYPE_WALK;
178 if(self.impulse == GRAPHOOK_FIRE && self.hook_time <= time && cvar("g_grappling_hook"))
184 else if(self.impulse == GRAPHOOK_RELEASE)
186 // remove hook, reset movement type
187 RemoveGrapplingHook(self);
190 /*else // make sure the player's movetype is correct
192 //if(self.hook == world && self.movetype == MOVETYPE_FLY)
193 if((self.hook == world || !self.hook.state) && self.movetype == MOVETYPE_FLY)
195 self.movetype = MOVETYPE_WALK;
198 // note: The hook entity does the actual pulling
201 void SetGrappleHookBindings()
203 stuffcmd(self, strcat("alias +hook \"impulse ", ftos(GRAPHOOK_FIRE), "\"\n"));
204 stuffcmd(self, strcat("alias -hook \"impulse ", ftos(GRAPHOOK_RELEASE), "\"\n"));