Advertisement
Guest User

Basic Admin mode (MySQL) | By iRaiDeN

a guest
Apr 16th, 2014
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. #include    < a_samp >
  2. #include    < a_mysql >
  3. #include    < zcmd >
  4. //#include  < sscanf2 >
  5.  
  6. #define     DB_SERVER       "127.0.0.1"
  7. #define     DB_USER         "root"
  8. #define     DB_PASS         ""
  9. #define     DB_DB           "samp"
  10.  
  11. new
  12.     pLevel [ MAX_PLAYERS ] ,
  13.     pName [ 24 char ] ,
  14.     dbHandle ,
  15.     gQuery [ 356 char ] ;
  16.    
  17. public OnGameModeInit ( )
  18. {
  19.     dbHandle = mysql_connect ( DB_SERVER , DB_USER , DB_DB , DB_PASS ) ;
  20.     mysql_tquery ( dbHandle , "CREATE TABLE IF NOT EXISTS admin (username varchar(40),pAdminlevel int(6)" ) ;
  21. }
  22. public OnPlayerConnect ( playerid )
  23. {
  24.     GetPlayerName(playerid, pName , 24 ) ;
  25.     format ( gQuery , 128 , "SELECT * FROM admin WHERE username='%s'" , pName ) ;
  26.     mysql_function_query ( dbHandle , gQuery , 356 , "getPlayerData" , "i" , playerid ) ;
  27.     new localString [ 128 char ] ;
  28.     if ( pLevel [ playerid ] > 0 )
  29.     {
  30.         format ( localString , 128 , "[*Admin MOTD]: Welcome back [%s] *keep on the rules" , pName [ playerid ] ) ;
  31.         SendClientMessage ( playerid , -1 , localString ) ;
  32.     }
  33.     return 1 ;
  34. }
  35.  
  36. public OnPlayerDisconnect ( playerid , reason )
  37.     return pName [ playerid ] = EOS , 1 ;
  38.  
  39. COMMAND:makeadmin ( playerid , params [ ] )
  40. {
  41.     if ( pLevel [ playerid ] <= 0 || pLevel [ playerid ] < 5 || !IsPlayerAdmin ( playerid ) )
  42.         return SendClientMessage ( playerid , -1 , "[Error]: You aren't allowed to use this command!" ) ;
  43.     if ( sscanf ( params , "ud" , params [ 0 ] , params [ 1 ] ) )
  44.         return SendClientMessage ( playerid , -1 , "[Usage]: /MakeAdmin [ID] [Level]" ) ;
  45.     pLevel [ params [ 0 ] ] = params [ 1 ] ;
  46.     format ( gQuery , 356 , "INSERT INTO admin (username,pAdminlevel) VALUES ('%s','%d')" , pName [ playerid ] , params [ 1 ] ) ;
  47.     SendClientMessage ( playerid , -1 , "[*Admin]: Your'e promted this player to Admin Stuff*" ) ;
  48.     SendClientMessage ( params [ 0 ] , -1 , "[*Admin]: Welcome to the admin's stuff* (keep on the rules)" ) ;
  49.     return 1 ;
  50. }
  51.  
  52. COMMAND:aheal ( playerid , params [ ] )
  53. {
  54.     if ( pLevel [ playerid ] <= 0 )
  55.         return SendClientMessage ( playerid , -1 , "[Error]: You aren't allowed to use this command!" ) ;
  56.     if ( sscanf ( params , "ud" , params [ 0 ] ) )
  57.         return SendClientMessage ( playerid , -1 , "[Usage]: /AHeal [ID]" ) ;
  58.     SetPlayerHealth ( playerid , SetPlayerArmour ( playerid , 100 ) ) ;
  59.     return 1 ;
  60. }
  61.  
  62. forward getPlayerData ( playerid ) ;
  63. public getPlayerData ( playerid )
  64.     return pLevel [ playerid ] = cache_get_field_content_int ( 0 , "pAdminlevel" , dbHandle ) , 1 ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement