Raised This Month: $51 Target: $400
 12% 

Touching entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 03-04-2012 , 03:35   Touching entities
Reply With Quote #1

I create some entity with TE_BEAMPOINTS message, and now I want to check if the line of My custom entity is touching a custom entity (like func_door).

Here my partial code:

PHP Code:
    static iHitiTrFloat:fFraction
    engfunc
EngFunc_TraceLinefOriginfOriginEndDONT_IGNORE_MONSTERSiEntiTr )

    
get_tr2iTrTR_flFractionfFraction )
    
iHit get_tr2iTrTR_pHit )

    if( 
fFraction 1.0 )
    {
        static 
szClassName64 ]
        
peviEntpev_classnameszClassNamecharsmaxszClassName ) )
    
        if( 
equalszClassName"func_door_rotating" ) || equalszClassName"func_door" ) )
            
// my code..
    

but always is return iHit = -1, but if I test iHit on valid player is return valid iHit, only iHit is returned -1 when I try to check if touching another entities.

I think I must to use fOriginEnd position to check if touching custom entities, but I don't know how to do that.

Thanks in advance.

Last edited by dFF; 03-04-2012 at 03:37.
dFF is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 03-04-2012 , 05:02   Re: Touching entities
Reply With Quote #2

I made this a while ago.
Whenever you hold your +use key. You will draw the X, Y and Z axis in front of you which extends out 50 units to either side. If an axis does not stretch out 50 units then it will create a spark to tell you that there is something blocking the traceline from the center of the axis.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <engine>
#include <xs>

new BeamSprite;

public 
plugin_init( )
{
    
register_plugin"Trace Normal""1.0""Mazza" );

    
register_forwardFM_CmdStart"Forward_CmdStart" );
}

public 
plugin_precache()
{
    
BeamSprite precache_model("sprites/zbeam1.spr");
}

public 
Forward_CmdStart(iduc_handleseed)
{
    if(!
is_user_alive(id))
        return;

    static 
iButtoniButton get_ucuc_handleUC_Buttons );
    static 
