Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <fun>
- #include <dbi>
- //Lets declare necessary variables for dbi
- new Sql:dbc
- new Result:result
- new pCvarHost,
- pCvarUser,
- pCvarPass,
- pCvarDB
- //Lets declare variable for health
- new vip[ 33 ]
- //Plugin initialize
- public plugin_init( )
- {
- //Lets declare plugin name, version and author
- register_plugin("SMS VIP" , "0.1" , "Ardivaba" )
- //Now if user want's to know how to become vip
- register_clcmd("say /sms","DisplaySMS",-1,"")
- //Now if user want's to know how to become vip
- register_clcmd("say /vip","checkVIP",-1,"")
- //Lets forward new round start
- register_logevent("LogEventRoundStart", 2, "1=Round_Start")
- //Lets register cvars to connect mysql database
- pCvarHost = register_cvar("nick_mysql_host","127.0.0.1",FCVAR_PROTECTED)
- pCvarUser = register_cvar("nick_mysql_user","root",FCVAR_PROTECTED)
- pCvarPass = register_cvar("nick_mysql_pass","",FCVAR_PROTECTED)
- pCvarDB = register_cvar("nick_mysql_db","users",FCVAR_PROTECTED)
- sql_init()
- }
- //Scrap functinon
- public update( id )
- {
- return PLUGIN_HANDLED
- }
- //If player wants to see how to become vip...lets print him directions
- public DisplaySMS( id )
- {
- client_print( id, print_chat, "[SMSVIP] To become vip, send SMS: BVIP YourUsername to 13011." )
- }
- //When client connects, we will check if he's vip, dont we?
- public checkVIPdb( id )
- {
- //Lets declare some variables
- new query[ 256 ],VIP[ 32 ],name[ 32 ]
- //Lets get player's name into variable: name
- get_user_name( id, name, 31 )
- //Now lets format query
- format( query, 255, "SELECT vip FROM users WHERE username='%s'", name )
- //Lets get user's health, also errors will be in string: result
- result = dbi_query( dbc, query )
- //If we get some nice things, then we will set their health to array
- if( dbi_nextrow( result ) > 0 )
- {
- dbi_field( result, 1, VIP, 31 )
- //Lets set user's health to array
- vip[ id ] = str_to_num( VIP )
- }
- else
- {
- //Since we probably didnt get anything, we'll free result
- //To avoid memory leaks
- dbi_free_result( result )
- }
- }
- //!! This wont work for some reason !!
- public LogEventRoundStart( id )
- {
- //We will declare some variables for loop
- new Players[32]
- new playerCount, i
- new aPlayer
- //Lets get the number of players
- get_players(Players, playerCount)
- for (i=0; i<playerCount; i++)
- {
- aPlayer = Players[i]
- if( vip[aPlayer] )
- {
- checkVIPdb( aPlayer )
- client_print( aPlayer, print_chat, "[SMSVIP] You are vip, start owning!" )
- }
- }
- }
- //Check vip
- public checkVIP( id )
- {
- client_print( id, print_chat, "[SMSVIP] You VIP status is: %d", vip[ id ] )
- }
- //Lets initialize sql
- public sql_init( )
- {
- //Yay, usual variable declaring
- new host[ 64 ], username[ 33 ], password[ 32 ], dbname[ 32 ], error[ 32 ]
- //Now we're going to get some data to connect into database
- get_pcvar_string( pCvarHost, host, 64 )
- get_pcvar_string( pCvarUser, username, 32 )
- get_pcvar_string( pCvarPass, password, 32 )
- get_pcvar_string( pCvarDB, dbname, 32 )
- //Lets connect to the database and store errors in string: dbc
- dbc = dbi_connect( host, username, password, dbname, error, 32 )
- //Let's check if we get connection with database
- if (dbc == SQL_FAILED)
- {
- //Huston, we have a problem!
- server_print( "[SMSVIP] Could Not Connect To SQL Database^n" )
- }
- else
- {
- //Yay, we got some (milk?)
- server_print( "[SMSVIP] Connected To SQL, Have A Nice Day!^n" )
- }
- }
- /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
- *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1061\\ f0\\ fs16 \n\\ par }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement