Advertisement
KeplerBR

responseOnASCIInumber.pl

Jun 20th, 2012
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 14.88 KB | None | 0 0
  1. ###########################
  2. # Name of Plugin: ASCIInumberKiller.pl
  3. # Version: 2.2.1 (fix) (7/06/2008)
  4. # Version of Openkore Required: OpenKore SVN (test in SVN)
  5. # if OpenKore SVN comment line "use Commands qw(run register unregister);" (~ line 98)
  6. #
  7. # Description: for response BotKiller #1 - Method 4: ASCII number. (http://www.eathena.ws/board/index.php?showtopic=120522)
  8. #
  9. # ***************************************************************
  10. # * For read my note : Editplus > tools > preferences.. fonts "Tahoma" size 9   *
  11. # ***************************************************************
  12. # *      NOTE 01 : This plugin meant to be use with hakore's reactOnNPC         *
  13. # ***************************************************************
  14. #
  15. # Ex. ../control/config.txt
  16. # reactOnNPC ASCIInumberKiller num {
  17. #     type number
  18. # }
  19. # reactOnNPC ASCIInumberKiller text {
  20. #     type text
  21. # }
  22. # ASCIInumberKiller {
  23. #     lengthCharNumber 8
  24. #     BgColor ^[D-Fd-f][A-Fa-f0-9][D-Fd-f][A-Fa-f0-9]{3}
  25. #}
  26. #
  27. # ************** or [for advance] **********
  28. #
  29. # reactOnNPC ASCIInumberKiller num {
  30. #     type number
  31. #     msg_0 /BotKiller blabla/
  32. #     msg_1 /blabla/
  33. #     .
  34. #     .
  35. #     msg_n /blabla/
  36. # }
  37. # reactOnNPC ASCIInumberKiller text {
  38. #     type text
  39. #     msg_0 /BotKiller blabla/
  40. #     msg_1 /blabla/
  41. #     .
  42. #     .
  43. #     msg_n /blabla/
  44. # }
  45. # ASCIInumberKiller {
  46. #     lengthCharNumber 8
  47. #     BgColor ^[D-Fd-f][A-Fa-f0-9][D-Fd-f][A-Fa-f0-9]{3}|FFFFFF|FFFFFA|code hexcolor you server|.. |brabra
  48. #}
  49. #
  50. # ***************************************************************
  51. # *      NOTE 02 : This plugin meant to be modify to your server by youselft            *
  52. # ***************************************************************
  53. #
  54. # A. How to get number and lenght of number
  55. # - set ../control/config.txt : debug 2, logConsole 1
  56. # - use plugins reactOnNPC.pl ,responseOnASCIInumber.pl
  57. # - look at you ../logs/console.txt
  58. # or
  59. # use plugins LogNpcMsg.pl (find in my (windows98SE) site --> http://www.stephack.com/) [easy log npc msg for me ;P]
  60. #
  61. # B. How to Change lenght of number (defult = 8) [ex. Creamsoda-RO = 25, Rookie-RO = 8]
  62. # Use this block:
  63. # ASCIInumber {
  64. #  lengthCharNumber 8       # length of characters at each line of each number
  65. #  BgColor  FFFFFF|FFFFFA       # regexp color(HEXcode) Background you npc msg *Find it by youself
  66. # }
  67. #
  68. # C. How to add another number [ suport A-Z, if you can :) ]
  69. # - look at line(160) my %digit =  ('##########====####====####====##########' => 0,
  70. #
  71. # ex. number 0              =     ##########====####====####====##########
  72. # 1 number = 8 character=   ######## ##====## ##====## ##====## ########
  73. #                                   =           1                   2                 3                  4                  5
  74. #                                               V                   |                 |                   |                 |
  75. #  1 ########   <- -    -   ########            V                 |                   |                 |
  76. #  2 ##====##   <- -    -   -   -   -   -   -  ##====##       V               |                 |
  77. #  3 ##====##   <- -    -   -   -   -   -   -   -   -   -   -   -   ##====##          V             |
  78. #  4 ##====##   <- -    -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   ##====##            V
  79. #  5 ########   <-  -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   ########
  80. #
  81. #   ***************************************************************
  82. #   :::: Thank For :::::
  83. #   LogConsole : krrado,Shyshio,zeruelx [Forums, PM]
  84. # Tester : Shyshio [VanRO]
  85. # Codeing&document : Mucilon [forums opk inter]
  86. #
  87.  
  88. package ASCIInumberKiller;
  89.  
  90. use strict;
  91. use Plugins;
  92. use Utils;
  93. use Globals;
  94. use Misc;
  95. #use Commands qw(run register unregister); #svn comment this line
  96. use Log qw(message debug);
  97. use I18N qw(bytesToString);
  98.  
  99. my $prefix = "ASCIInumberKiller";
  100. my $line_msg;
  101. my $startLine; 
  102. my $line_msgNum;
  103. my $lengthCharNumber;
  104. my @num_0;
  105. my @num_1;
  106. my @num_2;
  107. my @num_3;
  108. my %reactOnNPC;
  109.  
  110. Plugins::register('ASCIInumberKiller', 'response On ASCII number', \&onUnload);
  111. my $cmd = Commands::register(['ASCIInumberKiller', 'talk response On ASCII number', \&onASCIICmd]);
  112. my $hooks = Plugins::addHooks(
  113.   ['packet/npc_talk', \&onNPCTalk],
  114.   ['packet/npc_talk_close', \&onUndef]
  115. );
  116.  
  117. sub onUnload {
  118.   Plugins::delHooks($hooks);
  119.   Commands::unregister($cmd);
  120.   undef %reactOnNPC;
  121.   undef @num_0;
  122.   undef @num_1;
  123.   undef @num_2;
  124.   undef @num_3;
  125. }
  126.  
  127. sub onUndef {
  128.   undef %reactOnNPC;
  129. }
  130.  
  131. sub onNPCTalk {
  132.   my (undef, $args) = @_;
  133.   my $msg = I18N::bytesToString(unpack("Z*", substr($args->{RAW_MSG}, 8)));
  134.   my @npcMsg = '';
  135.   @npcMsg = split(/\^/,$msg);
  136.   $msg ='';
  137.   my $code;
  138.   if (!exists $config{$prefix."_0_BgColor"}) {
  139.     $code = '^[D-Fd-f][A-Fa-f0-9][D-Fd-f][A-Fa-f0-9]{3}';
  140.     message "[ASCIInumber v2.2.1(fix)] There is no BgColor option at your config.txt file, assuming BgColor to '$code'.\n", "success"; 
  141.   }else{
  142.     $code = $config{$prefix."_0_BgColor"};
  143.     #message "[ASCIInumber v2.2.1(fix)] There is no BgColor option at your config.txt file, assuming BgColor to '$code'.\n", "success";
  144.   }
  145.   foreach my $line (@npcMsg) {
  146.     # Convert ASCII Background to =
  147.     if($line =~ s/$code//){
  148.       $line =~ s/./=/g;
  149.     } else {
  150.       # Convert ASCII Number to #
  151.       $line =~ s/^[A-Fa-f0-9]{6}//;
  152.       $line =~ s/./#/g;
  153.     }
  154.     $msg .= $line;
  155.   }  
  156.   debug "[Convert NPC message] to : $msg\n", "success";
  157.   if(!defined %reactOnNPC || $reactOnNPC{action}) {
  158.     undef %reactOnNPC if defined %reactOnNPC;
  159.     $reactOnNPC{index} = 1;
  160.     $reactOnNPC{msg}[$reactOnNPC{index}] = $msg;
  161.   } else {
  162.     $reactOnNPC{index}++;
  163.     $reactOnNPC{msg}[$reactOnNPC{index}] = $msg;
  164.   }
  165. }
  166.  
  167. sub onCheckASCII {
  168.   my (undef, $args) = @_;
  169.   # For Disply ASCII number [set "debug 2" to see detail]
  170.   @num_0 ='';
  171.   @num_1 ='';
  172.   @num_2 ='';
  173.   @num_3 ='';
  174.   $line_msg =0;
  175.   $line_msgNum =0;
  176.   my $i =0;
  177.   my $j =0;
  178.   if (!exists $config{$prefix."_0_lengthCharNumber"}) {
  179.     message "[ASCIInumber v2.2.1(fix)] There is no lengthCharNumber option at your config.txt file, assuming lengthCharNumber 8.\n", "success";
  180.     $lengthCharNumber = 8;
  181.   } else {
  182.     $lengthCharNumber = $config{$prefix."_0_lengthCharNumber"};
  183.   }
  184.   for ($i=1;$i < $reactOnNPC{index}+1 ;$i++) {
  185.     message "[$i] : $reactOnNPC{msg}[$i]\n", "success";
  186.     $line_msg += 1;
  187.   }
  188.  
  189.   #get num & position
  190.   for ($i = 0;$i <= length($reactOnNPC{msg}[$line_msg-1]);$i++) {
  191.     for ($j=0;$j <= length($reactOnNPC{msg}[$line_msg-1]) - $lengthCharNumber;$j++) {
  192.       $num_0[$i]  = substr($reactOnNPC{msg}[$line_msg-4], $i, $lengthCharNumber);
  193.       $num_0[$i] .= substr($reactOnNPC{msg}[$line_msg-3], $i, $lengthCharNumber);
  194.       $num_0[$i] .= substr($reactOnNPC{msg}[$line_msg-2], $i, $lengthCharNumber);
  195.       $num_0[$i] .= substr($reactOnNPC{msg}[$line_msg-1], $i, $lengthCharNumber);
  196.       $num_0[$i] .= substr($reactOnNPC{msg}[$line_msg], $i, $lengthCharNumber);
  197.      
  198.       $num_1[$i]  = substr($reactOnNPC{msg}[$line_msg-5], $i, $lengthCharNumber);
  199.       $num_1[$i] .= substr($reactOnNPC{msg}[$line_msg-4], $i, $lengthCharNumber);
  200.       $num_1[$i] .= substr($reactOnNPC{msg}[$line_msg-3], $i, $lengthCharNumber);
  201.       $num_1[$i] .= substr($reactOnNPC{msg}[$line_msg-2], $i, $lengthCharNumber);
  202.       $num_1[$i] .= substr($reactOnNPC{msg}[$line_msg-1], $i, $lengthCharNumber);
  203.  
  204.       $num_2[$i]  = substr($reactOnNPC{msg}[$line_msg-6], $i, $lengthCharNumber);
  205.       $num_2[$i] .= substr($reactOnNPC{msg}[$line_msg-5], $i, $lengthCharNumber);              
  206.       $num_2[$i] .= substr($reactOnNPC{msg}[$line_msg-4], $i, $lengthCharNumber);
  207.       $num_2[$i] .= substr($reactOnNPC{msg}[$line_msg-3], $i, $lengthCharNumber);
  208.       $num_2[$i] .= substr($reactOnNPC{msg}[$line_msg-2], $i, $lengthCharNumber);
  209.  
  210.       $num_3[$i]  = substr($reactOnNPC{msg}[$line_msg-7], $i, $lengthCharNumber);
  211.       $num_3[$i] .= substr($reactOnNPC{msg}[$line_msg-6], $i, $lengthCharNumber);
  212.       $num_3[$i] .= substr($reactOnNPC{msg}[$line_msg-5], $i, $lengthCharNumber);
  213.       $num_3[$i] .= substr($reactOnNPC{msg}[$line_msg-4], $i, $lengthCharNumber);
  214.       $num_3[$i] .= substr($reactOnNPC{msg}[$line_msg-3], $i, $lengthCharNumber);
  215.     }
  216.     $line_msgNum += 1;
  217.   }
  218.   undef %reactOnNPC if defined %reactOnNPC;
  219. }
  220.  
  221. sub onASCIICmd {
  222.   my (undef, $args) = @_;
  223.   &onCheckASCII;
  224.   my %digit =  (
  225.     '######===##===##===######' => 0,
  226.     '==####==##==######====######==##==####==' => 0,
  227.     '==####==##====####====####====##==####==' => 0,
  228.     '##########====####====####====##########' => 0,
  229.     '==#===##====#====#==#####' => 1,
  230.     '==#====#====#====#====#==' => 1,
  231.     '==##====#====#====#====#=' => 1,
  232.     '==####======##======##======##==########' => 1,
  233.     '==####==##==##======##======##==########' => 1,
  234.     '#####====#######====#####' => 2,
  235.     '==####==##====##====##====##====########' => 2,
  236.     '######========##==########======########' => 2,
  237.     '########======############======########' => 2,
  238.     '#####====######====######' => 3,
  239.     '########======##########======##########' => 3,
  240.     '######========##==####========########==' => 3,
  241.     '#===##===######====#====#' => 4,
  242.     '===#===##==#=#=#####===#=' => 4,
  243.     '====####==##==####====##########======##' => 4,
  244.     '======##====####==##==##########======##' => 4,
  245.     '##====####====##########======##======##' => 4,
  246.     '######====#####====######' => 5,
  247.     '##########======########======##########' => 5,
  248.     '==########======######========########==' => 5,
  249.     '##########========######======##########' => 5,
  250.     '#====#====######===######' => 6,
  251.     '######====######===######' => 6,
  252.     '====##====##====##########====##==####==' => 6,
  253.     '##########======##########====##########' => 6,
  254.     '==####==##======##########====##==####==' => 6,
  255.     '#####====#====#====#====#' => 7,      
  256.     '#####===#===#===#====#===' => 7,
  257.     '##########====##==######====##==####====' => 7,
  258.     '########======##====##====##====##======' => 7,
  259.     '########======##==######====##====##====' => 7,
  260.     '########======##======##======##======##' => 7,
  261.     '######===#######===######' => 8,
  262.     '##########====##==####==##====##########' => 8,
  263.     '##########====############====##########' => 8,
  264.     '==####==##====##==####==##====##==####==' => 8,
  265.     '######===######====######' => 9,
  266.     '##########====##########======##########' => 9,
  267.     '==####==##====##==######====##====##====' => 9,
  268.     '##############################===============##########===============##########===============##############################' => '0',
  269.     '==========##########====================#####====================#####====================#####====================#####=====' => '1',
  270.     '==========##########==========#####==========#####===============#####===============#####===============####################' => '2',
  271.     '####################=========================#####=====###############=========================#########################=====' => '3',
  272.     '===============#####===============##########==========#####=====#####=====#########################===============#####=====' => '4',
  273.     '##############################====================####################=========================#########################=====' => '5',
  274.     '##############################====================##############################===============##############################' => '6',
  275.     '=====###############=====#####====================####################=====#####===============#####=====###############=====' => '6',
  276.     '#########################===============#####===============#####===============#####====================#####===============' => '7',
  277.     '##############################===============###################################===============##############################' => '8',
  278.     '=====###############=====#####===============#####=====###############=====#####===============#####=====###############=====' => '8',
  279.     '##############################===============##############################====================##############################' => '9',
  280.     '=====###############=====#####===============#####=====####################=====####################=====###############=====' => '9',
  281.     '==========#####===============#####=====#####=====#####===============###################################===============#####' => 'A',
  282.     '=====###############=====#####====================#####====================#####=========================###############=====' => 'C',
  283.     '##############################====================####################=====#####====================#########################' => 'E',
  284.     '##############################====================####################=====#####====================#####====================' => 'F',
  285.     '#####===============##########===============###################################===============##########===============#####' => 'H',
  286.     '===============#####====================#####====================#####=====#####==========#####==========##########==========' => 'J',
  287.     '=====#####==========#####=====#####=====#####==========##########===============#####=====#####==========#####==========#####' => 'K',
  288.     '#####====================#####====================#####====================#####====================#########################' => 'L',
  289.     '#####===============###############=====###############=====#####=====##########===============##########===============#####' => 'M',
  290.     '#####===============###############==========##########=====#####=====##########==========###############===============#####' => 'N',
  291.     '###############==========#####==========#####=====###############==========#####====================#####====================' => 'P',
  292.     '###############==========#####==========#####=====###############==========#####==========#####=====#####===============#####' => 'R',
  293.     '#########################==========#####====================#####====================#####====================#####==========' => 'T',
  294.     '#####===============##########===============##########===============##########===============#####=====###############=====' => 'U',
  295.     '#####===============##########===============##########===============#####=====#####=====#####===============#####==========' => 'V',
  296.     '#####===============##########===============##########=====#####=====###############=====###############===============#####' => 'W',
  297.     '#####===============#####=====#####=====#####===============#####===============#####=====#####=====#####===============#####' => 'X',
  298.     '#####===============#####=====#####=====#####===============#####====================#####====================#####==========' => 'Y',
  299.     '#########################===============#####===============#####===============#####===============#########################' => 'Z'
  300.   );
  301.  
  302.   my @result_ = '';
  303.   my $k =0;
  304.   my $ans = '';
  305.    
  306.   foreach (keys %digit) {
  307.     for ($k =0;$k <= $line_msgNum;$k++) {
  308.       if ($_ eq $num_0[$k] ) {
  309.         $result_[$k] = $digit{$_};
  310.       }
  311.       if ($_ eq $num_1[$k] ) {
  312.         $result_[$k] = $digit{$_};
  313.       }
  314.       if ($_ eq $num_2[$k] ) {
  315.         $result_[$k] = $digit{$_};
  316.       }
  317.       if ($_ eq $num_3[$k] ) {
  318.         $result_[$k] = $digit{$_};
  319.       }
  320.     }
  321.   }
  322.   for ($k=0;$k <=@result_ ;$k++) {
  323.     $ans .= $result_[$k]
  324.   }
  325.   $cmd = "talk $args ".$ans;
  326.   message "[ASCIInumber v2.2.1(fix)] Executing command \"$cmd\".\n", "success";
  327.   #add Delay 1-3 sec before $cmd
  328.   message "[ASCIInumber v2.2.1(fix)] *** Delay 1-3 sec. before $cmd ***.\n", "success";
  329.   my $startTime = time;
  330.   while (1) {
  331.     last if (timeOut($startTime,3));
  332.   }
  333.   Commands::run($cmd);         
  334.   undef @result_;
  335.   undef @num_0;
  336.   undef @num_1;
  337.   undef @num_2;
  338.   undef @num_3;
  339. }
  340. return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement