AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Create a shotgun burst with tracers (https://forums.alliedmods.net/showthread.php?t=100074)

Max! 08-12-2009 07:50

Create a shotgun burst with tracers
 
Ive been trying to achieve a shotgun burst effect with tracers but i cant figure out how to do it. atm it shoots 8 tracers in the same spot, where i need to to shoot 8 tracers in a random spread

Help is appreciated

ot_207 08-12-2009 08:49

Re: Create a shotgun burst with tracers
 
You can use the Ham_TraceAttack forward. There you get the player eyes origin and the end position of the trace handle, and create the tracers.

Max! 08-12-2009 08:51

Re: Create a shotgun burst with tracers
 
Code:

public GunShot(id)
{
    new aiming[3], Float:origin[3]
    get_user_origin(id, aiming, 3);
    pev(id, pev_origin, origin)
    message_begin(MSG_BROADCAST, SVC_TEMPENTITY) //  MSG_PAS MSG_BROADCAST
    write_byte(TE_TRACER)
    write_coord(floatround(origin[0]))
    write_coord(floatround(origin[1]))
    write_coord(floatround(origin[2]))
    write_coord(aiming[0])
    write_coord(aiming[1])
    write_coord(aiming[2])
    message_end()
    message_begin(0, SVC_TEMPENTITY, _, 0);
    write_byte(TE_GUNSHOTDECAL);
    write_coord(aiming[0]);
    write_coord(aiming[1]);
    write_coord(aiming[2]);
    write_short(0);
    write_byte(41);
    message_end();
}

thats what i wrote, and when i call it i loop it 8 times, how would i add some spread to that?

ot_207 08-12-2009 08:53

Re: Create a shotgun burst with tracers
 
No, it is not needed to do that, you can find out all the shots exactly where they hit with the method I posted above.
Edit: Now I have read more carefully. You would like the tracers random? Or would you like the tracers to go exactly where the shot ends?

Max! 08-13-2009 03:23

Re: Create a shotgun burst with tracers
 
i awnt the tracers to go from 1 point to 8 random points near each other where the bullets should hit

ot_207 08-13-2009 03:49

Re: Create a shotgun burst with tracers
 
Here! I have tested it! It works ;)

PHP Code:

/* Script generated by Pawn Studio */

#define PLUGIN    "Tracer"
#define AUTHOR    "OT"
#define VERSION    "1.0"

#include <amxmodx> 
#include <fakemeta> 
#include <engine> 
#include <hamsandwich> 
#include <xs> 

new Trie:RegisteredClasses 

public plugin_precache() 

    
RegisteredClasses TrieCreate() 
    
    
register_forward(FM_Spawn,"spawn"


public 
spawn(id

    if(
pev_valid(id)) 
    { 
        static 
classname[32
        
pev(id,pev_classname,classname,charsmax(classname)) 
         
        if(!
TrieKeyExists(RegisteredClasses,classname)) 
        { 
            
RegisterHam(Ham_TraceAttack,classname,"fw_global_traceatt"
            
TrieSetCell(RegisteredClasses,classname,true
        } 
    } 


public 
plugin_init() 

    
register_plugin(PLUGIN,VERSION,AUTHOR
     
    
RegisterHam(Ham_TraceAttack,"worldspawn","fw_global_traceatt"
}  


public 
fw_global_traceatt(entattackerFloat:damageFloat:direction[3], tracehdldamagebits

    new 
trace create_tr2() 
    new 
Float:start[3], Float:view_offs[3], Floatend[3
    
pev(attackerpev_originstart
    
pev(attackerpev_view_ofsview_offs

    
// player eye origin 
    
xs_vec_add(startview_offsstart
     
    
get_tr2(tracehdlTR_vecEndPosend
     
    
engfunc(EngFunc_TraceLinestartendDONT_IGNORE_MONSTERSattackertrace
     
    
get_tr2(traceTR_vecEndPosend
    
msg_tracer(start,end)     

    
free_tr2(trace)

    return 
HAM_IGNORED 


stock msg_tracer(Floatorigin[3], Floatend[3]) 

    
message_begin(MSG_BROADCASTSVC_TEMPENTITY//  MSG_PAS MSG_BROADCAST 
    
write_byte(TE_TRACER
    
engfunc(EngFunc_WriteCoordorigin[0]) 
    
engfunc(EngFunc_WriteCoordorigin[1]) 
    
engfunc(EngFunc_WriteCoordorigin[2]) 
    
engfunc(EngFunc_WriteCoordend[0]) 
    
engfunc(EngFunc_WriteCoordend[1]) 
    
engfunc(EngFunc_WriteCoordend[2]) 
    
message_end() 



Alka 08-13-2009 03:50

Re: Create a shotgun burst with tracers
 
You can check this plugin -> http://forums.alliedmods.net/showthread.php?p=544649 has shotgun tracers.

@ot_207 - TraceAttack for "worldspawn" ?

ot_207 08-13-2009 03:57

Re: Create a shotgun burst with tracers
 
Quote:

Originally Posted by Alka (Post 898240)
You can check this plugin -> http://forums.alliedmods.net/showthread.php?p=544649 has shotgun tracers.

@ot_207 - TraceAttack for "worldspawn" ?

Yes ;) it works!
LE: You can check these plugins: http://forums.alliedmods.net/showthread.php?t=94916 and http://forums.alliedmods.net/showthread.php?p=663892 both are using them :).

ConnorMcLeod 08-13-2009 07:17

Re: Create a shotgun burst with tracers
 
Mine also use worldspawn, but it wont help to reproduce shotgun.


This could help :

Code:

// special deathmatch shotgun spreads
#define VECTOR_CONE_DM_SHOTGUN        Vector( 0.08716, 0.04362, 0.00  )// 10 degrees by 5 degrees
#define VECTOR_CONE_DM_DOUBLESHOTGUN Vector( 0.17365, 0.04362, 0.00 ) // 20 degrees by 5 degrees

void CShotgun::PrimaryAttack()
{
        Vector vecSrc        = m_pPlayer->GetGunPosition( );
        Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );

        Vector vecDir;

#ifdef CLIENT_DLL
        if ( bIsMultiplayer() )
#else
        if ( g_pGameRules->IsMultiplayer() )
#endif
        {
                vecDir = m_pPlayer->FireBulletsPlayer( 4, vecSrc, vecAiming, VECTOR_CONE_DM_SHOTGUN, 2048, BULLET_PLAYER_BUCKSHOT, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
        }
        else
        {
                // regular old, untouched spread.
                vecDir = m_pPlayer->FireBulletsPlayer( 6, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 2048, BULLET_PLAYER_BUCKSHOT, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
        }
}

/*
================
FireBullets

Go to the trouble of combining multiple pellets into a single damage call.

This version is used by Players, uses the random seed generator to sync client and server side shots.
================
*/
Vector CBaseEntity::FireBulletsPlayer ( ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq, int iDamage, entvars_t *pevAttacker, int shared_rand )
{
        static int tracerCount;
        TraceResult tr;
        Vector vecRight = gpGlobals->v_right;
        Vector vecUp = gpGlobals->v_up;
        float x, y, z;

        if ( pevAttacker == NULL )
                pevAttacker = pev;  // the default attacker is ourselves

        ClearMultiDamage();
        gMultiDamage.type = DMG_BULLET | DMG_NEVERGIB;

        for ( ULONG iShot = 1; iShot <= cShots; iShot++ )
        {
                //Use player's random seed.
                // get circular gaussian spread
                x = UTIL_SharedRandomFloat( shared_rand + iShot, -0.5, 0.5 ) + UTIL_SharedRandomFloat( shared_rand + ( 1 + iShot ) , -0.5, 0.5 );
                y = UTIL_SharedRandomFloat( shared_rand + ( 2 + iShot ), -0.5, 0.5 ) + UTIL_SharedRandomFloat( shared_rand + ( 3 + iShot ), -0.5, 0.5 );
                z = x * x + y * y;

                Vector vecDir = vecDirShooting +
                                                x * vecSpread.x * vecRight +
                                                y * vecSpread.y * vecUp;
                Vector vecEnd;

                vecEnd = vecSrc + vecDir * flDistance;
                UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, ENT(pev)/*pentIgnore*/, &tr);
               
                // do damage, paint decals
                if (tr.flFraction != 1.0)
                {
                        CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);

                        if ( iDamage )
                        {
                                pEntity->TraceAttack(pevAttacker, iDamage, vecDir, &tr, DMG_BULLET | ((iDamage > 16) ? DMG_ALWAYSGIB : DMG_NEVERGIB) );
                               
                                TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
                                DecalGunshot( &tr, iBulletType );
                        }
                        else switch(iBulletType)
                        {
                        default:
                        case BULLET_PLAYER_9MM:               
                                pEntity->TraceAttack(pevAttacker, gSkillData.plrDmg9MM, vecDir, &tr, DMG_BULLET);
                                break;

                        case BULLET_PLAYER_MP5:               
                                pEntity->TraceAttack(pevAttacker, gSkillData.plrDmgMP5, vecDir, &tr, DMG_BULLET);
                                break;

                        case BULLET_PLAYER_BUCKSHOT:       
                                // make distance based!
                                pEntity->TraceAttack(pevAttacker, gSkillData.plrDmgBuckshot, vecDir, &tr, DMG_BULLET);
                                break;
                       
                        case BULLET_PLAYER_357:               
                                pEntity->TraceAttack(pevAttacker, gSkillData.plrDmg357, vecDir, &tr, DMG_BULLET);
                                break;
                               
                        case BULLET_NONE: // FIX
                                pEntity->TraceAttack(pevAttacker, 50, vecDir, &tr, DMG_CLUB);
                                TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
                                // only decal glass
                                if ( !FNullEnt(tr.pHit) && VARS(tr.pHit)->rendermode != 0)
                                {
                                        UTIL_DecalTrace( &tr, DECAL_GLASSBREAK1 + RANDOM_LONG(0,2) );
                                }

                                break;
                        }
                }
                // make bullet trails
                UTIL_BubbleTrail( vecSrc, tr.vecEndPos, (flDistance * tr.flFraction) / 64.0 );
        }
        ApplyMultiDamage(pev, pevAttacker);

        return Vector( x * vecSpread.x, y * vecSpread.y, 0.0 );
}


Arkshine 08-13-2009 07:24

Re: Create a shotgun burst with tracers
 
Quote:

Here! I have tested it! It works ;)


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

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