Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
|
01-18-2015
, 11:41
Problem with getting thickness
|
#1
|
My purpose when making this plugin is to see if I can get thickness when an entity collide with anything in game(command "/fire2"). In theory, it should work. However, when I test, the result are almost always 0.0 or a very large float, much larger than the result given by using player aim (command "/fire1"). I couldn't see what's wrong.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx> #include <fakemeta> #include <engine> #include <xs>
#define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "author"
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_clcmd("/fire1", "wallthick1") register_clcmd("/fire2", "wallthick2") register_touch("bullet", "*", "fw_bullet_touch") }
public plugin_precache() { precache_model("sprites/yelflare2.spr") }
public wallthick1(id) { client_print(id, print_center, "%f", getWallThickness1(id)/39.37) }
public wallthick2(id) { static Float:StartOrigin[3], Float:Angle[3], Float:a[3] engfunc(EngFunc_GetAttachment, id, 0, StartOrigin, a) entity_get_vector(id, EV_VEC_v_angle, Angle) Angle[0] = Angle[0] * -1.0 new BulletEnt = create_entity("info_target")
entity_set_string(BulletEnt, EV_SZ_classname, "bullet") entity_set_model(BulletEnt, "sprites/yelflare2.spr") entity_set_origin(BulletEnt, StartOrigin) entity_set_vector(BulletEnt, EV_VEC_angles, Angle) new Float:MinBox[3] = {-1.0, -1.0, -1.0} new Float:MaxBox[3] = {1.0, 1.0, 1.0} entity_set_vector(BulletEnt, EV_VEC_mins, MinBox) entity_set_vector(BulletEnt, EV_VEC_maxs, MaxBox) entity_set_int(BulletEnt, EV_INT_solid, SOLID_BBOX) entity_set_int(BulletEnt, EV_INT_movetype, MOVETYPE_FLY) entity_set_edict(BulletEnt, EV_ENT_owner, id) entity_set_int(BulletEnt, EV_INT_rendermode, kRenderTransAdd) entity_set_float(BulletEnt, EV_FL_renderamt, 100.0) new Float:Velocity[3], vec vec = random_num(25, 100) //get_speed_vector(StartOrigin, EndOrigin, 5.0, Velocity) velocity_by_aim(id, vec, Velocity) entity_set_vector(BulletEnt, EV_VEC_vuser1, Velocity) entity_set_vector(BulletEnt, EV_VEC_velocity, Velocity) client_print(id, print_chat, "%i", vec) }
public fw_bullet_touch(Ent, touch) { if(!is_valid_ent(Ent)) return static owner owner = entity_get_edict(Ent, EV_ENT_owner) if(touch == owner) return client_print(owner, print_center, "%f", getWallThickness2(Ent, owner)/39.37) remove_entity(Ent) }
Float:getWallThickness1( const player ) { /* TRACELINE #1 : Player's eyes to wall. */ server_print( "START TRACELINE #1" ); new Float:source[3], Float:direction[3], Float:end[3], Float:endOrig[3]; new Float:fraction; // Get eyes position pev( player, pev_origin, source ); pev( player, pev_view_ofs, direction ); xs_vec_add( source, direction, source ); // Get eyes direction pev( player, pev_v_angle, direction ); engfunc( EngFunc_MakeVectors, direction ); global_get( glb_v_forward, direction ); // Get the end direction from eyes xs_vec_mul_scalar( direction, 9999.0, end ); xs_vec_add( source, end, end ); engfunc( EngFunc_TraceLine, source, end, DONT_IGNORE_MONSTERS, player, 0 ); // Get the fraction of the trace get_tr2( 0, TR_flFraction, fraction ); // No hit if( fraction == 1.0 ) { return 0.0; }
/* TRACELINE #2 : Inside wall to behind wall to check if there is free space*/ server_print( "START TRACELINE #2" ); // Get the end position the trace hits. get_tr2( 0, TR_vecEndPos, end ); //get_tr2( 0, TR_vecPlaneNormal, direction ); // drawBeam( source, end, 200, 50, 50 ); // Save this position so we can calculate the thickness later. endOrig = end;
// Get new start position by moving inside the wall a bit. xs_vec_mul_scalar( direction, 2.0, direction ); xs_vec_add( end, direction, source ); // Get the end position from inside the wall to far behind. xs_vec_mul_scalar( direction, 9999.0, direction ); xs_vec_add( source, direction, end ); engfunc( EngFunc_TraceLine, source, end, DONT_IGNORE_MONSTERS, player, 0 ); // Get the fraction of the trace get_tr2( 0, TR_flFraction, fraction );
// No hit or no free space if( fraction == 1.0 || get_tr2( 0, TR_AllSolid ) ) { return 0.0; } /* TRACELINE #3 : From behind the wall to back inside the wall to know the */ server_print( "START TRACELINE #3" ); // The end position of the next trace is the start position of the previous trace. // Get the end position the trace hits which is the start position of next trace. end = source; get_tr2( 0, TR_vecEndPos, source ); // drawBeam( source, end, 50, 200, 50 );
engfunc( EngFunc_TraceLine, source, end, DONT_IGNORE_MONSTERS, player, 0 ); // Get the end position just behind the wall. get_tr2( 0, TR_vecEndPos, end ); // drawBeam( source, end, 50, 50, 200 ); // Get the thickness of the wall. return vector_distance( end, endOrig ); }
Float:getWallThickness2( const Ent, const player ) { /* TRACELINE #1 : Player's eyes to wall. */ //server_print( "START TRACELINE #1" ); new Float:source[3], Float:direction[3], Float:end[3], Float:endOrig[3]; new Float:fraction; // Get eyes position //pev( player, pev_origin, source ); // pev( player, pev_view_ofs, direction ); //xs_vec_add( source, direction, source ); // Get eyes direction //pev( player, pev_v_angle, direction ); // engfunc( EngFunc_MakeVectors, direction ); //global_get( glb_v_forward, direction ); // Get the end direction from eyes //xs_vec_mul_scalar( direction, 9999.0, end ); //xs_vec_add( source, end, end ); //engfunc( EngFunc_TraceLine, source, end, DONT_IGNORE_MONSTERS, player, 0 ); // Get the fraction of the trace // get_tr2( 0, TR_flFraction, fraction ); // No hit //if( fraction == 1.0 ) //{ // return 0.0; //}
/* TRACELINE #2 : Inside wall to behind wall to check if there is free space*/ server_print( "START TRACELINE #2" ); // Get the end position the trace hits. //get_tr2( 0, TR_vecEndPos, end ); //get_tr2( 0, TR_vecPlaneNormal, direction ); // drawBeam( source, end, 200, 50, 50 ); // Save this position so we can calculate the thickness later. entity_get_vector(Ent, EV_VEC_origin, end) endOrig = end;
// Get new start position by moving inside the wall a bit. entity_get_vector(Ent, EV_VEC_vuser1, direction) vector_to_angle(direction, direction) xs_vec_mul_scalar( direction, 2.0, direction ); xs_vec_add( end, direction, source ); // Get the end position from inside the wall to far behind. xs_vec_mul_scalar( direction, 9999.0, direction ); xs_vec_add( source, direction, end ); engfunc( EngFunc_TraceLine, source, end, DONT_IGNORE_MONSTERS, player, 0 ); // Get the fraction of the trace get_tr2( 0, TR_flFraction, fraction );
// No hit or no free space if( fraction == 1.0 || get_tr2( 0, TR_AllSolid ) ) { return 0.0; } /* TRACELINE #3 : From behind the wall to back inside the wall to know the */ server_print( "START TRACELINE #3" ); // The end position of the next trace is the start position of the previous trace. // Get the end position the trace hits which is the start position of next trace. end = source; get_tr2( 0, TR_vecEndPos, source ); // drawBeam( source, end, 50, 200, 50 );
engfunc( EngFunc_TraceLine, source, end, DONT_IGNORE_MONSTERS, player, 0 ); // Get the end position just behind the wall. get_tr2( 0, TR_vecEndPos, end ); // drawBeam( source, end, 50, 50, 200 ); // Get the thickness of the wall. return vector_distance( end, endOrig ); }
Please help
Thanks
Last edited by RateX; 01-18-2015 at 11:41.
|
|