| closedDistance Based Accuracy / Cone of Fire Creation |
| Started by Wilson [29th ID] on 07-24-2007, 09:28 PM |
Threads: 57
Joined: Oct 2005
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.rnrnI 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.rnrnI have commented it all out so it should be relatively easy to follow.rnrn
#include <amxmodx>rn#include <amxmisc>rn#include <fakemeta>rnrn#pragma semicolon 1rnrn#define PLUGIN "Distance Accuracy"rn#define VERSION "1.0"rn#define AUTHOR "29th ID"rnrn// Global CVarsrnnew g_cvarDistance, g_cvarOffset;rnrnpublic plugin_init() {rn register_plugin( PLUGIN, VERSION, AUTHOR );rn rn // Register Hookrn register_forward( FM_TraceLine, "hook_TraceLine", 1 );rn rn // Register CVarsrn g_cvarDistance = register_cvar( "trace_distance", "300" );rn g_cvarOffset = register_cvar( "trace_offset", "50" );rn}rnrn// The actual hookrn// start origin end origin hit players? shooter idoftracernpublic hook_TraceLine( Float:start[3], Float:end[3], monsters, id, ptr ) {rn rn // Get victim user idrn new victim = get_tr( TR_pHit );rn rn // If the shooter or victim is not alive, exit.rn // (Not a bullet..ie putting mouse over someone and seeing their name)rn if( !is_user_alive( id ) ) return PLUGIN_CONTINUE;rn rn // Grab the maximum distance cvarrn new Float:m_cvarDistance = get_pcvar_float( g_cvarDistance );rn rn // Get the distance between "start origin" and "end origin"rn new Float:m_flTraceDistance = vecdist( start, end );rn rn // If start/end distance is greater than the max distance cvarrn if( m_flTraceDistance > m_cvarDistance )rn {rn // Grab the desired offset cvarrn new Float:m_cvarOffset = get_pcvar_float( g_cvarOffset );rn rn // Create a new "end origin" vectorrn new Float:m_newend[3];rn rn // Copy the current end origin vector, but add the offset cvar to each linern m_newend[0] = end[0]+m_cvarOffset;rn m_newend[1] = end[1]+m_cvarOffset;rn m_newend[2] = end[2]+m_cvarOffset;rn rn // Create this trace again, but with the new "end origin", m_newendrn engfunc( EngFunc_TraceLine, start, m_newend, monsters, id, ptr );rn rn // Debug echorn //client_print( id, print_chat, "Trace: %f > %f", m_flTraceDistance, m_cvarDistance );rn rn return PLUGIN_HANDLED;rn }rn return PLUGIN_CONTINUE;rn}rnrn// Space saver for vector distance (distance between two origins)rnstock Float:vecdist(Float:vec1[3], Float:vec2[3])rn{rn new Float:x = vec1[0] - vec2[0];rn new Float:y = vec1[1] - vec2[1];rn new Float:z = vec1[2] - vec2[2];rn x*=x;rn y*=y;rn z*=z;rn return floatsqroot(x+y+z);rn}Threads: 30
Joined: Sep 2006
Why giving up all your work Cpt? If I didn't know better, I'd say you're quitting DoD....:(
Threads: 57
Joined: Oct 2005
Nooo. This is just something that's been sitting idle in my scripting folder that I know I'm never going to use.
Threads: 75
Joined: Jun 2006
There is a place I got a program for DoD:S that does exactly this...I will have to look it up and get it posted here....that may help someone who wishes to contiune this project.nnCheers!

