Raised This Month: $ Target: $400
 0% 

How to get the coordinate of gunpoint


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
akn
Junior Member
Join Date: Aug 2009
Old 08-22-2009 , 07:59   Re: How to get the coordinate of gunpoint
Reply With Quote #1

Quote:
Originally Posted by Arkshine View Post
If you want to throw a tracer like this does this plugin, it should be enough to retrieve the gun position. All the weapons in HL or CS use the gun position as source origin.
this plugin can't show trace in first person view, that is what i want to do.
akn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-22-2009 , 08:09   Re: How to get the coordinate of gunpoint
Reply With Quote #2

I'm confused, you are talking the view like in the image in your first post ? It does show in this plugin. Anyway, whatever the view.
__________________
Arkshine is offline
akn
Junior Member
Join Date: Aug 2009
Old 08-22-2009 , 09:12   Re: How to get the coordinate of gunpoint
Reply With Quote #3

the picture in first post is not a tracer, it is a laser sight, link:http://forums.alliedmods.net/showthread.php?p=518900
akn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-22-2009 , 11:21   Re: How to get the coordinate of gunpoint
Reply With Quote #4

What I was meant if you want to do the same thing than this plugin but using TE_USERTRACER, using the position from gun is perfectly fine since with the speed you won't see any difference.

Here a test plugin :

Code:
    #include <amxmodx>     #include <fakemeta>     #include <engine>         new gMaxClients;     enum _:Coord_e { Float:x, Float:y, Float:z };     enum _:Angle_e { Float:Pitch, Float:Yaw, Float:Roll };         #define VectorAdd(%0,%1,%2)    ( %2[ x ] = %0[ x ] + %1[ x ], %2[ y ] = %0[ y ] + %1[ y ], %2[ z ] = %0[ z ] + %1[ z ] )     #define VectorMA(%0,%1,%2,%3)  ( %3[ x ] = %0[ x ] + %1 * %2[ x ], %3[ y ] = %0[ y ] + %1 * %2[ y ], %3[ z ] = %0[ z ] + %1 * %2[ z ] )     #define VectorScale(%0,%1,%2)  ( %2[ x ] = %1 * %0[ x ], %2[ y ] = %1 * %0[ y ], %2[ z ] = %1 * %0[ z ] )         #define write_coord_f(%0)      ( engfunc( EngFunc_WriteCoord, %0 ) )             public plugin_init ()     {         register_clcmd( "tracer", "ClientCommand_ShootTracer" );         register_forward( FM_PlaybackEvent, "Forward_PlaybackEvent" );                 gMaxClients = get_maxplayers();     }             public Forward_PlaybackEvent ( Flags, Invoker, EventId )     {         if  ( 1 <= Invoker <= gMaxClients )         {             ClientCommand_ShootTracer( Invoker );         }     }         public ClientCommand_ShootTracer ( const Player )     {         new Float:Origin  [ Coord_e ];         new Float:Velocity[ Coord_e ];         new Float:Forward [ Coord_e ];         new Float:VAngle  [ Angle_e ];                 UTIL_GetGunPosition( Player, Origin );         // engfunc( EngFunc_GetAttachment, Player, 0 , Origin, VAngle );                 pev( Player, pev_v_angle, VAngle );         angle_vector( VAngle, ANGLEVECTOR_FORWARD, Velocity );         VectorScale( Velocity, 4096.0, Velocity );         FX_UserTracer( .Source   = Origin,                        .Velocity = Velocity,                        .Life     = 3,                        .Color    = 1,                        .Length   = 1 );     }         UTIL_GetGunPosition ( const Player, Float:Source[ Coord_e ] )     {         static Float:ViewOfs[ Coord_e ];         pev( Player, pev_origin, Source );         pev( Player, pev_view_ofs, ViewOfs );         VectorAdd( Source, ViewOfs, Source );     }         FX_UserTracer ( const Float:Source[ Coord_e ], const Float:Velocity[ Coord_e ], const Life, const Color, const Length )     {         client_print( 0, print_chat, "BANG" );                 message_begin( MSG_BROADCAST, SVC_TEMPENTITY );         write_byte( TE_USERTRACER );         write_coord_f( Source[ x ] );         write_coord_f( Source[ y ] );         write_coord_f( Source[ z ] );         write_coord_f( Velocity[ x ] );         write_coord_f( Velocity[ y ] );         write_coord_f( Velocity[ z ] );         write_byte( Life * 10 );         write_byte( Color );         write_byte( Length * 10 );         message_end();     }
__________________
Arkshine is offline
akn
Junior Member
Join Date: Aug 2009
Old 08-22-2009 , 12:28   Re: How to get the coordinate of gunpoint
Reply With Quote #5

first, Arkshine, I really appreciate your effort and time answering this question,
the test code still have same problem as "Advanced Weapon Tracers", you can't see the tracer of your own shots.

ps:
pev( Player, pev_view_ofs, ViewOfs );
ViewOfs is always 0, 0, 17 when Player is the first person viewer
ViewOfs is always 0, 0, 12 when Player is other player
it only adjust the source coordinate from player model center to player view point
we have to adjust the source coordinate to weapon view model(like v_usp.mdl), then player could see the tracer of their own shots.
akn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-22-2009 , 12:39   Re: How to get the coordinate of gunpoint
Reply With Quote #6

Try using "engfunc( EngFunc_GetAttachment, Player, 0 , Origin, VAngle );" in the code so. But the problem using this message is you have to find the right direction, otherwise it doesn't match well.
__________________

Last edited by Arkshine; 08-22-2009 at 12:54.
Arkshine is offline
akn
Junior Member
Join Date: Aug 2009
Old 08-22-2009 , 12:58   Re: How to get the coordinate of gunpoint
Reply With Quote #7

i tried with below code:
//UTIL_GetGunPosition( Player, Origin );
engfunc( EngFunc_GetAttachment, Player, 0 , Origin, VAngle );

the effect of player own shot is not good, because the attachment is not from view model(v_usp.mdl), i also tried with attachment id 0, 1 , 2 ,3, same result.
akn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-22-2009 , 13:07   Re: How to get the coordinate of gunpoint
Reply With Quote #8

But, well at least you see the tracer... :p

This way it's more accurate ( about the direction, and works for multishots ):

Code:
    #include <amxmodx>     #include <fakemeta>     #include <hamsandwich>     #include <engine>     enum _:Coord_e { Float:x, Float:y, Float:z };     enum _:Angle_e { Float:Pitch, Float:Yaw, Float:Roll };     #define message_begin_f(%0,%1,%2) ( engfunc( EngFunc_MessageBegin, %0, %1, %2 ) )     #define write_coord_f(%0)         ( engfunc( EngFunc_WriteCoord, %0 ) )     new Trie:gRegisteredClasses;         public plugin_precache()     {         gRegisteredClasses = TrieCreate();         register_forward( FM_Spawn, "Entity_Spawn" );     }     public Entity_Spawn( const Entity )     {         if( pev_valid( Entity ) )         {             static ClassName[32];             pev( Entity,pev_classname, ClassName, charsmax( ClassName ) );                         if ( !TrieKeyExists( gRegisteredClasses, ClassName ) )             {                 RegisterHam( Ham_TraceAttack, ClassName, "Forward_GlobalTraceAttack" );                 TrieSetCell( gRegisteredClasses, ClassName, true );             }         }     }     public plugin_init ()     {         RegisterHam( Ham_TraceAttack, "worldspawn", "Forward_GlobalTraceAttack" );         RegisterHam( Ham_TraceAttack, "player"    , "Forward_GlobalTraceAttack" );     }         public Forward_GlobalTraceAttack ( const Victim, const Attacker, const Float:Damage, const Float:Direction[ Coord_e ] )     {         static Float:Angle   [ Coord_e ];         static Float:Origin  [ Coord_e ];         static Float:Velocity[ Coord_e ];                 engfunc( EngFunc_GetAttachment, Attacker, 0 , Origin, Angle );                 Velocity[ x ] = Direction[ x ] * 4096.0;         Velocity[ y ] = Direction[ y ] * 4096.0;         Velocity[ z ] = Direction[ z ] * 4096.0;                 FX_UserTracer( .Source   = Origin,                        .Velocity = Velocity,                        .Life     = 3,                        .Color    = 0,                        .Length   = 1 );     }         FX_UserTracer ( const Float:Source[ Coord_e ], const Float:Velocity[ Coord_e ], const Life, const Color, const Length )     {         message_begin_f( MSG_PVS, SVC_TEMPENTITY, Source, 0 );         write_byte( TE_USERTRACER );         write_coord_f( Source[ x ] );         write_coord_f( Source[ y ] );         write_coord_f( Source[ z ] );         write_coord_f( Velocity[ x ] );         write_coord_f( Velocity[ y ] );         write_coord_f( Velocity[ z ] );         write_byte( Life * 10 );         write_byte( Color );         write_byte( Length * 10 );         message_end();     }

But if you want really the tracer at this point, I don't see any others ways than calculating yourself the position.

On a plugin I'm using that to calculate the start point :

Code:
    UTIL_GetStartPosition ( const Player, const Float:Angles[ Angle_e ],                             const Float:FactorForward = 0.0, const Float:FactorRight = 0.0, const Float:FactorUp = 0.0, Float:Origin[ Coord_e ] )     {         static Float:Forward[ Coord_e ];         static Float:Right  [ Coord_e ];         static Float:Up     [ Coord_e ];         UTIL_MakeVector( Angles );         UTIL_GetGunPosition( Player, Origin );         if ( FactorForward > 0.0 )  { global_get( glb_v_forward, Forward ); }         if ( FactorRight   > 0.0 )  { global_get( glb_v_right, Right );     }         if ( FactorUp      > 0.0 )  { global_get( glb_v_up, Up );           }         Origin[ x ] += Forward[ x ] * FactorForward + Right[ x ] * FactorRight + Up[ x ] * FactorUp;         Origin[ y ] += Forward[ y ] * FactorForward + Right[ y ] * FactorRight + Up[ y ] * FactorUp;         Origin[ z ] += Forward[ z ] * FactorForward + Right[ z ] * FactorRight + Up[ z ] * FactorUp;     }

Code:
UTIL_GetStartPosition( Player, VAngles, .FactorForward = 12.0, .FactorRight = 2.0, .FactorUp = -4.0, .Origin = StartOrigin );
__________________

Last edited by Arkshine; 08-22-2009 at 13:13.
Arkshine is offline
akn
Junior Member
Join Date: Aug 2009
Old 08-24-2009 , 00:24   Re: How to get the coordinate of gunpoint
Reply With Quote #9

many thanks Arkshine,
calculating the position can't be precise, since TE_BEAMENTPOINT is able to location the position so well, maybe we could get the position by investigating how does the TE_BEAMENTPOINT message be handled by client.
Where could I get the client code handling TE_BEAMENTPOINT message?
akn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-24-2009 , 03:53   Re: How to get the coordinate of gunpoint
Reply With Quote #10

Quote:
calculating the position can't be precise
You can get exactly the position, I don't see the problem. But the position would be different for each weapons.

About TE_BEAMENTPOINT, I don't understand what you want to do.
__________________
Arkshine 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 15:07.


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