AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [Stock] Grenade Way (https://forums.alliedmods.net/showthread.php?t=176424)

DarkGL 01-18-2012 07:14

[Stock] Grenade Way
 
2 Attachment(s)
Function show player how thrown grenade will go
PHP Code:

new laser;

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

stock showGrenadeWay id weapon ){
    new 
Float:fGrenadeGrav 1.0;

    switch( 
weapon) {
    case 
CSW_HEGRENADE:
        
fGrenadeGrav    =                 0.55;
    case 
CSW_FLASHBANG:
        
fGrenadeGrav    =                 0.5;
    case 
CSW_SMOKEGRENADE:
        
fGrenadeGrav    =                 0.5;
    }
    static 
pGrav;
    
    if( !
pGrav )    pGrav   =          get_cvar_pointer"sv_gravity" );
    
    new 
Float:fStartPos] , FloatfViewOfs] , FloatfVector] , FloatfVeloc ] , FloatfAngles ] , FloatfEndPos ] , FloatfTmpVector ] , pTr FloatfFraction FloatfNormal ] , iCollision FloatfVel;
    new 
Float:fGrav =                 get_pcvar_floatpGrav ) , pHit 0;

    const            
maxCollsion                =            30;
    const 
Float:    fConstAliveTime            =            2.0;
    const 
Float:    fConstLoops                =            20.0;
    new 
Float:        fAliveTime                =            0.0;
    new 
Float:        fStep                    =            fConstAliveTime fConstLoops;

    
pevid pev_origin fStartPos );
    
pevid pev_view_ofs fViewOfs );
    
pevid pev_velocity fVeloc );
    
pevid pev_v_angle fAngles );

    
xs_vec_addfStartPos fViewOfs fStartPos );

    if (
fAngles[0] < 0)
        
fAngles[0] = -10.0 fAngles[0] * ((90.0 10.0) / 90.0);
    else
        
fAngles[0] = -10.0 fAngles[0] * ((90.0 10.0) / 90.0);

    
fVel = (90.0 fAngles[0]) * 6.0;
    if (
fVel 750.0)
        
fVel 750.0;

    
pevid pev_v_angle fAngles );

    
angle_vectorfAngles ANGLEVECTOR_FORWARD fVector );

    
xs_vec_mul_scalarfVector 16.0 fTmpVector );

    
xs_vec_addfStartPos fTmpVector fStartPos );

    
xs_vec_mul_scalarfVector fVel fVector );

    
xs_vec_addfVector fVeloc fVector );


    for( ; 
fAliveTime fConstAliveTime fAliveTime += fStep ){

        
xs_vec_copyfStartPos fEndPos);
        
xs_vec_mul_scalarfVector fStep fTmpVector );
        
xs_vec_addfEndPos fTmpVector fEndPos );

        
pTr       =              create_tr2();

        
engfunc(EngFunc_TraceLinefStartPosfEndPosDONT_IGNORE_MONSTERSidpTr )
        
        if( 
fAliveTime == 0.0 ){
            
fStartPos ] += 10.0;
        }

        
get_tr2pTr TR_flFraction fFraction);

        
pHit    =                 get_tr2pTr TR_pHit );

        if( 
pHit != id && fFraction 1.0 ){
            
get_tr2pTr TR_vecEndPos fEndPos );
            
            
get_tr2pTr TR_vecPlaneNormal fNormal )
            
            if( 
fNormal ] > 0.9 && fVector ] <= 0.0 && fVector ] >= -fGrav 0.20 ){
                return ;
            }

            new 
FloatfScalar xs_vec_dotfVectorfNormal ) * 1.3;

            
fVector[0] = fVector[0] - fScalar fNormal[0];
            
fVector[1] = fVector[1] - fScalar fNormal[1];
            
fVector[2] = fVector[2] - fScalar fNormal[2];

            
iCollision++;

            if(  
iCollision maxCollsion )
            break;

            
fAliveTime              -=        fStep   *             ( 1.0 fFraction ) ;
        }
        
        new 
iR iG iB;

        switch( 
weapon ) {
        case 
CSW_HEGRENADE:{
                
iR 250;
                
iG 0;
                
iB 0;
            }
        case 
CSW_FLASHBANG:{
                
iR 0;
                
iG 0;
                
iB 250;
            }
        case 
CSW_SMOKEGRENADE:{
                
iR 0;
                
iG 250;
                
iB 0;
            }
        }
        
        
message_beginMSG_ONE_UNRELIABLE SVC_TEMPENTITY , { } , id )
        
write_byte(0)                     // TE_BEAMPOINTS
        
engfuncEngFunc_WriteCoord fStartPos ] )
        
engfuncEngFunc_WriteCoord fStartPos ] )
        
engfuncEngFunc_WriteCoord fStartPos ] )
        
engfuncEngFunc_WriteCoord fEndPos ] )
        
engfuncEngFunc_WriteCoord fEndPos ] )
        
engfuncEngFunc_WriteCoord fEndPos ] )
        
write_short(laser)
        
write_byte(1)
        
write_byte(1)
        
write_byte(1)
        
write_byte(15)
        
write_byte(0)
                
write_byteiR )
                
write_byteiG )
                
write_byteiB )
        
write_byte(210)
        
write_byte(0)
        
message_end()

        
xs_vec_copyfEndPos fStartPos );
        
        
fVector]    -=              floatmulfloatmulfGrenadeGrav fGrav ) , floatmulfFraction fStep ) );

        
free_tr2pTr );
    }


Result:
Attachment 98323
Attachment 98324
http://www.youtube.com/watch?v=RzXca9lTRBA

Library
PHP Code:

#include <xs>
#include <fakemeta> 

  • First parametr is player id
  • Second is weapon CSW_HEGRENADE , CSW_FLASHBANG or CSW_SMOKEGRENADE

Example:
Showing way when player have grenade in hands
PHP Code:

public client_PreThinkid ){
        if( 
is_user_aliveid ) ){
                new 
iWeapon     =       get_user_weaponid );
                
                if( 
iWeapon == CSW_HEGRENADE || iWeapon == CSW_SMOKEGRENADE || iWeapon == CSW_FLASHBANG ){
                        
showGrenadeWayid iWeapon );
                }
        }



Devil259 01-18-2012 17:13

Re: [Stock] Grenade Way
 
Great.

hleV 01-19-2012 03:10

Re: [Stock] Grenade Way
 
This is so awesome.

joropito 01-19-2012 11:09

Re: [Stock] Grenade Way
 
Why not using TE_BEAMFOLLOW after grenade spawn and avoid to hook client_PreThink?

DarkGL 01-19-2012 11:31

Re: [Stock] Grenade Way
 
joropito it show grenade way before you throw him
your method would show way after throw and only traveled path

Lolz0r 01-19-2012 12:31

Re: [Stock] Grenade Way
 
This is fantastic!

kiki33hun 01-30-2012 10:34

Re: [Stock] Grenade Way
 
Nice, thanx

liinuus 01-30-2012 11:25

Re: [Stock] Grenade Way
 
awesome

FR0NTLINE 01-30-2012 13:02

Re: [Stock] Grenade Way
 
Awesome way to show team flashers whats up! Good fuckin job

Immortal_BLG 01-30-2012 21:15

Re: [Stock] Grenade Way
 
Another method how find grenade explosion origin, even if the grenade is on conveyor, etc: http://forums.bots-united.com/showthread.php?t=7641


All times are GMT -4. The time now is 20:44.

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