This plugin basically replicates a cone of fire. It is distance based accuracy. Depending on how far away you are from your target, your bullet will be offset by a variable.
I created the plugin but never took it anywhere because I realised the DoD default cone of fire suffices for my purposes, but I figure someone will someday have a use for it, and by that time I might be long dead. So I figured I'd post it here in case anyone else wants to use it.
I have commented it all out so it should be relatively easy to follow.
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#pragma semicolon 1
#define PLUGIN "Distance Accuracy"
#define VERSION "1.0"
#define AUTHOR "29th ID"
// Global CVars
new g_cvarDistance, g_cvarOffset;
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR );
// Register Hook
register_forward( FM_TraceLine, "hook_TraceLine", 1 );
// Register CVars
g_cvarDistance = register_cvar( "trace_distance", "300" );
g_cvarOffset = register_cvar( "trace_offset", "50" );
}
// The actual hook
// start origin end origin hit players? shooter idoftrace
public hook_TraceLine( Float:start[3], Float:end[3], monsters, id, ptr ) {
// Get victim user id
new victim = get_tr( TR_pHit );
// If the shooter or victim is not alive, exit.
// (Not a bullet..ie putting mouse over someone and seeing their name)
if( !is_user_alive( id ) ) return PLUGIN_CONTINUE;
// Grab the maximum distance cvar
new Float:m_cvarDistance = get_pcvar_float( g_cvarDistance );
// Get the distance between "start origin" and "end origin"
new Float:m_flTraceDistance = vecdist( start, end );
// If start/end distance is greater than the max distance cvar
if( m_flTraceDistance > m_cvarDistance )
{
// Grab the desired offset cvar
new Float:m_cvarOffset = get_pcvar_float( g_cvarOffset );
// Create a new "end origin" vector
new Float:m_newend[3];
// Copy the current end origin vector, but add the offset cvar to each line
m_newend[0] = end[0]+m_cvarOffset;
m_newend[1] = end[1]+m_cvarOffset;
m_newend[2] = end[2]+m_cvarOffset;
// Create this trace again, but with the new "end origin", m_newend
engfunc( EngFunc_TraceLine, start, m_newend, monsters, id, ptr );
// Debug echo
//client_print( id, print_chat, "Trace: %f > %f", m_flTraceDistance, m_cvarDistance );
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
// Space saver for vector distance (distance between two origins)
stock Float:vecdist(Float:vec1[3], Float:vec2[3])
{
new Float:x = vec1[0] - vec2[0];
new Float:y = vec1[1] - vec2[1];
new Float:z = vec1[2] - vec2[2];
x*=x;
y*=y;
z*=z;
return floatsqroot(x+y+z);
}
__________________