AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] checking if the user is aiming outside (https://forums.alliedmods.net/showthread.php?t=132325)

Kreation 07-14-2010 03:51

[SOLVED] checking if the user is aiming outside
 
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.

ot_207 07-14-2010 05:58

Re: checking if the user is aiming outside
 
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



Kreation 07-14-2010 15:09

Re: checking if the user is aiming outside
 
Quote:

Originally Posted by ot_207 (Post 1238700)
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?

ot_207 07-14-2010 16:05

Re: checking if the user is aiming outside
 
Quote:

Originally Posted by Kreation (Post 1239118)
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.

Kreation 07-14-2010 23:29

Re: checking if the user is aiming outside
 
Got it working. Thanks.

ot_207 07-15-2010 12:21

Re: checking if the user is aiming outside
 
Quote:

Originally Posted by Kreation (Post 1239597)
Got it working. Thanks.

Ok. I am curious, what didn't the function have?

drekes 07-15-2010 12:27

Re: [SOLVED] checking if the user is aiming outside
 
changed the return into this:
PHP Code:

    if(engfunc(EngFunc_PointContentsend) == CONTENTS_SKY)
        return 
true;
    
    return 
false


Bugsy 07-15-2010 22:13

Re: [SOLVED] checking if the user is aiming outside
 
Quote:

Originally Posted by drekes (Post 1240247)
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 ); 


drekes 07-15-2010 23:42

Re: [SOLVED] checking if the user is aiming outside
 
Quote:

Originally Posted by Bugsy (Post 1240912)
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?

Bugsy 07-15-2010 23:58

Re: [SOLVED] checking if the user is aiming outside
 
Quote:

Originally Posted by drekes (Post 1240959)
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.


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

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