Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.62 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fun>
  3. #include <dbi>
  4.  
  5. //Lets declare necessary variables for dbi
  6. new Sql:dbc
  7. new Result:result
  8.  
  9. new pCvarHost,
  10.     pCvarUser,
  11.     pCvarPass,
  12.     pCvarDB
  13.  
  14. //Lets declare variable for health
  15. new vip[ 33 ]
  16.  
  17. //Plugin initialize
  18. public plugin_init( )
  19. {
  20.     //Lets declare plugin name, version and author
  21.     register_plugin("SMS VIP" , "0.1" , "Ardivaba" )
  22.    
  23.     //Now if user want's to know how to become vip
  24.     register_clcmd("say /sms","DisplaySMS",-1,"")
  25.    
  26.     //Now if user want's to know how to become vip
  27.     register_clcmd("say /vip","checkVIP",-1,"")
  28.  
  29.     //Lets forward new round start
  30.     register_logevent("LogEventRoundStart", 2, "1=Round_Start")
  31.  
  32.     //Lets register cvars to connect mysql database
  33.     pCvarHost = register_cvar("nick_mysql_host","127.0.0.1",FCVAR_PROTECTED)
  34.     pCvarUser = register_cvar("nick_mysql_user","root",FCVAR_PROTECTED)
  35.     pCvarPass = register_cvar("nick_mysql_pass","",FCVAR_PROTECTED)
  36.     pCvarDB = register_cvar("nick_mysql_db","users",FCVAR_PROTECTED)
  37.     sql_init()
  38.  
  39. }
  40.  
  41. //Scrap functinon
  42. public update( id )
  43. {
  44.     return PLUGIN_HANDLED
  45. }
  46.  
  47. //If player wants to see how to become vip...lets print him directions
  48. public DisplaySMS( id )
  49. {
  50.     client_print( id, print_chat, "[SMSVIP] To become vip, send SMS: BVIP YourUsername to 13011." )
  51. }
  52.  
  53. //When client connects, we will check if he's vip, dont we?
  54. public checkVIPdb( id )
  55. {
  56.     //Lets declare some variables
  57.     new query[ 256 ],VIP[ 32 ],name[ 32 ]
  58.     //Lets get player's name into variable: name
  59.     get_user_name( id, name, 31 )
  60.     //Now lets format query
  61.     format( query, 255, "SELECT vip FROM users WHERE username='%s'", name )
  62.     //Lets get user's health, also errors will be in string: result
  63.     result = dbi_query( dbc, query )
  64.     //If we get some nice things, then we will set their health to array
  65.     if( dbi_nextrow( result ) > 0 )
  66.         {
  67.         dbi_field( result, 1, VIP, 31 )
  68.         //Lets set user's health to array
  69.         vip[ id ] = str_to_num( VIP )
  70.         }
  71.         else
  72.         {
  73.         //Since we probably didnt get anything, we'll free result
  74.         //To avoid memory leaks
  75.         dbi_free_result( result )
  76.         }
  77. }
  78.  
  79. //!! This wont work for some reason !!
  80. public LogEventRoundStart( id )
  81. {
  82.     //We will declare some variables for loop
  83.     new Players[32]
  84.     new playerCount, i
  85.     new aPlayer
  86.     //Lets get the number of players
  87.     get_players(Players, playerCount)
  88.     for (i=0; i<playerCount; i++)
  89.     {
  90.         aPlayer = Players[i]
  91.         if( vip[aPlayer] )
  92.         {
  93.             checkVIPdb( aPlayer )
  94.             client_print( aPlayer, print_chat, "[SMSVIP] You are vip, start owning!" )
  95.         }
  96.     }
  97. }
  98.  
  99. //Check vip
  100. public checkVIP( id )
  101. {
  102.     client_print( id, print_chat, "[SMSVIP] You VIP status is: %d", vip[ id ] )
  103. }  
  104.  
  105. //Lets initialize sql
  106. public sql_init( )
  107. {
  108.     //Yay, usual variable declaring
  109.     new host[ 64 ], username[ 33 ], password[ 32 ], dbname[ 32 ], error[ 32 ]
  110.     //Now we're going to get some data to connect into database
  111.     get_pcvar_string( pCvarHost, host, 64 )
  112.     get_pcvar_string( pCvarUser, username, 32 )
  113.     get_pcvar_string( pCvarPass, password, 32 )
  114.     get_pcvar_string( pCvarDB, dbname, 32 )
  115.     //Lets connect to the database and store errors in string: dbc
  116.     dbc = dbi_connect( host, username, password, dbname, error, 32 )
  117.     //Let's check if we get connection with database
  118.     if (dbc == SQL_FAILED)
  119.         {
  120.         //Huston, we have a problem!
  121.         server_print( "[SMSVIP] Could Not Connect To SQL Database^n" )
  122.         }
  123.         else
  124.         {
  125.         //Yay, we got some (milk?)
  126.         server_print( "[SMSVIP] Connected To SQL, Have A Nice Day!^n" )
  127.         }
  128. }
  129. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  130. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1061\\ f0\\ fs16 \n\\ par }
  131. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement