PDA

View Full Version : Artificial bullet


Dr.G
02-08-2010, 04:45 PM
This is THE way to make a "fake bullet" with spread. Written by xxavalanchexx

->

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <xs>

new beamSpr;

public plugin_init()
{
register_clcmd("fire","do_fire");
}

public plugin_precache()
{
beamSpr = precache_model("sprites/laserbeam.spr");
}

public do_fire(id)
{
new arg1[4], arg2[8];
read_argv(1,arg1,3);
read_argv(2,arg2,7);
new cShots = str_to_num(arg1);
new Float:flSpread = floatstr(arg2);

new Float:vecSrc[3], Float:vecOrigin[3], Float:vecViewOfs[3];

pev(id, pev_origin, vecOrigin);
pev(id, pev_view_ofs, vecViewOfs);

xs_vec_add(vecOrigin, vecViewOfs, vecSrc);

new Float:vecVAngle[3], Float:vecPunchAngle[3], Float:vecTemp[3], Float:vecDirShooting[3];

pev(id, pev_v_angle, vecVAngle);
pev(id, pev_punchangle, vecPunchAngle);
xs_vec_add(vecVAngle, vecPunchAngle, vecTemp);

engfunc(EngFunc_MakeVectors, vecTemp);
global_get(glb_v_forward, vecDirShooting);

new Float:vecSpread[3];
vecSpread[0] = flSpread;
vecSpread[1] = flSpread;
vecSpread[2] = flSpread;

FireBulletsPlayer(cShots, vecSrc, vecDirShooting, vecSpread, 2048.0, 10, id);

return PLUGIN_HANDLED;
}

public FireBulletsPlayer ( cShots, Float:vecSrc[3], Float:vecDirShooting[3], Float:vecSpread[3], Float:flDistance, iDamage, pevAttacker )
{
new tr;

new Float:vecRight[3], Float:vecUp[3];
global_get( glb_v_right, vecRight );
global_get( glb_v_up, vecUp );

new Float:x, Float:y/* , Float:z; */

new Float:vecDir[3], Float:vecEnd[3], Float:vecTemp1[3], Float:vecTemp2[3];

for ( new iShot = 1; iShot <= cShots; iShot++ )
{
//Use player's random seed.
// get circular gaussian spread
x = random_float( -0.5, 0.5 ) + random_float( -0.5, 0.5 );
y = random_float( -0.5, 0.5 ) + random_float( -0.5, 0.5 );
/* z = x * x + y * y; */

/* Vector vecDir = vecDirShooting +
x * vecSpread.x * vecRight +
y * vecSpread.y * vecUp; */

xs_vec_mul_scalar( vecRight, x * vecSpread[0], vecTemp1 );
xs_vec_mul_scalar( vecUp, y * vecSpread[1], vecTemp2 );

xs_vec_add( vecDirShooting, vecTemp1, vecDir );
xs_vec_add( vecDir, vecTemp2, vecDir );

/* vecEnd = vecSrc + vecDir * flDistance; */

xs_vec_mul_scalar( vecDir, flDistance, vecTemp1 );
xs_vec_add( vecSrc, vecTemp1, vecEnd );

engfunc( EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, pevAttacker/*pentIgnore*/, tr );

new Float:flFraction;
get_tr2( tr, TR_flFraction, flFraction );

// do damage, paint decals
if(flFraction != 1.0)
{
new pEntity = get_tr2( tr, TR_pHit );

if ( iDamage && pev_valid(pEntity) )
{
ExecuteHam( Ham_TakeDamage, pEntity, any:pevAttacker, any:pevAttacker, any:float(iDamage), any:(DMG_BULLET | ((iDamage > 16) ? DMG_ALWAYSGIB : DMG_NEVERGIB)) );

/* TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
DecalGunshot( &tr, iBulletType ); */
}
}
// make bullet trails
/* UTIL_BubbleTrail( vecSrc, tr.vecEndPos, (flDistance * tr.flFraction) / 64.0 ); */

new Float:vecEndPos[3];
get_tr2( tr, TR_vecEndPos, vecEndPos );

// beam effect
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_BEAMPOINTS );
write_coord( floatround(vecSrc[0]) );
write_coord( floatround(vecSrc[1]) );
write_coord( floatround(vecSrc[2]) );
write_coord( floatround(vecEndPos[0]) );
write_coord( floatround(vecEndPos[1]) );
write_coord( floatround(vecEndPos[2]) );
write_short( beamSpr );
write_byte( 0 );
write_byte( 0 );
write_byte( 255 );
write_byte( 10 );
write_byte( 0 );
write_byte( 0 );
write_byte( 255 );
write_byte( 0 );
write_byte( 200 );
write_byte( 0 );
message_end( );
}

return 1;
}

The spread gotta be set really low, I use 0.23 for a shotgun eg.