Senior Member
|
03-09-2009
, 21:04
Re: Doing ladder
|
#18
|
Quote:
Originally Posted by ConnorMcLeod
Stand by.
Was simply copy/pasting laddermove code from HLSDK, gonna share what i'v done so anyone can work on it.
Code:
void PM_LadderMove( physent_t *pLadder )
{
vec3_t ladderCenter;
trace_t trace;
qboolean onFloor;
vec3_t floor;
vec3_t modelmins, modelmaxs;
if ( pmove->movetype == MOVETYPE_NOCLIP )
return;
pmove->PM_GetModelBounds( pLadder->model, modelmins, modelmaxs );
VectorAdd( modelmins, modelmaxs, ladderCenter );
VectorScale( ladderCenter, 0.5, ladderCenter );
pmove->movetype = MOVETYPE_FLY;
// On ladder, convert movement to be relative to the ladder
VectorCopy( pmove->origin, floor );
floor[2] += pmove->player_mins[pmove->usehull][2] - 1;
if ( pmove->PM_PointContents( floor, NULL ) == CONTENTS_SOLID )
onFloor = true;
else
onFloor = false;
pmove->gravity = 0;
pmove->PM_TraceModel( pLadder, pmove->origin, ladderCenter, &trace );
if ( trace.fraction != 1.0 )
{
float forward = 0, right = 0;
vec3_t vpn, v_right;
AngleVectors( pmove->angles, vpn, v_right, NULL );
if ( pmove->cmd.buttons & IN_BACK )
forward -= MAX_CLIMB_SPEED;
if ( pmove->cmd.buttons & IN_FORWARD )
forward += MAX_CLIMB_SPEED;
if ( pmove->cmd.buttons & IN_MOVELEFT )
right -= MAX_CLIMB_SPEED;
if ( pmove->cmd.buttons & IN_MOVERIGHT )
right += MAX_CLIMB_SPEED;
if ( pmove->cmd.buttons & IN_JUMP )
{
pmove->movetype = MOVETYPE_WALK;
VectorScale( trace.plane.normal, 270, pmove->velocity );
}
else
{
if ( forward != 0 || right != 0 )
{
vec3_t velocity, perp, cross, lateral, tmp;
float normal;
//ALERT(at_console, "pev %.2f %.2f %.2f - ",
// pev->velocity.x, pev->velocity.y, pev->velocity.z);
// Calculate player's intended velocity
//Vector velocity = (forward * gpGlobals->v_forward) + (right * gpGlobals->v_right);
VectorScale( vpn, forward, velocity );
VectorMA( velocity, right, v_right, velocity );
// Perpendicular in the ladder plane
// Vector perp = CrossProduct( Vector(0,0,1), trace.vecPlaneNormal );
// perp = perp.Normalize();
VectorClear( tmp );
tmp[2] = 1;
CrossProduct( tmp, trace.plane.normal, perp );
VectorNormalize( perp );
// decompose velocity into ladder plane
normal = DotProduct( velocity, trace.plane.normal );
// This is the velocity into the face of the ladder
VectorScale( trace.plane.normal, normal, cross );
// This is the player's additional velocity
VectorSubtract( velocity, cross, lateral );
// This turns the velocity into the face of the ladder into velocity that
// is roughly vertically perpendicular to the face of the ladder.
// NOTE: It IS possible to face up and move down or face down and move up
// because the velocity is a sum of the directional velocity and the converted
// velocity through the face of the ladder -- by design.
CrossProduct( trace.plane.normal, perp, tmp );
VectorMA( lateral, -normal, tmp, pmove->velocity );
if ( onFloor && normal > 0 ) // On ground moving away from the ladder
{
VectorMA( pmove->velocity, MAX_CLIMB_SPEED, trace.plane.normal, pmove->velocity );
}
//pev->velocity = lateral - (CrossProduct( trace.vecPlaneNormal, perp ) * normal);
}
else
{
VectorClear( pmove->velocity );
}
}
}
}
PHP Code:
/* Copyright © 2008, ConnorMcLeod
Ladder Test is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ladder Test; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <amxmodx> #include <fakemeta> #include <hamsandwich> #include <xs>
#define PLUGIN "Ladder Test" #define AUTHOR "ConnorMcLeod" #define VERSION "0.0.1"
#define MAX_CLIMB_SPEED 200.0
new gOnLadder[33];
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Touch, "func_wall", "World_Touch") RegisterHam(Ham_Touch, "func_breakable", "World_Touch") // RegisterHam(Ham_Touch, "worldspawn", "World_Touch")
register_forward( FM_PlayerPostThink , "PlayerPostThink") }
public World_Touch(iEnt, id) { if( !is_user_alive(id) ) { return }
if( pev(id, pev_groundentity) == iEnt ) { return } gOnLadder[id] = iEnt }
public PlayerPostThink(id) { if( !gOnLadder[id] || pev(id, pev_movetype) == MOVETYPE_NOCLIP) { return }
static pLadder ; pLadder = gOnLadder[id] static bool:onFloor static Float:modelmins[3], Float:modelmaxs[3], Float:ladderCenter[3], Float:floor[3], Float:origin[3]
pev(pLadder, pev_mins, modelmins) pev(pLadder, pev_maxs, modelmaxs) xs_vec_add( modelmins, modelmaxs, ladderCenter ); xs_vec_mul_scalar( ladderCenter, 0.5, ladderCenter );
set_pev(id, pev_movetype, MOVETYPE_FLY)
pev( id, pev_origin, origin ) xs_vec_copy(origin, floor) pev(id, pev_mins, modelmins) floor[2] += modelmins[2] - 1
if ( engfunc( EngFunc_PointContents, floor ) == CONTENTS_SOLID ) onFloor = true; else onFloor = false;
//set_pev(id, pev_gravity, 0.0) // useless ?
//PM_TraceModel( pLadder, pmove->origin, ladderCenter, &trace ) // engfunc(EngFunc_TraceModel, origin, ladderCenter, HULL_HUMAN, pLadder, 0);
static Float:flTraceFraction global_get( glb_trace_fraction, flTraceFraction ) if ( flTraceFraction == 1.0 ) return
static iButton ; iButton = pev(id, pev_button) static Float:flVelocity[3]
static Float:_forward, Float:right static Float:vpn[3], Float:v_right[3]; _forward = 0.0 right = 0.0
new Float:flAngles[3] pev(id, pev_angles, flAngles) engfunc(EngFunc_AngleVectors, flAngles, vpn, v_right, 0.0);
if ( iButton & IN_BACK ) _forward -= MAX_CLIMB_SPEED; if ( iButton & IN_FORWARD ) _forward += MAX_CLIMB_SPEED; if ( iButton & IN_MOVELEFT ) right -= MAX_CLIMB_SPEED; if ( iButton & IN_MOVERIGHT ) right += MAX_CLIMB_SPEED;
new Float:flTracePlaneNormal[3] if ( iButton & IN_JUMP ) { set_pev(id, pev_movetype, MOVETYPE_WALK) global_get(glb_trace_plane_normal, flTracePlaneNormal) xs_vec_mul_scalar(flTracePlaneNormal, 270.0, flVelocity) set_pev(id, pev_velocity, flVelocity) } else { if( _forward || right ) { static Float:velocity[3], Float:perp[3], Float:cross[3], Float:lateral[3], Float:tmp[3] static Float:normal
xs_vec_mul_scalar(vpn, _forward, velocity) VectorMA( velocity, right, v_right, velocity )
tmp[0] = 0.0 tmp[1] = 0.0 tmp[2] = 1.0; global_get(glb_trace_plane_normal, flTracePlaneNormal) xs_vec_cross( tmp, flTracePlaneNormal, perp ); xs_vec_normalize(perp, perp)
// decompose velocity into ladder plane normal = xs_vec_dot( velocity, flTracePlaneNormal ); // This is the velocity into the face of the ladder xs_vec_mul_scalar(flTracePlaneNormal, normal, cross)
// This is the player's additional velocity xs_vec_sub( velocity, cross, lateral );
// This turns the velocity into the face of the ladder into velocity that // is roughly vertically perpendicular to the face of the ladder. // NOTE: It IS possible to face up and move down or face down and move up // because the velocity is a sum of the directional velocity and the converted // velocity through the face of the ladder -- by design. xs_vec_cross(flTracePlaneNormal, perp, tmp) VectorMA( lateral, -normal, tmp, velocity ); if ( onFloor && normal > 0 ) // On ground moving away from the ladder { VectorMA( velocity, MAX_CLIMB_SPEED, flTracePlaneNormal, velocity ); } set_pev(id, pev_velocity, velocity) } else { set_pev(id, pev_velocity, Float:{0.0,0.0,0.0}) return } } gOnLadder[id] = 0 }
VectorMA(const Float:veca[3], Float:scale, const Float:vecb[3], Float:vecc[3]) { vecc[0] = veca[0] + scale*vecb[0]; vecc[1] = veca[1] + scale*vecb[1]; vecc[2] = veca[2] + scale*vecb[2]; }
|
GJ! but how can we create it? like can u make something like /bm. like if we type /ladder we can make and and have move_ladder bind so we can move it.
|
|