AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Distance Based Accuracy / Cone of Fire Creation (https://forums.alliedmods.net/showthread.php?t=58372)

Wilson [29th ID] 07-24-2007 20:29

Distance Based Accuracy / Cone of Fire Creation
 
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); }

Arkshine 07-24-2007 20:33

Re: Distance Based Accuracy / Cone of Fire Creation
 
"PLUGIN_" ?

You should use "FMRES_" .

FMRES_HANDLED
FMRES_IGNORED
FMRES_OVERRIDE
FMRES_SUPERCEDE


All times are GMT -4. The time now is 18:45.

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