Raised This Month: $ Target: $400
 0% 

Problem with getting thickness


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-18-2015 , 11:41   Problem with getting thickness
Reply With Quote #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(PLUGINVERSIONAUTHOR)
    
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(idprint_center"%f"getWallThickness1(id)/39.37)
}

public 
wallthick2(id)
{
    static 
Float:StartOrigin[3], Float:Angle[3], Float:a[3]
    
    
engfunc(EngFunc_GetAttachmentid0StartOrigina)
    
    
entity_get_vector(idEV_VEC_v_angleAngle)
    
Angle[0] = Angle[0] * -1.0
    
new BulletEnt create_entity("info_target")

    
entity_set_string(BulletEntEV_SZ_classname"bullet")
    
entity_set_model(BulletEnt"sprites/yelflare2.spr")
    
entity_set_origin(BulletEntStartOrigin)
    
entity_set_vector(BulletEntEV_VEC_anglesAngle)
            
    new 
Float:MinBox[3] = {-1.0, -1.0, -1.0}
    new 
Float:MaxBox[3] = {1.01.01.0}
    
entity_set_vector(BulletEntEV_VEC_minsMinBox)
    
entity_set_vector(BulletEntEV_VEC_maxsMaxBox)
            
    
entity_set_int(BulletEntEV_INT_solidSOLID_BBOX)
    
entity_set_int(BulletEntEV_INT_movetypeMOVETYPE_FLY)
    
entity_set_edict(BulletEntEV_ENT_ownerid)
    
entity_set_int(BulletEntEV_INT_rendermodekRenderTransAdd)
    
entity_set_float(BulletEntEV_FL_renderamt100.0)
            
    new 
Float:Velocity[3], vec
    vec 
random_num(25100)
    
//get_speed_vector(StartOrigin, EndOrigin, 5.0, Velocity)
    
velocity_by_aim(idvecVelocity)
    
entity_set_vector(BulletEntEV_VEC_vuser1Velocity)
    
entity_set_vector(BulletEntEV_VEC_velocityVelocity)
    
client_print(idprint_chat"%i"vec)
}

public 
fw_bullet_touch(Enttouch)
{
    if(!
is_valid_ent(Ent))
        return
        
    static 
owner
    owner 
entity_get_edict(EntEV_ENT_owner)
    if(
touch == owner)
        return
        
    
client_print(ownerprint_center"%f"getWallThickness2(Entowner)/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
    
pevplayerpev_originsource );
    
pevplayerpev_view_ofsdirection );
    
xs_vec_addsourcedirectionsource );
    
    
// Get eyes direction
    
pevplayerpev_v_angledirection );
    
engfuncEngFunc_MakeVectorsdirection );
    
global_getglb_v_forwarddirection );
    
    
// Get the end direction from eyes
    
xs_vec_mul_scalardirection9999.0end );
    
xs_vec_addsourceendend );
   
    
engfuncEngFunc_TraceLinesourceendDONT_IGNORE_MONSTERSplayer);
    
    
// Get the fraction of the trace
    
get_tr20TR_flFractionfraction );
    
    
// 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_tr20TR_vecEndPosend );
    
//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_scalardirection2.0direction );
    
xs_vec_addenddirectionsource );
    
    
// Get the end position from inside the wall to far behind.
    
xs_vec_mul_scalardirection9999.0direction );
    
xs_vec_addsourcedirectionend );
    
    
engfuncEngFunc_TraceLinesourceendDONT_IGNORE_MONSTERSplayer);
    
    
// Get the fraction of the trace
    
get_tr20TR_flFractionfraction );

    
// No hit or no free space
    
if( fraction == 1.0 || get_tr20TR_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_tr20TR_vecEndPossource );
    
   
// drawBeam( source, end, 50, 200, 50 );

    
engfuncEngFunc_TraceLinesourceendDONT_IGNORE_MONSTERSplayer);
    
    
// Get the end position just behind the wall.
    
get_tr20TR_vecEndPosend );
    
  
//  drawBeam( source, end, 50, 50, 200 );
    
    // Get the thickness of the wall.
    
return vector_distanceendendOrig );
}

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(EntEV_VEC_originend)
    
endOrig end;

    
// Get new start position by moving inside the wall a bit.
    
entity_get_vector(EntEV_VEC_vuser1direction)
    
vector_to_angle(directiondirection)
    
xs_vec_mul_scalardirection2.0direction );
    
xs_vec_addenddirectionsource );
    
    
// Get the end position from inside the wall to far behind.
    
xs_vec_mul_scalardirection9999.0direction );
    
xs_vec_addsourcedirectionend );
    
    
engfuncEngFunc_TraceLinesourceendDONT_IGNORE_MONSTERSplayer);
    
    
// Get the fraction of the trace
    
get_tr20TR_flFractionfraction );

    
// No hit or no free space
    
if( fraction == 1.0 || get_tr20TR_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_tr20TR_vecEndPossource );
    
   
// drawBeam( source, end, 50, 200, 50 );

    
engfuncEngFunc_TraceLinesourceendDONT_IGNORE_MONSTERSplayer);
    
    
// Get the end position just behind the wall.
    
get_tr20TR_vecEndPosend );
    
  
//  drawBeam( source, end, 50, 50, 200 );
    
    // Get the thickness of the wall.
    
return vector_distanceendendOrig );

Please help
Thanks

Last edited by RateX; 01-18-2015 at 11:41.
RateX is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-18-2015 , 12:44   Re: Problem with getting thickness
Reply With Quote #2

It would help to link to the original thread from where you get the code: https://forums.alliedmods.net/showthread.php?t=245240

Your problem is with fire2 and fire1 is working fine ?
__________________
HamletEagle is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-18-2015 , 13:02   Re: Problem with getting thickness
Reply With Quote #3

^Yes, you got it.

Last edited by RateX; 01-18-2015 at 13:04.
RateX is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-02-2015 , 10:53   Re: Problem with getting thickness
Reply With Quote #4

Bump -.-
__________________
Currently offline for study.
RateX is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 03-03-2015 , 05:03   Re: Problem with getting thickness
Reply With Quote #5

There is a plugin something like "Walk through walls" which is calculating thickness of walls .. Maybe you can look ito that code to see how the author is calculating that..
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !

#RespectList ANTICHRISTUS fysiks Bugsy

Most Common Errors You Can Encounter Every Now and Then
devilicioux is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode