IsraelNevo

[PAWN] Usp shop

Aug 6th, 2020
1,491
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*********** Include **************/
  2. #include < amxmodx >
  3. #include < fvault >
  4. #include < fakemeta >
  5. #include < hamsandwich >
  6.  
  7. /*********** Define **************/
  8. #define FOLDER "amxx/Usp/"
  9. #define USP_PATTERN "v_usp"
  10.  
  11. /*********** Native **************/
  12. native get_user_points(client)
  13. native set_user_points(client, amount)
  14.  
  15. /*********** News **************/
  16. new szVault[ ] = "UspSystem"
  17. new const szPrefix[] = "Fun"
  18.  
  19. enum _:UspItems
  20. {
  21.     numbermodel[ 33 ],
  22.     Name[ 33 ],
  23.     price
  24. }
  25.  
  26. new const UspInfo[ ][ UspItems ] =
  27. {
  28.     { 1, "Usp #1", 10000 },
  29.     { 2, "Usp #2", 20000 },
  30.     { 3, "Usp #3", 30000 },
  31.     { 4, "Usp #4", 40000 }
  32. }
  33.  
  34. new CurrentUsp[ 33 ]
  35. new UspStatus[ 33 ]
  36. new MAX_USP
  37.  
  38. /*********** Plugin Init **************/
  39. public plugin_init()
  40. {
  41.     register_plugin("Usp Shop", "v1.0", "Unnkown + Shon")
  42.    
  43.     register_clcmd("say /usp","CmdUsp")
  44.    
  45.     RegisterHam( Ham_Item_Deploy, "weapon_usp", "OnUspDeploy", 1 )
  46. }
  47.  
  48. /*********** Precache **************/
  49. public plugin_precache( )
  50. {  
  51.     MAX_USP = sizeof( UspInfo )
  52.    
  53.     new szTemp[ 120 ]
  54.    
  55.     for( new i = 0 ; i < MAX_USP ; i++ )
  56.     {
  57.         formatex( szTemp, charsmax( szTemp ), "models/%s%s%d.mdl", FOLDER, USP_PATTERN, UspInfo[ i ][ numbermodel ] )
  58.        
  59.         precache_model( szTemp )
  60.     }
  61. }
  62.  
  63. /*********** Dis/connect **************/
  64. public client_putinserver( index )
  65. {
  66.     CurrentUsp[ index ] = 0
  67.     CmdLoad( index )
  68. }
  69.  
  70. public client_disconnect( client )
  71. {
  72.     CmdSave( client )
  73. }
  74.  
  75. /*********** Deploy **************/
  76. public OnUspDeploy( iEnt )
  77. {
  78.     if( pev_valid( iEnt ) != 2 )
  79.         return
  80.        
  81.     static id
  82.    
  83.     id = get_pdata_cbase( iEnt, 41, 4 )
  84.    
  85.     if( !is_user_alive( id ) )
  86.         return
  87.    
  88.     Change_Usp_Model( id )
  89. }
  90.  
  91. /*********** Usp menu **************/
  92. public CmdUsp( client )
  93. {
  94.     new szItem[ 208 ]
  95.    
  96.     formatex( szItem, charsmax( szItem ), "\r[\w %s \r] \wUsp Shop", szPrefix )
  97.     new menu = menu_create( szItem, "handler" )
  98.    
  99.     for ( new i = 0; i < sizeof( UspInfo ); i++ )
  100.     {
  101.         if( i <= UspStatus[ client ]-1 )
  102.             formatex( szItem, charsmax( szItem ), "%s %s", UspInfo[ i ][ Name ], CurrentUsp[ client ]-1 == i ? "\d- \yUsing" : "" )
  103.         else
  104.             formatex( szItem, charsmax( szItem ), "%s \r[ %i Cash ]", UspInfo[ i ][ Name ], UspInfo[ i ][ price ] )
  105.    
  106.         menu_additem( menu, szItem )
  107.     }
  108.    
  109.     menu_display( client, menu )
  110.     return 1
  111. }
  112.  
  113. /*********** Usp handler **************/
  114. public handler( client, menu, item )
  115. {
  116.     if( item == MENU_EXIT )
  117.     {
  118.         menu_destroy( menu )
  119.         return 1
  120.     }
  121.  
  122.     if( item > UspStatus[ client ] )
  123.         return ColorChat( client, "You have to buy the ^3previous^1 usp." )
  124.  
  125.     if( item == CurrentUsp[ client ]-1 )
  126.         return ColorChat( client, "You ^3already^1 use this ^3usp^1" )
  127.        
  128.     if( item <= UspStatus[ client ]-1 )
  129.     {
  130.         if( is_user_alive( client ) && get_user_weapon( client ) == CSW_USP )
  131.             Change_Usp_Model( client )
  132.        
  133.         CurrentUsp[ client ] = item+1
  134.        
  135.         ColorChat( client, "You have been used:^3 %s^1.", UspInfo[ item ][ Name ] )
  136.        
  137.         CmdSave( client )
  138.         return 1
  139.     }
  140.        
  141.     if( get_user_points( client ) >= UspInfo[ item ][ price ] )
  142.     {
  143.         if( is_user_alive( client ) && get_user_weapon( client ) == CSW_USP )
  144.             Change_Usp_Model( client )
  145.        
  146.         UspStatus[ client ]++
  147.         CurrentUsp[ client ] = item+1
  148.        
  149.         set_user_points( client, get_user_points( client ) - UspInfo[ item ][ price ] )
  150.        
  151.         ColorChat( client, "You have been used:^3 %s^1.", UspInfo[ item ][ Name ] )
  152.        
  153.         CmdSave( client )
  154.         return 1
  155.     }
  156.     else
  157.     {
  158.         ColorChat( client, "You don't have enough points. Missing: ^3%i ^1points.", UspInfo[ item ][ price ] - get_user_points( client ) )
  159.        
  160.         CmdUsp( client )
  161.         return 1
  162.     }
  163.     return 1
  164. }
  165.  
  166. /*********** Save/Load **************/
  167. stock CmdSave(index)
  168. {
  169.     if(is_user_bot(index) || is_user_hltv(index))
  170.         return
  171.    
  172.     new szKey[ 64 ], szData[ 256 ]
  173.     formatex( szKey, charsmax( szKey ), "%s", GetAuth( index ) )
  174.     formatex( szData, charsmax( szData ), "%i %i %s", UspStatus[ index ], CurrentUsp[ index ], GetUserName( index ))
  175.     fvault_set_data( szVault, szKey, szData )
  176. }
  177.  
  178. stock CmdLoad( index )
  179. {
  180.     new szKey[ 64 ], szData[ 256 ]
  181.    
  182.     formatex( szKey, charsmax( szKey ), "%s", GetAuth( index ) )
  183.    
  184.     formatex( szData, charsmax( szData ), "%i %i %s", UspStatus[ index ], CurrentUsp[ index ], GetUserName( index ))
  185.     fvault_get_data( szVault, szKey, szData, 255 )
  186.    
  187.     new SetData[ 2 ][ 32 ]
  188.     parse( szData, SetData[ 0 ], 31, SetData[ 1 ], 31  )
  189.    
  190.     UspStatus[ index ] = str_to_num( SetData[ 0 ] )
  191.     CurrentUsp[ index ] = str_to_num( SetData[ 1 ] )
  192. }
  193.  
  194. /*********** Stocks **************/
  195. stock GetUserName( client )
  196. {
  197.     new szName[ 33 ]
  198.    
  199.     get_user_name( client, szName, charsmax( szName ) )
  200.    
  201.     return szName
  202. }
  203. stock GetAuth( id )
  204. {
  205.     static szAuth[ 60 ]
  206.     get_user_authid( id, szAuth, charsmax( szAuth ) )
  207.     if( contain( szAuth, "VALVE_" ) != -1 || contain( szAuth, "ID_LAN" ) != -1 )
  208.     get_user_ip( id, szAuth, charsmax( szAuth ), 1 )
  209.     return szAuth
  210. }
  211.  
  212. stock Change_Usp_Model( id )
  213. {
  214.     new szTemp[ 120 ]
  215.    
  216.     formatex( szTemp, charsmax( szTemp ), "models/%s%s%d.mdl", FOLDER, USP_PATTERN, UspInfo[ CurrentUsp[ id ]-1 ][ numbermodel ])
  217.        
  218.     set_pev( id, pev_viewmodel2, szTemp )
  219. }
  220.  
  221. stock ColorChat(const id, const string[], {Float, Sql, Resul,_}:...)
  222. {
  223.     new msg[191], players[32], count = 1
  224.    
  225.     static len
  226.     len = formatex(msg, charsmax(msg), "^3[^1 %s^3 ]^1 ", szPrefix )
  227.     vformat(msg[len], charsmax(msg) - len, string, 3)
  228.    
  229.     if(id)
  230.         players[0] = id
  231.     else
  232.         get_players(players,count,"ch")
  233.    
  234.     for (new i = 0; i < count; i++)
  235.     {
  236.         if(is_user_connected(players[i]))
  237.         {
  238.             message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, players[i])
  239.             write_byte(players[i])
  240.             write_string(msg)
  241.             message_end()
  242.         }
  243.     }
  244.     return 0
  245. }
RAW Paste Data