oldButton oldButton pev(idpev_oldbuttons);
    
    if( (
iButton IN_USE) && (oldButton IN_USE))
    {
        new 
Float:fAim[3],Float:fAngles[3],Float:fOrigin[3], FloatfAimOrigin[3], iOrigin[3];
        
        
get_user_origin(idiOrigin1);
        
IVecFVec(iOriginfOrigin);
        
// pev(id,pev_origin,fOrigin) 
        
velocity_by_aim(id300fAim
        
vector_to_angle(fAim,fAngles
        
        
fAimOrigin[0] = fOrigin[0] + fAim[0
        
fAimOrigin[1] = fOrigin[1] + fAim[1
        
fAimOrigin[2] = fOrigin[2] + fAim[2
        
        new 
count;
        
        static 
FloatvTarget[6][3];
        
        for(
count 0count count++)
        {
            
xs_vec_copy(fAimOriginvTarget[count]);
        }
        
        new 
FloatfConstant 50.0;
        
        for(
count count count++)
        {
            switch(
count)
            {
                case 
0:
                    
vTarget[count][0] -= fConstant;
                case 
1:
                    
vTarget[count][0] += fConstant;
                case 
2:
                    
vTarget[count][1] -= fConstant;
                case 
3:
                    
vTarget[count][1] += fConstant;
                case 
4:
                    
vTarget[count][2] -= fConstant;
                case 
5:
                    
vTarget[count][2] += fConstant;
            }
        }
        
        for(
count count count++)
        {
            if(
point_contents(vTarget[count]) != CONTENTS_EMPTY)
                
client_print(idprint_center"Collision Detected");
            
            
engfunc(EngFunc_TraceLinefAimOriginvTarget[count], IGNORE_MONSTERSid0)
            static 
Float:flFraction
            get_tr2
(0TR_flFractionflFraction)
            if( 
flFraction != 1.0 )
            {
                
flFraction *= fConstant
                
switch(count)
                {
                    case 
0:
                        
vTarget[count][0] = fAimOrigin[0] - flFraction;
                    case 
1:
                        
vTarget[count][0] = fAimOrigin[0] + flFraction;
                    case 
2:
                        
vTarget[count][1] = fAimOrigin[1] - flFraction;
                    case 
3:
                        
vTarget[count][1] = fAimOrigin[1] + flFraction;
                    case 
4:
                        
vTarget[count][2] = fAimOrigin[2] - flFraction;
                    case 
5:
                        
vTarget[count][2] = fAimOrigin[2] + flFraction;
                }
                
                
UTIL_DrawSparks(vTarget[count]);
            } 
        }
        
        for(
count count count++)
        {
            new 
iColorRGB[3];
            
            switch(
count)
            {
                case 
01:
                    
iColorRGB[0] = 200;
                case 
23:
                    
iColorRGB[1] = 200;
                case 
45:
                    
iColorRGB[2] = 200;
            }
            
            
UTIL_DrawLine(fAimOriginvTarget[count], iColorRGB[0], iColorRGB[1], iColorRGB[2], 1);    
            
            static 
Floatmins[3]; xs_vec_set(mins, -fConstant, -fConstant, -fConstant);
            static 
Floatmaxs[3]; xs_vec_set(maxsfConstantfConstantfConstant);
            
            
xs_vec_add(minsfAimOriginmins);
            
xs_vec_add(maxsfAimOriginmaxs);
            
            
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
            
write_byte(TE_BOX)
            
engfunc(EngFunc_WriteCoordmins[0])
            
engfunc(EngFunc_WriteCoordmins[1])
            
engfunc(EngFunc_WriteCoordmins[2])
            
engfunc(EngFunc_WriteCoordmaxs[0])
            
engfunc(EngFunc_WriteCoordmaxs[1])
            
engfunc(EngFunc_WriteCoordmaxs[2])
            
write_short(1)
            
write_byte(200)
            
write_byte(200)
            
write_byte(200)
            
message_end()
        }
    }
}

stock UTIL_DrawLine(FloatstartOrigin[3], FloatendOrigin[3], redgreenbluelife)
{
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(TE_BEAMPOINTS)
    
engfunc(EngFunc_WriteCoordstartOrigin[0])
    
engfunc(EngFunc_WriteCoordstartOrigin[1])
    
engfunc(EngFunc_WriteCoordstartOrigin[2])
    
engfunc(EngFunc_WriteCoordendOrigin[0])
    
engfunc(EngFunc_WriteCoordendOrigin[1])
    
engfunc(EngFunc_WriteCoordendOrigin[2])
    
write_short(BeamSprite)
    
write_byte(1)
    
write_byte(5)
    
write_byte(life)
    
write_byte(20)
    
write_byte(0)
    
write_byte(red)
    
write_byte(green)
    
write_byte(blue)
    
write_byte(200)
    
write_byte(200)
    
message_end()
}

stock UTIL_DrawSparks(FloatfOrigin[3])
{
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(TE_SPARKS)
    
engfunc(EngFunc_WriteCoordfOrigin[0])
    
engfunc(EngFunc_WriteCoordfOrigin[1])
    
engfunc(EngFunc_WriteCoordfOrigin[2])
    
message_end()


Screenshots provided below to help with my explanation.

Hopefully the script above will provide the help you need to fix your issue.
Attached Thumbnails
Click image for larger version

Name:	2012-03-04_00002.jpg
Views:	141
Size:	90.2 KB
ID:	100143   Click image for larger version

Name:	2012-03-04_00003.jpg
Views:	121
Size:	92.1 KB
ID:	100144   Click image for larger version

Name:	2012-03-04_00004.jpg
Views:	132
Size:	89.7 KB
ID:	100145  
__________________
It's a mystery.
Mini_Midget is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 03-04-2012 , 08:07   Re: Touching entities
Reply With Quote #3

Thanks for the reply.

I tried to extract you're code in this short:

PHP Code:
    static iTest
    iTest 
TryDedectiEnt )
    if( 
iTest )
    {
        
// no problem here, passed ok.
        // my code...
    
}

-----------
TryDedectiEnt )
{
    static 
Float:fOrigin]
    
peviEntpev_endoriginfOrigin )
    
    new 
count;
    
    static 
FloatvTarget[6][3];
    
    for(
count 0count count++)
    {
        
xs_vec_copy(fOriginvTarget[count]);
    }
    
    new 
FloatfConstant 50.0;
        
    for(
count count count++)
    {
        switch(
count)
        {
            case 
0vTarget[count][0] -= fConstant;
            case 
1vTarget[count][0] += fConstant;
            case 
2vTarget[count][1] -= fConstant;
            case 
3vTarget[count][1] += fConstant;
            case 
4vTarget[count][2] -= fConstant;
            case 
5vTarget[count][2] += fConstant;
        }
    }
        
    for(
count count count++)
    {
        if(
point_contents(vTarget[count]) != CONTENTS_EMPTY)
            
client_print(0print_center"Collision Detected!!"); // It's ok, printed the message.
        
        // NOW, Here it's the problem, I don't know why!
        
engfunc(EngFunc_TraceLinefOriginvTarget[count], IGNORE_MONSTERSiEnt0)
        static 
Float:flFractioniHit
        get_tr2
(0TR_flFractionflFraction)
        
iHit get_tr20TR_pHit )
        
        if( 
flFraction != 1.0 )
        {
            if( 
IsTouchingEntsiHit ) )
                return 
iHit
        
}
    }
    
    return 
0
}

IsTouchingEntsiEnt )
{
    if( !
pev_validiEnt ) )
        return 
0
        
    
static szClassName64 ]
    
peviEntpev_classnameszClassNamecharsmaxszClassName ) )
    
    if( 
equalszClassName"func_door_rotating" ) || equalszClassName"func_door" ) )
        return 
iEnt
        
    
return 0


Last edited by dFF; 03-04-2012 at 08:07.
dFF is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 03-04-2012 , 08:53   Re: Touching entities
Reply With Quote #4

Mmm... That is quite strange!
The traceline should definitely be executing.

Can you show more code please?
__________________
It's a mystery.
Mini_Midget is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 03-04-2012 , 11:45   Re: Touching entities
Reply With Quote #5

Hmm.. If I change in TraceLine EndOrigin with current origin of my entity the line is drawn; but there is a new problem. see photo
(tested with func_breakable on de_nuke map)

Attached Thumbnails
Click image for larger version

Name:	untitled2.jpg
Views:	130
Size:	18.9 KB
ID:	100152  
dFF 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 06:15.


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