// by daemonicky // comments are translated // I may have put some errors while dumping this code // I apologize for them void() PlayerPostThink = { if (PlayerDoGrab(PLAYER_RADIUS)) { // player grabbed onto ledge or something ... // // declarations and globals // float GRAB_EYE_UP = 10; // how much from origin eye is float GRAB_HAND_UP = 15; // how much from origin hand is float PLAYER_LEGS = 24; float PLAYER_RADIUS = 32; float PLAYER_HEIGHT = 56;//24 /* PLAYER_LEGS */+ 32; float grab_can; float grab_z; float(vector _origin, float _radius, vector _angles) PlayerCanGrabOne; float(vector _origin, float _radius, float _n) PlayerCanGrabAround; .... float(float _radius/*hack*/) PlayerDoGrab = { // the grabbing itself if (grab_can) { // there is a chance it is safe and // does not causes problems // i do not know for sure if (TRUE) { local vector SafeOrigin; SafeOrigin = self.origin; SafeOrigin_z = grab_z; setorigin(self,SafeOrigin); } else { // unsafe self.origin_z = grab_z; } self.velocity_z = 0; // gravitation is always applied so do this // TODO: make it less rigid self.velocity = self.velocity * 0.5; } // always test if (PlayerCanGrab(_radius/*hack*/)) { // for first time- turned on if (!grab_can) { // it was set grab_can = TRUE; // remember height grab_z = self.origin_z; PlayerStop(); // possible alternative : self.movetype = MOVETYPE_FLY; } } else { grab_can = FALSE; } return grab_can; } float(float _radius/*hack*/) PlayerCanGrab = { return PlayerCanGrabAround(self.origin, _radius/*hack*/, 4 * 4); // was threre, but not so cool // return PlayerCanGrabOne(self.origin, _radius/*hack*/, self.angles); }; float(vector _origin, float _radius, vector _angles) PlayerCanGrabOne = { local vector Eye; local vector Hand; // remove pitch /* v_forward = */ makevectors('0 1 0' * _angles_y + '0 0 1' * _angles_z); // Eye = _origin + v_forward*_radius + v_up *GRAB_EYE_UP; Hand = Eye; Hand_z += GRAB_HAND_UP; if (FALSE) // debug { particle(Hand, '0 0 0', 1, 10); particle(Eye, '0 0 0', 2, 10); } // eye is inside wall traceline(_origin, Eye, TRUE, self); if (trace_fraction == 1.0) // return FALSE; // hand is free traceline(_origin, Hand, TRUE, self); if (trace_fraction != 1.0) { return FALSE; } //bprint(" grab"); return TRUE; } float(vector _origin, float _radius, float _n) PlayerCanGrabAround = { local vector v = '0 0 0'; while(v_y < 360) { if (PlayerCanGrabOne(_origin, _radius, v)) return TRUE; v_y += 360/_n; } return FALSE; }