Raised This Month: $ Target: $400
 0% 

Grenade trajectory prediction


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
lazarev
Veteran Member
Join Date: Sep 2008
Old 03-31-2011 , 15:27   Re: Grenade trajectory prediction
Reply With Quote #10

PHP Code:
/*    Copyright © 2011, Gabe Newell

    Grenade Tracing is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Grenade Tracing; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
    
    This plugin was made by request.
    Credits: Revolution. http://www.gamedeception.net/threads/12759-Grenade-Tracing
*/

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

#define NUMBLOOPS 20.0
#define TIMEALIVE 2.0
#define OLDDAMPER 1.75
#define NEWDAMPER 0.75
#define SVGRAVITY 3.75
#define FLOORSTOP 0.20

new spr_beam;

public 
plugin_init( )
{
    
register_plugin"Grenade Tracing""0.0.2""Juice" );
    
register_concmd"trace_grenade""TraceGrenade" );
}

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

public 
TraceGrenadeid )
{
    
//new Float:dest[3];
    
new pmtrace 0;

    new 
Float:gravity get_cvar_float("sv_gravity") / SVGRAVITY;

    new 
Float:angThrow], Float:throwvector], Float:startpos], Float:endpos], Float:punchangle];
    new 
Float:origin], Float:view_ofs];
    new 
Float:pmEyePos], Float:pmVelocity];
    
    
pevidpev_velocitypmVelocity );
    
    
pevidpev_punchanglepunchangle );
    
pevidpev_v_angleangThrow );
    
    
pevid ,pev_originorigin );
    
pevidpev_view_ofsview_ofs );
    
    
xs_vec_addangThrowpunchangleangThrow );
    
xs_vec_addoriginview_ofspmEyePos );

    if (
angThrow[0] < 0)
        
angThrow[0] = -10 angThrow[0] * ((90 10) / 90.0);
    else
        
angThrow[0] = -10 angThrow[0] * ((90 10) / 90.0);

    new 
Float:flVel = (90 angThrow[0]) * 6;
    if (
flVel 500)
        
flVel 500.0;
        
    
angle_vectorangThrowANGLEVECTOR_FORWARDthrowvector );

    
startpos[0] = pmEyePos[0] + throwvector[0] * 16;
    
startpos[1] = pmEyePos[1] + throwvector[1] * 16;
    
startpos[2] = pmEyePos[2] + throwvector[2] * 16;

    
throwvector[0] = throwvector[0] * flVel pmVelocity[0];
    
throwvector[1] = throwvector[1] * flVel pmVelocity[1];
    
throwvector[2] = throwvector[2] * flVel pmVelocity[2];

    new 
collisions 0;
    new 
Float:timelive;
    new 
Float:step = (TIMEALIVE NUMBLOOPS);
    
    new 
ent;
    new 
Float:plane_normal[3];
    new 
Float:fraction;
    
    for ( 
timelive 0.0timelive TIMEALIVEtimelive += step )
    {
        
endpos[0] = startpos[0] + throwvector[0] * step;
        
endpos[1] = startpos[1] + throwvector[1] * step;
        
endpos[2] = startpos[2] + throwvector[2] * step//move
        
        
engfuncEngFunc_TraceLinestartposendposDONT_IGNORE_MONSTERS0pmtrace );
        
ent get_tr2pmtraceTR_pHit )

        
get_tr2pmtraceTR_vecPlaneNormalplane_normal );
        
get_tr2pmtraceTR_flFractionfraction );
        
        if( 
ent != id && fraction 1.0 )
        {
            
endpos[0] = startpos[0] + throwvector[0] * fraction step;
            
endpos[1] = startpos[1] + throwvector[1] * fraction step;
            
endpos[2] = startpos[2] + throwvector[2] * fraction step;
            
/*
            if ( plane_normal[2] > 0.9 && throwvector[2] <= 0 && throwvector[2] >= -gravity*FLOORSTOP )
            {
                dest[0] = endpos[0];
                dest[1] = endpos[1];
                dest[2] = endpos[2];
            }
            */
            
message_beginMSG_ONE_UNRELIABLESVC_TEMPENTITY_id );
            
write_byteTE_SPARKS );
            
engfuncEngFunc_WriteCoordendpos[0] );
            
engfuncEngFunc_WriteCoordendpos[1] );
            
engfuncEngFunc_WriteCoordendpos[2] );
            
message_end();
            
            new 
Float:proj xs_vec_dotthrowvectorplane_normal ); 
            
            
throwvector[0] = (throwvector[0]*OLDDAMPER proj*2*plane_normal[0]) * NEWDAMPER//reflection off the wall
            
throwvector[1] = (throwvector[1]*OLDDAMPER proj*2*plane_normal[1]) * NEWDAMPER;
            
throwvector[2] = (throwvector[2]*OLDDAMPER proj*2*plane_normal[2]) * NEWDAMPER

            
collisions++;
            if (
collisions 30) break;

            
timelive -= (step * (fraction));
        }
        
        
BeamPointsidstartposendpos );
        
        
startpos[0] = endpos[0];
        
startpos[1] = endpos[1];
        
startpos[2] = endpos[2];

        
throwvector[2] -= gravity fraction step//gravity
    
}

    
//dest[0] = startpos[0];
    //dest[1] = startpos[1];
    //dest[2] = startpos[2];
    
    
return PLUGIN_HANDLED;
}

BeamPointsidFloat:startpos[3], Float:endpos[3] )
{
    
message_beginMSG_ONE_UNRELIABLESVC_TEMPENTITY_id );
    
write_byteTE_BEAMPOINTS )            // type
    
engfuncEngFunc_WriteCoordstartpos[0] );    // origin[1]
    
engfuncEngFunc_WriteCoordstartpos[1] );    // origin[2]
    
engfuncEngFunc_WriteCoordstartpos[2] );    // origin[3]
    
engfuncEngFunc_WriteCoordendpos[0] );    // origin2[1]
    
engfuncEngFunc_WriteCoordendpos[1] );    // origin2[2]
    
engfuncEngFunc_WriteCoordendpos[2] );    // origin2[3]
    
write_shortspr_beam );            // sprite index
    
write_byte);                // start frame
    
write_byte);                // framerate
    
write_byte30 );                // life in 0.1 sec
    
write_byte20 );                // width
    
write_byte);                // noise
    
write_byte);                // red
    
write_byte255 );                // green
    
write_byte);                // blue
    
write_byte255 );                // brightness
    
write_byte);                // speed
    
message_end()


Last edited by lazarev; 04-01-2011 at 10:49.
lazarev is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:36.


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