Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2011
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. extern int gmsgCustomDecal;
  2.  
  3. void UTIL_CustomDecal( TraceResult *pTrace, const char *name, int persistent /* =0 */ )
  4. {
  5.     if (pTrace->flFraction == 1.0)
  6.         return;
  7.  
  8.     if ( pTrace->pHit )
  9.     {
  10.         int idx = ENTINDEX( pTrace->pHit );
  11.     //  ALERT(at_console, "%d\n", idx);
  12.         if (idx)
  13.             return;
  14.     }
  15.  
  16. //  ALERT(at_console, "sent\n");
  17.  
  18.     MESSAGE_BEGIN( MSG_BROADCAST, gmsgCustomDecal );
  19.         WRITE_COORD( pTrace->vecEndPos.x );
  20.         WRITE_COORD( pTrace->vecEndPos.y );
  21.         WRITE_COORD( pTrace->vecEndPos.z );
  22.         WRITE_COORD( pTrace->vecPlaneNormal.x );
  23.         WRITE_COORD( pTrace->vecPlaneNormal.y );
  24.         WRITE_COORD( pTrace->vecPlaneNormal.z );
  25.         WRITE_BYTE( persistent );
  26.         WRITE_STRING( name );
  27.     MESSAGE_END();
  28. }
  29.  
  30. void UTIL_BloodDecalTrace( TraceResult *pTrace, int bloodColor )
  31. {
  32.     if ( UTIL_ShouldShowBlood( bloodColor ) )
  33.     {
  34.         if ( bloodColor == BLOOD_COLOR_RED )
  35.         {
  36.             UTIL_DecalTrace( pTrace, DECAL_BLOOD1 + RANDOM_LONG(0,5) );
  37.             UTIL_CustomDecal( pTrace, "redblood" );
  38.         }
  39.         else
  40.         {
  41.             UTIL_DecalTrace( pTrace, DECAL_YBLOOD1 + RANDOM_LONG(0,5) );
  42.             UTIL_CustomDecal( pTrace, "yellowblood" );
  43.         }
  44.     }
  45. }
  46.  
  47.  
  48. void UTIL_DecalTrace( TraceResult *pTrace, int decalNumber )
  49. {
  50.     short entityIndex;
  51.     int index;
  52.     int message;
  53.  
  54.     if ( decalNumber < 0 )
  55.         return;
  56.  
  57.     index = gDecals[ decalNumber ].index;
  58.  
  59.     if ( index < 0 )
  60.         return;
  61.  
  62.     if (pTrace->flFraction == 1.0)
  63.         return;
  64.  
  65.     // buz: also paint custom decal
  66.     if (decalNumber == DECAL_SCORCH1 || decalNumber == DECAL_SCORCH2)
  67.     {
  68.         UTIL_CustomDecal( pTrace, "scorch" );
  69.     }
  70.  
  71.     // Only decal BSP models
  72.     if ( pTrace->pHit )
  73.     {
  74.         CBaseEntity *pEntity = CBaseEntity::Instance( pTrace->pHit );
  75.         if ( pEntity && !pEntity->IsBSPModel() )
  76.             return;
  77.         entityIndex = ENTINDEX( pTrace->pHit );
  78.     }
  79.     else
  80.         entityIndex = 0;
  81.  
  82.     message = TE_DECAL;
  83.     if ( entityIndex != 0 )
  84.     {
  85.         if ( index > 255 )
  86.         {
  87.             message = TE_DECALHIGH;
  88.             index -= 256;
  89.         }
  90.     }
  91.     else
  92.     {
  93.         message = TE_WORLDDECAL;
  94.         if ( index > 255 )
  95.         {
  96.             message = TE_WORLDDECALHIGH;
  97.             index -= 256;
  98.         }
  99.     }
  100.    
  101.     MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
  102.         WRITE_BYTE( message );
  103.         WRITE_COORD( pTrace->vecEndPos.x );
  104.         WRITE_COORD( pTrace->vecEndPos.y );
  105.         WRITE_COORD( pTrace->vecEndPos.z );
  106.         WRITE_BYTE( index );
  107.         if ( entityIndex )
  108.             WRITE_SHORT( entityIndex );
  109.     MESSAGE_END();
  110. }
  111.  
  112. /*
  113. ==============
  114. UTIL_PlayerDecalTrace
  115.  
  116. A player is trying to apply his custom decal for the spray can.
  117. Tell connected clients to display it, or use the default spray can decal
  118. if the custom can't be loaded.
  119. ==============
  120. */
  121. void UTIL_PlayerDecalTrace( TraceResult *pTrace, int playernum, int decalNumber, BOOL bIsCustom )
  122. {
  123.     int index;
  124.    
  125.     if (!bIsCustom)
  126.     {
  127.         if ( decalNumber < 0 )
  128.             return;
  129.  
  130.         index = gDecals[ decalNumber ].index;
  131.         if ( index < 0 )
  132.             return;
  133.     }
  134.     else
  135.         index = decalNumber;
  136.  
  137.     if (pTrace->flFraction == 1.0)
  138.         return;
  139.  
  140.     MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
  141.         WRITE_BYTE( TE_PLAYERDECAL );
  142.         WRITE_BYTE ( playernum );
  143.         WRITE_COORD( pTrace->vecEndPos.x );
  144.         WRITE_COORD( pTrace->vecEndPos.y );
  145.         WRITE_COORD( pTrace->vecEndPos.z );
  146.         WRITE_SHORT( (short)ENTINDEX(pTrace->pHit) );
  147.         WRITE_BYTE( index );
  148.     MESSAGE_END();
  149. }
  150.  
  151. void UTIL_GunshotDecalTrace( TraceResult *pTrace, int decalNumber )
  152. {
  153.     if ( decalNumber < 0 )
  154.         return;
  155.  
  156.     int index = gDecals[ decalNumber ].index;
  157.     if ( index < 0 )
  158.         return;
  159.  
  160.     if (pTrace->flFraction == 1.0)
  161.         return;
  162.  
  163.     MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, pTrace->vecEndPos );
  164.         WRITE_BYTE( TE_GUNSHOTDECAL );
  165.         WRITE_COORD( pTrace->vecEndPos.x );
  166.         WRITE_COORD( pTrace->vecEndPos.y );
  167.         WRITE_COORD( pTrace->vecEndPos.z );
  168.         WRITE_SHORT( (short)ENTINDEX(pTrace->pHit) );
  169.         WRITE_BYTE( index );
  170.     MESSAGE_END();
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement