Advertisement
Guest User

script

a guest
Nov 10th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.36 KB | None | 0 0
  1. new _fileData[256][11][256]
  2. new _fileCount
  3.  
  4. public plugin_init()
  5. {
  6.     register_plugin( PLUGIN, VERSION, AUTHOR )
  7.     _loadFile("cmdtext.txt")
  8. }
  9.  
  10. public _loadFile(filename[64])
  11. {
  12.     new config[64], file
  13.     get_configsdir(config, charsmax(config))
  14.     format(filename, charsmax(filename), "%s/%s", config, filename)
  15.    
  16.     if(!file_exists(filename))
  17.     {
  18.         write_file(filename, "; This file has been created automatically")
  19.         write_file(filename, "; ")
  20.         write_file(filename, "; Example: ^"command_name^" ^"acces required (ex: d)^", s:arg1, s:arg2, n:arg3, n:arg4, f:arg5, f:arg6, s:arg7, ^"Text you want to print on chat^"")
  21.         write_file(filename, "; Replace args with targetname to get the name of target")
  22.         write_file(filename, "; Replace args with adminname to get the name of admin")
  23.         write_file(filename, "; s: = string; n: = num; f: = float")
  24.     }
  25.     file = fopen(filename,"r")
  26.    
  27.     if (file)
  28.     {
  29.         while (!feof(file))
  30.         {
  31.             fgets(file,_fileData[_fileCount][0],charsmax(_fileData[][]))
  32.             trim(_fileData[_fileCount][0])
  33.            
  34.             if (_fileData[_fileCount][0][0] != '"')
  35.                 continue;
  36.                        
  37.             if (parse(_fileData[_fileCount][0],
  38.                         _fileData[_fileCount][1],charsmax(_fileData[][]), // command
  39.                         _fileData[_fileCount][2],charsmax(_fileData[][]), // access required
  40.                         _fileData[_fileCount][3],charsmax(_fileData[][]), // argument 1
  41.                         _fileData[_fileCount][4],charsmax(_fileData[][]), // argument 2
  42.                         _fileData[_fileCount][5],charsmax(_fileData[][]), // argument 3
  43.                         _fileData[_fileCount][6],charsmax(_fileData[][]), // argument 4
  44.                         _fileData[_fileCount][7],charsmax(_fileData[][]), // argument 5
  45.                         _fileData[_fileCount][8],charsmax(_fileData[][]), // argument 6
  46.                         _fileData[_fileCount][9],charsmax(_fileData[][]), // argument 7
  47.                         _fileData[_fileCount][10],charsmax(_fileData[][])) < 2) // text format
  48.             {
  49.                 log_amx("[err] Line %d is wrong formatted!", _fileCount)
  50.                 continue;
  51.             }
  52.            
  53.             log_amx("[debug] #%d: %s", _fileCount, _fileData[_fileCount][0])
  54.             log_amx("[debug] #%d: %s %s %s %s %s %s %s %s %s %s", _fileCount,
  55.                 _fileData[_fileCount][1],
  56.                 _fileData[_fileCount][2],
  57.                 _fileData[_fileCount][3],
  58.                 _fileData[_fileCount][4],
  59.                 _fileData[_fileCount][5],
  60.                 _fileData[_fileCount][6],
  61.                 _fileData[_fileCount][7],
  62.                 _fileData[_fileCount][8],
  63.                 _fileData[_fileCount][9],
  64.                 _fileData[_fileCount][10])
  65.            
  66.             _fileCount++;
  67.             if(_fileCount > 255)
  68.             {
  69.                 log_amx("[err] Too many lines in the file, max allowed are 256 lines!")
  70.                 break;
  71.             }
  72.         }
  73.         fclose(file);
  74.     }
  75.     server_print("[AMXX] Loaded %d command%s from file.", _fileCount, _fileCount == 1 ? "" : "s")
  76.     return PLUGIN_HANDLED
  77. }
  78.  
  79. public client_command(id)
  80. {
  81.     new command[32], argument = 1, paramsplit[11][5][64], message[192], count = 0, Float:floatmsg
  82.     read_argv(0, command, charsmax(command))
  83.    
  84.     if(get_cvar_num("amx_show_activity") == 0)
  85.     {
  86.         for(new i; i < _fileCount; i++)
  87.         {
  88.             if(equali(command, _fileData[i][1]))
  89.             {
  90.                 log_amx("[debug] Command '%s' detected", _fileData[i][1])
  91.                 if(get_user_flags(id) & read_flags(_fileData[i][2]))
  92.                 {
  93.                     log_amx("[debug] Access '%s' detected", _fileData[i][2])
  94.                     for(new a; a < 11; a++)
  95.                     {
  96.                         if(_fileData[i][a][1] == ':')
  97.                         {
  98.                             log_amx("[debug] Delimiter ':' detected")
  99.                             paramsplit[a][4][0] = -1
  100.                             split(_fileData[i][a], paramsplit[a][0], 63, paramsplit[a][1], 63, ":")
  101.                            
  102.                             log_amx("[debug] String splited into '%s' and '%s'", paramsplit[a][0], paramsplit[a][1])
  103.                             if(paramsplit[a][0][0] == 's') // string
  104.                                 paramsplit[a][4][0] = 1
  105.                             else if(paramsplit[a][0][0] == 'n') // integer (num)
  106.                                 paramsplit[a][4][0] = 2
  107.                             else if(paramsplit[a][0][0] == 'f') // float
  108.                                 paramsplit[a][4][0] = 3
  109.                                
  110.                             if(equali(paramsplit[a][1], "targetname"))
  111.                             {
  112.                                 read_argv(argument, paramsplit[a][1], charsmax(paramsplit[][]))
  113.                                 paramsplit[a][3][0] = cmd_target(id, paramsplit[a][1], CMDTARGET_OBEY_IMMUNITY | CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF)
  114.                                 get_user_name(paramsplit[a][3][0], paramsplit[a][0], charsmax(paramsplit[][]))
  115.                                 argument++;
  116.                                 log_amx("[debug] A target name has been found")
  117.                                 log_amx("[debug] Name returned: '%s'", paramsplit[a][0])
  118.                                
  119.                             }
  120.                             else if(equali(paramsplit[a][1], "adminname"))
  121.                             {
  122.                                 log_amx("[debug] An admin name has been found")
  123.                                 get_user_name(id, paramsplit[a][0], charsmax(paramsplit[][]))
  124.                                 log_amx("[debug] Name returned: '%s'", paramsplit[a][0])
  125.                             }
  126.                             else
  127.                             {
  128.                                 log_amx("[debug] Argument %s has been found !", paramsplit[a][1])
  129.                                 read_argv(argument, paramsplit[a][1], charsmax(paramsplit[][]))
  130.                                 formatex(paramsplit[a][0], charsmax(paramsplit[][]), "%s", paramsplit[a][1])
  131.                                 argument++;
  132.                                 log_amx("[debug] Message returned: '%s'", paramsplit[a][0])
  133.                             }
  134.                                
  135.                             if(paramsplit[a][4][0] == 2)
  136.                                 paramsplit[a][0][0] = str_to_num(paramsplit[a][1])
  137.                             else if(paramsplit[a][4][0] == 3)
  138.                                 floatmsg = str_to_float(paramsplit[a][1])
  139.                             count++;
  140.                         }
  141.                     }
  142.                     log_amx("[debug] Loop stopped at %d arguments!", count)
  143.                     switch(count)
  144.                     {
  145.                         case 1:
  146.                         {
  147.                             formatex(message, charsmax(message), _fileData[i][10],
  148.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0])
  149.                             log_amx("[debug] Message '%s' has been formatted!", message)
  150.                         }
  151.                         case 2:
  152.                         {   formatex(message, charsmax(message), _fileData[i][10],
  153.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0],
  154.                                 (paramsplit[4][4][0] == 3) ? floatmsg : paramsplit[4][0])
  155.                             log_amx("[debug] Message '%s' has been formatted!", message)
  156.                         }
  157.                         case 3:
  158.                         {
  159.                             formatex(message, charsmax(message), _fileData[i][10],
  160.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0],
  161.                                 (paramsplit[4][4][0] == 3) ? floatmsg : paramsplit[4][0],
  162.                                 (paramsplit[5][4][0] == 3) ? floatmsg : paramsplit[5][0])
  163.                             log_amx("[debug] Message '%s' has been formatted!", message)
  164.                         }
  165.                         case 4:
  166.                         {
  167.                             formatex(message, charsmax(message), _fileData[i][10],
  168.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0],
  169.                                 (paramsplit[4][4][0] == 3) ? floatmsg : paramsplit[4][0],
  170.                                 (paramsplit[5][4][0] == 3) ? floatmsg : paramsplit[5][0],
  171.                                 (paramsplit[6][4][0] == 3) ? floatmsg : paramsplit[6][0])
  172.                             log_amx("[debug] Message '%s' has been formatted!", message)
  173.                         }
  174.                         case 5:
  175.                         {  
  176.                             formatex(message, charsmax(message), _fileData[i][10],
  177.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0],
  178.                                 (paramsplit[4][4][0] == 3) ? floatmsg : paramsplit[4][0],
  179.                                 (paramsplit[5][4][0] == 3) ? floatmsg : paramsplit[5][0],
  180.                                 (paramsplit[6][4][0] == 3) ? floatmsg : paramsplit[6][0],
  181.                                 (paramsplit[7][4][0] == 3) ? floatmsg : paramsplit[7][0])
  182.                             log_amx("[debug] Message '%s' has been formatted!", message)
  183.                         }
  184.                         case 6:
  185.                         {
  186.                             formatex(message, charsmax(message), _fileData[i][10],
  187.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0],
  188.                                 (paramsplit[4][4][0] == 3) ? floatmsg : paramsplit[4][0],
  189.                                 (paramsplit[5][4][0] == 3) ? floatmsg : paramsplit[5][0],
  190.                                 (paramsplit[6][4][0] == 3) ? floatmsg : paramsplit[6][0],
  191.                                 (paramsplit[7][4][0] == 3) ? floatmsg : paramsplit[7][0],
  192.                                 (paramsplit[8][4][0] == 3) ? floatmsg : paramsplit[8][0])
  193.                             log_amx("[debug] Message '%s' has been formatted!", message)
  194.                         }
  195.                         case 7:
  196.                         {
  197.                             formatex(message, charsmax(message), _fileData[i][10],
  198.                                 (paramsplit[3][4][0] == 3) ? floatmsg : paramsplit[3][0],
  199.                                 (paramsplit[4][4][0] == 3) ? floatmsg : paramsplit[4][0],
  200.                                 (paramsplit[5][4][0] == 3) ? floatmsg : paramsplit[5][0],
  201.                                 (paramsplit[6][4][0] == 3) ? floatmsg : paramsplit[6][0],
  202.                                 (paramsplit[7][4][0] == 3) ? floatmsg : paramsplit[7][0],
  203.                                 (paramsplit[8][4][0] == 3) ? floatmsg : paramsplit[8][0],
  204.                                 (paramsplit[9][4][0] == 3) ? floatmsg : paramsplit[9][0])
  205.                             log_amx("[debug] Message '%s' has been formatted!", message)
  206.                         }
  207.                     }
  208.                     client_print(0, print_chat, "%s", message, paramsplit[3][0], paramsplit[4][0])
  209.                     log_amx("[debug] Message '%s' has been printed into chat", message, paramsplit[3][0], paramsplit[4][0])
  210.                 }
  211.             }
  212.         }
  213.     }
  214. }
  215.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement