currently it works only for left handed, I am try to make it fit right handed
Code:
//first person tracer
#include <amxmodx>
#include <cstrike>
#include <fakemeta_stocks>
#include <engine>
#include <hamsandwich>
#define VERSION "1.0"
#define write_coord_f(%1) engfunc(EngFunc_WriteCoord,%1)
enum _:Coord_e { Float:x, Float:y, Float:z };
#define VectorAdd(%0,%1,%2) ( %2[ x ] = %0[ x ] + %1[ x ], %2[ y ] = %0[ y ] + %1[ y ], %2[ z ] = %0[ z ] + %1[ z ] )
#define VectorScale(%0,%1,%2) ( %2[ x ] = %1 * %0[ x ], %2[ y ] = %1 * %0[ y ], %2[ z ] = %1 * %0[ z ] )
#define max_weapon CSW_P90
#define min_weapon CSW_P228
#define weapon_size max_weapon-min_weapon+1
new Trie:g_tClassNames
new dummy_ent[weapon_size]
public plugin_precache()
{
for(new int:i=0;i<weapon_size;i++) dummy_ent[i]=0;
g_tClassNames = TrieCreate()
RegisterHam(Ham_TraceAttack, "worldspawn", "TraceAttack", 1)
TrieSetCell(g_tClassNames, "worldspawn", 1)
RegisterHam(Ham_TraceAttack, "player", "TraceAttack", 1)
TrieSetCell(g_tClassNames, "player", 1)
register_forward(FM_Spawn, "Spawn", 1)
}
public plugin_init()
{
register_plugin("First Person Tracers", VERSION, "akn")
}
public plugin_end()
{
TrieDestroy(g_tClassNames)
}
public Spawn( iEnt )
{
if( pev_valid(iEnt) )
{
static szClassName[32]
pev(iEnt, pev_classname, szClassName, charsmax(szClassName))
if( !TrieKeyExists(g_tClassNames, szClassName) )
{
RegisterHam(Ham_TraceAttack, szClassName, "TraceAttack", 1)
TrieSetCell(g_tClassNames, szClassName, 1)
}
}
}
public TraceAttack(iEnt, iAttacker, Float:flDamage, Float:fDir[3], ptr, iDamageType)
{
new wid = get_user_weapon(iAttacker);
if( wid==CSW_KNIFE || wid==CSW_HEGRENADE || wid == CSW_SMOKEGRENADE || wid == CSW_FLASHBANG || wid == CSW_C4 ) return;
new float:end[3]
get_tr2(ptr, TR_vecEndPos, end)
Draw_from_gunpoint(iAttacker,wid,end);
}
public Draw_from_gunpoint(id, wid, const Float:end[3])
{
new Float:ori[3]={0,0,0};
new Float:offset[3];
new Float:vector[3];
new Float:angle[3];
wid=wid-min_weapon;
if(dummy_ent[wid]==0)
{
new classname[32];
dummy_ent[wid]=create_entity("worldspawn");
set_entity_visibility(dummy_ent[wid],0);
entity_set_vector(dummy_ent[wid],EV_VEC_origin,ori);
pev(id, pev_viewmodel2, classname, sizeof(classname)-1);
entity_set_model(dummy_ent[wid],classname);
}
entity_get_vector(id,EV_VEC_v_angle,angle);
angle[0]=0-angle[0];
entity_set_vector(dummy_ent[wid],EV_VEC_angles,angle);
engfunc(EngFunc_GetAttachment, dummy_ent[wid], 0, offset, angle);
entity_get_vector(id,EV_VEC_origin,ori);
pev(id,pev_view_ofs,vector);
if(vector[2]==12.0) ori[2]+=11; //duck
else ori[2]+=16; //stand
VectorAdd(ori,offset,ori); //left handed gunpoint
vector[0]=end[0]-ori[0];
vector[1]=end[1]-ori[1];
vector[2]=ori[2]-end[2];
vector_to_angle(vector,angle);
angle_vector(angle, ANGLEVECTOR_FORWARD, vector);
VectorScale(vector, 4096.0, vector);
Draw_tracer(ori,vector);
}
Draw_tracer(const Float:Source[3], const Float:Velocity[3])
{
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_USERTRACER );
write_coord_f( Source[0] );
write_coord_f( Source[1] );
write_coord_f( Source[2] );
write_coord_f( Velocity[0] );
write_coord_f( Velocity[1] );
write_coord_f( Velocity[2] );
write_byte( 20 ); //life
write_byte( 0 ); //color
write_byte( 3 ); //length
message_end();
}