Raised This Month: $ Target: $400
 0% 

[SOLVED] checking if the user is aiming outside


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 07-14-2010 , 03:51   [SOLVED] checking if the user is aiming outside
Reply With Quote #1

I'm currently trying to check if the player is aiming outside, like on de_dust2, in B tunnels would be inside.. you get the point(hopefully).

I have this code to check for it but the problem is that it always returns true, even when I'm in B tunnels. I've also tested this on cs_italy and the same result comes.

Code:
#include <amxmodx> #include <fakemeta> public plugin_init( ) {     register_plugin( "Test", "1.0", "Kreation" );         register_clcmd( "say /test", "CmdTest" ); } public CmdTest( id ) {     if( is_aiming_outside( id ) )     {         client_print( id, print_chat, "You're aiming outside, you're awesome!" );     }     else     {         client_print( id, print_chat, "You're not aiming outside, you're still awesome!" );     } } stock bool:is_aiming_outside( id ) {     new origin[3], Float:origin2[3];     get_user_origin( id, origin, 3 );     IVecFVec( origin, origin2 );         new i;         while( ( ++i < 45 ) && ( engfunc( EngFunc_PointContents, origin2 ) == CONTENTS_EMPTY ) )     {         origin2[2] + 15.0;     }         return ( engfunc( EngFunc_PointContents, origin2 ) ) ? true : false; }

Any and all help appreciated.
__________________
Hi.

Last edited by Kreation; 07-14-2010 at 23:29.
Kreation is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 07-14-2010 , 05:58   Re: checking if the user is aiming outside
Reply With Quote #2

It always returns true because the origin will always go in the sky, so basically you will always seem to be outside.

The way to do this right is with traceline.
Here is the stock, I have not tested it! I wrote it here directly.
PHP Code:
#include <xs>
stock bool:is_aiming_outsideid )
{
    new 
Float:origin[3], Float:angles[3], Float:view_offs[3]
    
// What we get: the origin of the player, the offset of the eyes and his angles (the direction he is aiming)
    
pev(idpev_originorigin)
    
pev(idpev_view_offsview_offs)
    
pev(idpev_v_angleangles);
    
    new 
Float:start[3], Float:end[3]
    
// Now we create the vectors for finding out the origin he is targeting.
    
    // Now start has the eye position
    
xs_vec_add(originview_offsstart)
    
    
// Turn the angles in vector (FORWARD meaning that we want in front)
    
angle_vector(anglesANGLEVECTOR_FORWARD,angles)
    
    
// We make the vector bigger for doing the best trace we can
    
xs_vec_mul_scalar(angles8024.0angles);

    
// We obtain the end vector of our target
    
xs_vec_add(anglesstartend);
    
    
// Create a trace handle for the traceline
    
new thdl create_tr2();

    
// Now we do a trace
    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERS|IGNORE_GLASS|IGNORE_MISSILEidthdl)
    
// This is the origin where we are aiming (it is held in start)
    
get_tr2(thdlTR_vecEndPosstart);
    
    
// Now we substract the angles just to make sure that we aren't in the wall or something
    
xs_vec_div_scalar(angles8024.0angles)
    
xs_vec_sub(startanglesstart);
    
    
// Now we add to the start to the z axis (meaning height)
    
xs_vec_add(start, {0.00.08000.0}, end)
    
    
// We do another trace_line to the sky
    
    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERS|IGNORE_GLASS|IGNORE_MISSILEidthdl)

    
// This is the origin where the trace stops (or in sky or in a wall)
    
get_tr2(thdlTR_vecEndPosend);

    
// Destroy the trace handle (do not forget to do that!)
    
free_tr2(thdl);
    
    return ( 
engfuncEngFunc_PointContentsend ) ) ? true false

__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 07-14-2010 at 06:04.
ot_207 is offline
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 07-14-2010 , 15:09   Re: checking if the user is aiming outside
Reply With Quote #3

Quote:
Originally Posted by ot_207 View Post
It always returns true because the origin will always go in the sky, so basically you will always seem to be outside.
That's what I thought last night, but I didn't post it because I couldn't explain what I mean't and thanks, I'll go test this now.

There's one problem with that code(compile error), I get a warning on line 60, tag mismatch.

Line 60:
Code:
xs_vec_add(start, {0.0, 0.0, 8000.0}, end)

I'm going to test this anyways just to see if that causes a problem or not.

EDIT: I tested it with that tag mismatch, and the same result. It always returns true. Any ideas?
__________________
Hi.

Last edited by Kreation; 07-14-2010 at 15:52.
Kreation is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 07-14-2010 , 16:05   Re: checking if the user is aiming outside
Reply With Quote #4

Quote:
Originally Posted by Kreation View Post
That's what I thought last night, but I didn't post it because I couldn't explain what I mean't and thanks, I'll go test this now.

There's one problem with that code(compile error), I get a warning on line 60, tag mismatch.

Line 60:
Code:
xs_vec_add(start, {0.0, 0.0, 8000.0}, end)

I'm going to test this anyways just to see if that causes a problem or not.

EDIT: I tested it with that tag mismatch, and the same result. It always returns true. Any ideas?
This is the correct way:
Code:
xs_vec_add(start, Float:{0.0, 0.0, 8000.0}, end)
And I told you that I didn't test the function so try doing some debugs on it. I already gave you 95% of what you need to do.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 07-14-2010 , 23:29   Re: checking if the user is aiming outside
Reply With Quote #5

Got it working. Thanks.
__________________
Hi.
Kreation is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 07-15-2010 , 12:21   Re: checking if the user is aiming outside
Reply With Quote #6

Quote:
Originally Posted by Kreation View Post
Got it working. Thanks.
Ok. I am curious, what didn't the function have?
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 07-15-2010 , 12:27   Re: [SOLVED] checking if the user is aiming outside
Reply With Quote #7

changed the return into this:
PHP Code:
    if(engfunc(EngFunc_PointContentsend) == CONTENTS_SKY)
        return 
true;
    
    return 
false
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2010 , 22:13   Re: [SOLVED] checking if the user is aiming outside
Reply With Quote #8

Quote:
Originally Posted by drekes View Post
changed the return into this:
PHP Code:
    if(engfunc(EngFunc_PointContentsend) == CONTENTS_SKY)
        return 
true;
    
    return 
false
PHP Code:
return bool: ( engfuncEngFunc_PointContents end ) == CONTENTS_SKY ); 
__________________
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 07-15-2010 , 23:42   Re: [SOLVED] checking if the user is aiming outside
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
PHP Code:
return bool: ( engfuncEngFunc_PointContents end ) == CONTENTS_SKY ); 
I understand how it works and thanks for correcting me, but could you explain what's wrong with my method please?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2010 , 23:58   Re: [SOLVED] checking if the user is aiming outside
Reply With Quote #10

Quote:
Originally Posted by drekes View Post
I understand how it works and thanks for correcting me, but could you explain what's wrong with my method please?
There's nothing wrong with your code, it would work fine. Doing it the way I posted just eliminates some code.
__________________
Bugsy 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 07:16.


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