Guest User

Slice

a guest
Sep 25th, 2010
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.19 KB | None | 0 0
  1. /*
  2.     Extended wanted-level display filterscript.
  3.     -----------
  4.     This makes it possible to display more than the game's default max number of 6 wanted-level stars.
  5.     You can also change the number of "inactive stars" to fit your needs.
  6.     There are a few options below that you might want to adjust to fit your needs.
  7.    
  8.     What do I need to do in my other scripts?
  9.     Nothing! Simply use SetPlayerWantedLevel and this script will automatically notice changes then display them.
  10.    
  11.     Author: Slice
  12. */
  13.  
  14. #include <a_samp>
  15.  
  16. #define MAX_DISPLAYED_STARS     24      // Max number of wanted-level stars displayed, including the game's 6 stars.
  17. #define NUM_INACTIVE_STARS      16      // Number of inactive stars to display, including the game's 6 stars; put 6 to disable.
  18. #define STARS_PER_ROW           8       // The number of stars displayed on each row
  19. #define ROW_HEIGHT              20.0    // The height between rows; no need to edit this.
  20.  
  21. #undef MAX_PLAYERS
  22. #define MAX_PLAYERS             500     // Change this to whatever your server is using so you won't have lots of unused memory.
  23.  
  24. #if MAX_DISPLAYED_STARS <= 6
  25.     #error STARS_PER_ROW may only be > 6
  26. #endif
  27.  
  28. #if STARS_PER_ROW < 6
  29.     #error STARS_PER_ROW may only be >= 6
  30. #endif
  31.  
  32. #if NUM_INACTIVE_STARS < 6
  33.     #error NUM_INACTIVE_STARS may only be >= 6
  34. #endif
  35.  
  36. stock
  37.     g_UpdateTimer = -1,
  38.     g_aPreviousWantedLevel[ MAX_PLAYERS char ], // I use char here so the array will use only 1 byte per slot (no more is needed).
  39.     Text:g_aStarTextDraws[ MAX_DISPLAYED_STARS - 1 ],
  40.     Text:g_aInactiveStarTextDraws[ NUM_INACTIVE_STARS - 6 ]
  41. ;
  42.  
  43. public OnFilterScriptInit( )
  44. {
  45.     new
  46.         i,
  47.         #if STARS_PER_ROW > 6
  48.             col = 7,
  49.             row = 0
  50.         #else
  51.             col = 1,
  52.             row = 1
  53.         #endif
  54.     ;
  55.    
  56.     for ( i = 0; i < sizeof( g_aStarTextDraws ); i++ )
  57.     {
  58.         g_aStarTextDraws[ i ] = TextDrawCreate( 503.5 - ( 18.0 * ( col - 7 ) ), 102.1 + ( row * ROW_HEIGHT ), "]" );
  59.        
  60.         TextDrawColor           ( g_aStarTextDraws[ i ], 0x906210FF );
  61.         TextDrawBackgroundColor ( g_aStarTextDraws[ i ], 0x000000AA );
  62.         TextDrawFont            ( g_aStarTextDraws[ i ], 2 );
  63.         TextDrawSetShadow       ( g_aStarTextDraws[ i ], 0 );
  64.         TextDrawSetProportional ( g_aStarTextDraws[ i ], true );
  65.         TextDrawLetterSize      ( g_aStarTextDraws[ i ], 0.6, 2.4 );
  66.         TextDrawAlignment       ( g_aStarTextDraws[ i ], 3 );
  67.         TextDrawSetOutline      ( g_aStarTextDraws[ i ], 1 );
  68.        
  69.         if ( ++col > STARS_PER_ROW )
  70.         {
  71.             col = 1;
  72.            
  73.             ++row;
  74.         }
  75.     }
  76.    
  77.     #if NUM_INACTIVE_STARS > 6
  78.    
  79.     #if STARS_PER_ROW > 6
  80.         col = 7;
  81.         row = 0;
  82.     #else
  83.         col = 1;
  84.         row = 1;
  85.     #endif
  86.    
  87.     for ( i = 0; i < NUM_INACTIVE_STARS - 6; i++ )
  88.     {
  89.         g_aInactiveStarTextDraws[ i ] = TextDrawCreate( 503.0 - ( 18.0 * ( col - 7 ) ), 100.0 + ( row * ROW_HEIGHT ), "]" );
  90.        
  91.         TextDrawColor           ( g_aInactiveStarTextDraws[ i ], 0x00000070 );
  92.         TextDrawFont            ( g_aInactiveStarTextDraws[ i ], 2 );
  93.         TextDrawSetShadow       ( g_aInactiveStarTextDraws[ i ], 0 );
  94.         TextDrawSetProportional ( g_aInactiveStarTextDraws[ i ], true );
  95.         TextDrawLetterSize      ( g_aInactiveStarTextDraws[ i ], 0.72, 2.88 );
  96.         TextDrawAlignment       ( g_aInactiveStarTextDraws[ i ], 3 );
  97.         TextDrawSetOutline      ( g_aInactiveStarTextDraws[ i ], 0 );
  98.        
  99.         if ( ++col > STARS_PER_ROW )
  100.         {
  101.             col = 1;
  102.            
  103.             ++row;
  104.         }
  105.     }
  106.    
  107.     #endif
  108. }
  109.  
  110. public OnFilterScriptExit( )
  111. {
  112.     KillTimer( g_UpdateTimer );
  113.    
  114.     for ( new i = 0; i < sizeof( g_aStarTextDraws ); i++ )
  115.         TextDrawDestroy( g_aStarTextDraws[ i ] );
  116.    
  117.     #if NUM_INACTIVE_STARS > 6
  118.    
  119.     for ( new i = 0; i < sizeof( g_aInactiveStarTextDraws ); i++ )
  120.         TextDrawDestroy( g_aInactiveStarTextDraws[ i ] );
  121.    
  122.     #endif
  123. }
  124.  
  125. public OnPlayerUpdate( playerid )
  126. {
  127.     static
  128.         wantedLevel // I use static here so the variable won't have to be initialized each OnPlayerUpdate; therefore, more efficiency.
  129.     ;
  130.    
  131.     wantedLevel = GetPlayerWantedLevel( playerid );
  132.    
  133.     if ( g_aPreviousWantedLevel[ playerid ] != wantedLevel )
  134.     {
  135.         UpdatePlayerWantedLevel( playerid, g_aPreviousWantedLevel[ playerid ], wantedLevel );
  136.        
  137.         g_aPreviousWantedLevel[ playerid ] = wantedLevel;
  138.     }
  139.    
  140.     return 1;
  141. }
  142.  
  143. UpdatePlayerWantedLevel( playerid, oldlevel, newlevel )
  144. {
  145.     if ( oldlevel > 6 || newlevel > 6 )
  146.     {
  147.         for ( new i = min( oldlevel, newlevel ), j = max( oldlevel, newlevel ); i < j; i++ )
  148.         {
  149.             if ( i < 0 || i > sizeof( g_aStarTextDraws ) )
  150.                 continue;
  151.            
  152.             if ( i >= 6 )
  153.             {
  154.                 if ( i < newlevel )
  155.                 {
  156.                     TextDrawShowForPlayer( playerid, g_aStarTextDraws[ i - 6 ] );
  157.                    
  158.                     #if NUM_INACTIVE_STARS > 6
  159.                    
  160.                     if ( i < NUM_INACTIVE_STARS )
  161.                         TextDrawHideForPlayer( playerid, g_aInactiveStarTextDraws[ i - 6 ] );
  162.                    
  163.                     #endif
  164.                 }
  165.                 else
  166.                 {
  167.                     TextDrawHideForPlayer( playerid, g_aStarTextDraws[ i - 6 ] );
  168.                    
  169.                     #if NUM_INACTIVE_STARS > 6
  170.                    
  171.                     if ( i < NUM_INACTIVE_STARS )
  172.                         TextDrawShowForPlayer( playerid, g_aInactiveStarTextDraws[ i - 6 ] );
  173.                    
  174.                     #endif
  175.                 }
  176.             }
  177.         }
  178.     }
  179.    
  180.     #if NUM_INACTIVE_STARS > 6
  181.    
  182.     if ( oldlevel == 0 )
  183.     {
  184.         for ( new i = 0; i < NUM_INACTIVE_STARS - 6; i++ )
  185.         {
  186.             if ( i >= newlevel - 6 )
  187.                 TextDrawShowForPlayer( playerid, g_aInactiveStarTextDraws[ i ] );
  188.         }
  189.     }
  190.     else if ( newlevel == 0 )
  191.     {
  192.         for ( new i = 0; i < NUM_INACTIVE_STARS - 6; i++ )
  193.             TextDrawHideForPlayer( playerid, g_aInactiveStarTextDraws[ i ] );
  194.     }
  195.    
  196.     #endif
  197. }
Advertisement
Add Comment
Please, Sign In to add comment