Advertisement
RanAway

[ Pawn ] Speed o meter

Jun 22nd, 2024 (edited)
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.08 KB | None | 0 0
  1. /************* includes ***************/
  2. #include < amxmodx >
  3. #include < fakemeta >
  4.  
  5. /************* defines ***************/
  6. #define Prefix          "AMXX"
  7.  
  8. /************* news ***************/
  9. new showspeed[ 33 ], speedcolor[ 33 ][ 4 ], Float:speedpos[ 33 ][ 3 ]
  10.  
  11. /************* plugin init ************/
  12. public plugin_init()
  13. {
  14.     register_plugin( "speedometer", "v1.0", "RanAway" )
  15.    
  16.     /************* commands ************/
  17.     register_clcmd( "say /speed", "speedometermenu" )
  18.    
  19.     /************* show speed hud ************/
  20.     set_task( 0.1, "speedometer", 0, _, _, "b" )
  21. }
  22.  
  23. /************* connect ************/
  24. public client_connect( id )
  25. {
  26.     /************* speed hud status ************/
  27.     showspeed[ id ] = true
  28.    
  29.     /************* speed hud color ************/
  30.     speedcolor[ id ][ 1 ] = 85
  31.     speedcolor[ id ][ 2 ] = 85
  32.     speedcolor[ id ][ 3 ] = 85
  33.    
  34.     /************* speed hud position ************/
  35.     speedpos[ id ][ 1 ] = 0.47
  36.     speedpos[ id ][ 2 ] = 0.80
  37. }
  38.  
  39. /************* speedometer menu ***********/
  40. public speedometermenu( id )
  41. {
  42.     new item[ 250 ]
  43.    
  44.     formatex( item, charsmax( item ), "\r[\w %s \r]\w speed o meter menu", Prefix )
  45.     new menu = menu_create( item, "sub_speedometermenu" )
  46.    
  47.     formatex( item, charsmax( item ), "status: %sactivated^n", showspeed[ id ] ? "\y" : "\rde" )
  48.     menu_additem( menu, item )
  49.    
  50.     menu_additem( menu, "change colors" )
  51.     menu_additem( menu, "change position" )
  52.    
  53.     menu_addtext( menu, "^n\d----------\r details\d -----------" )
  54.    
  55.     formatex( item, charsmax( item ), "\wcolors: \y|\r R: \y%i \y|\r G: \y%i \y|\r B: \y%i", speedcolor[ id ][ 1 ], speedcolor[ id ][ 2 ], speedcolor[ id ][ 3 ] )
  56.     menu_addtext( menu, item )
  57.    
  58.     formatex( item, charsmax( item ), "\wposition: \y|\r X: \y%.2f \y|\r Y: \y%.2f", speedpos[ id ][ 1 ], speedpos[ id ][ 2 ] )
  59.     menu_addtext( menu, item )
  60.    
  61.     menu_display( id, menu )
  62.     return 1
  63. }
  64.  
  65. public sub_speedometermenu( id, menu, item )
  66. {
  67.     if( item == MENU_EXIT ) return menu_destroy( menu )
  68.    
  69.     /************* de / activate speed hud ***********/
  70.     if( item == 0 ) showspeed[ id ] = !showspeed[ id ]
  71.     if( item == 1 ) return colorsmenu( id )
  72.     if( item == 2 ) return positionmenu( id )
  73.    
  74.     return speedometermenu( id )
  75. }
  76.  
  77. /************* position menu ***********/
  78. public positionmenu( id )
  79. {
  80.     new item[ 250 ]
  81.    
  82.     formatex( item, charsmax( item ), "\r[\w %s \r]\w position menu", Prefix )
  83.     new menu = menu_create( item, "sub_positionmenu" )
  84.    
  85.     menu_additem( menu, "move left \r<<<<<<",_, .callback = menu_makecallback( "blockposition" ) )
  86.     menu_additem( menu, "move right \r>>>>>>^n",_, .callback = menu_makecallback( "blockposition" ) )
  87.     menu_additem( menu, "move up \r^^^^^^^^^^^^ ",_, .callback = menu_makecallback( "blockposition" ) )
  88.     menu_additem( menu, "move down \rvvvvvv^n",_, .callback = menu_makecallback( "blockposition" ) )
  89.    
  90.     formatex( item, charsmax( item ), "\wposition: \y|\r X: \y%.2f \y|\r Y: \y%.2f", speedpos[ id ][ 1 ], speedpos[ id ][ 2 ] )
  91.     menu_addtext( menu, item )
  92.    
  93.     menu_setprop( menu, MPROP_EXITNAME, "back to menu" )
  94.     menu_display( id, menu )
  95.     return 1
  96. }
  97.  
  98. public sub_positionmenu( id, menu, item )
  99. {
  100.     if( item == MENU_EXIT ) return speedometermenu( id )
  101.    
  102.     /************* change X position ***********/
  103.     if( item == 0 && speedpos[ id ][ 1 ] > 0.01 ) speedpos[ id ][ 1 ] -= 0.01
  104.     if( item == 1 && speedpos[ id ][ 1 ] < 1.00 ) speedpos[ id ][ 1 ] += 0.01
  105.    
  106.     /************* change Y position ***********/
  107.     if( item == 2 && speedpos[ id ][ 2 ] > 0.01 ) speedpos[ id ][ 2 ] -= 0.01
  108.     if( item == 3 && speedpos[ id ][ 2 ] < 1.00 ) speedpos[ id ][ 2 ] += 0.01
  109.    
  110.     return positionmenu( id )
  111. }
  112.  
  113. /************* block positions ***********/
  114. public blockposition( id, menu, item )
  115. {
  116.     /************* X position ***********/
  117.     if( item == 0 && speedpos[ id ][ 1 ] <= 0.01 ) return ITEM_DISABLED
  118.     if( item == 1 && speedpos[ id ][ 1 ] >= 1.00 ) return ITEM_DISABLED
  119.    
  120.     /************* Y position ***********/
  121.     if( item == 2 && speedpos[ id ][ 2 ] <= 0.01 ) return ITEM_DISABLED
  122.     if( item == 3 && speedpos[ id ][ 2 ] >= 1.00 ) return ITEM_DISABLED
  123.    
  124.     return 1
  125. }
  126.  
  127. /************* colors menu ***********/
  128. public colorsmenu( id )
  129. {
  130.     new item[ 250 ]
  131.    
  132.     formatex( item, charsmax( item ), "\r[\w %s \r]\w colors menu", Prefix )
  133.     new menu = menu_create( item, "sub_colorsmenu" )
  134.    
  135.     menu_additem( menu, "R \y-\r ++",_, .callback = menu_makecallback( "blockcolors" ) )
  136.     menu_additem( menu, "R \y-\r --^n",_, .callback = menu_makecallback( "blockcolors" ) )
  137.    
  138.     menu_additem( menu, "G \y-\r ++",_, .callback = menu_makecallback( "blockcolors" ) )
  139.     menu_additem( menu, "G \y-\r --^n",_, .callback = menu_makecallback( "blockcolors" ) )
  140.    
  141.     menu_additem( menu, "B \y-\r ++",_, .callback = menu_makecallback( "blockcolors" ) )
  142.     menu_additem( menu, "B \y-\r --^n",_, .callback = menu_makecallback( "blockcolors" ) )
  143.    
  144.     formatex( item, charsmax( item ), "\wcolors: \y|\r R: \y%i \y|\r G: \y%i \y|\r B: \y%i", speedcolor[ id ][ 1 ], speedcolor[ id ][ 2 ], speedcolor[ id ][ 3 ] )
  145.     menu_addtext( menu, item )
  146.    
  147.     menu_setprop( menu, MPROP_EXITNAME, "back to menu" )
  148.     menu_display( id, menu )
  149.     return 1
  150. }
  151.  
  152. public sub_colorsmenu( id, menu, item )
  153. {
  154.     if( item == MENU_EXIT ) return speedometermenu( id )
  155.    
  156.     /************* change R position ***********/
  157.     if( item == 0 && speedcolor[ id ][ 1 ] < 255 ) speedcolor[ id ][ 1 ] += 5
  158.     if( item == 1 && speedcolor[ id ][ 1 ] > 0 ) speedcolor[ id ][ 1 ] -= 5
  159.    
  160.     /************* change G position ***********/
  161.     if( item == 2 && speedcolor[ id ][ 2 ] < 255 ) speedcolor[ id ][ 2 ] += 5
  162.     if( item == 3 && speedcolor[ id ][ 2 ] > 0 ) speedcolor[ id ][ 2 ] -= 5
  163.    
  164.     /************* change B position ***********/
  165.     if( item == 4 && speedcolor[ id ][ 3 ] < 255 ) speedcolor[ id ][ 3 ] += 5
  166.     if( item == 5 && speedcolor[ id ][ 3 ] > 0 ) speedcolor[ id ][ 3 ] -= 5
  167.    
  168.     return colorsmenu( id )
  169. }
  170.  
  171. /************* block colors ***********/
  172. public blockcolors( id, menu, item )
  173. {
  174.     /************* change R position ***********/
  175.     if( item == 0 && speedcolor[ id ][ 1 ] >= 255 ) return ITEM_DISABLED
  176.     if( item == 1 && speedcolor[ id ][ 1 ] <= 0 ) return ITEM_DISABLED
  177.    
  178.     /************* change G position ***********/
  179.     if( item == 2 && speedcolor[ id ][ 2 ] >= 255 ) return ITEM_DISABLED
  180.     if( item == 3 && speedcolor[ id ][ 2 ] <= 0 ) return ITEM_DISABLED
  181.    
  182.     /************* change B position ***********/
  183.     if( item == 4 && speedcolor[ id ][ 3 ] >= 255 ) return ITEM_DISABLED
  184.     if( item == 5 && speedcolor[ id ][ 3 ] <= 0 ) return ITEM_DISABLED
  185.    
  186.     return 1
  187. }
  188.  
  189. /************* speedometer ***********/
  190. public speedometer()
  191. {
  192.     new Float:speed, Float:speedf, Float:velocity[ 3 ]
  193.    
  194.     for( new i; i < get_maxplayers(); i++ )
  195.     {
  196.         if( !is_user_connected( i ) || !is_user_alive( i ) || !showspeed[ i ] ) continue
  197.        
  198.         pev( i, pev_velocity, velocity )
  199.         speed   = vector_length( velocity )
  200.             speedf  = floatsqroot( floatpower( velocity[ 0 ], 2.0 ) + floatpower( velocity[ 1 ], 2.0 ) )
  201.        
  202.         set_hudmessage( speedcolor[ i ][ 1 ], speedcolor[ i ][ 2 ], speedcolor[ i ][ 3 ], speedpos[ i ][ 1 ], speedpos[ i ][ 2 ], 0, 0.0, 0.1, 0.01, 0.0 )
  203.         ShowSyncHudMsg( i, CreateHudSyncObj(), "velocity: %3.2f", speed, speedf )
  204.     }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement