SHARE
TWEET

responseOnNPCImage.pl

ya4epT Jun 26th, 2014 215 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #########################################################################
  2. # This software is open source, licensed under the GNU General Public
  3. # License, version 2.
  4. # Basically, this means that you're allowed to modify and distribute
  5. # this software. However, if you distribute modified versions, you MUST
  6. # also distribute the source code.
  7. # See http://www.gnu.org/licenses/gpl.html for the full license.
  8. #########################################################################
  9. #
  10. # responseOnNPCImage v2
  11. #
  12. # Copyright 2007 by abt123 [mod ya4ept]
  13. #
  14. # NOTE: This plugin meant to be use with hakore's reactOnNPC
  15. # http://forums.openkore.com/viewtopic.php?f=34&t=1071
  16. # http://forums.openkore.com/viewtopic.php?f=34&t=198
  17. #
  18. # Example (put in config.txt):
  19. # Some server use image name as a response.
  20. # responseOnNPCImage_equal <num | text | resp | or leave blank for disable>
  21. # reactOnNPC talkImage text {
  22. #       type text
  23. #       msg_0 [Bot Check]
  24. #       msg_1 /.*/
  25. # }
  26. #########################################################################
  27.  
  28. package responseOnNPCImage;
  29.  
  30. use strict;
  31. use Plugins;
  32. use FileParsers qw(parseDataFile);
  33. use Globals qw(%config %talk);
  34. use I18N qw(bytesToString);
  35. use Log qw(message error);
  36.  
  37. Plugins::register('responseOnNPCImage', 'respose base on NPC Image', \&onUnload, \&onUnload);
  38.  
  39. my $cmd = Commands::register(['talkImage', 'talk response by image', \&cmdTalkImage]);
  40. my $hooks = Plugins::addHooks(
  41.         ['packet/npc_image', \&onNPCImage],
  42.         ['packet_pre/npc_talk_number', \&onNPCTalkInput],
  43.         ['packet_pre/npc_talk_text', \&onNPCTalkInput],
  44.         ['packet/npc_talk_responses', \&onNPCResponses]
  45. );
  46. my $imageName;
  47. my @NPCresponses;
  48.  
  49. # Syntax:
  50. # '<image name>' => '<response>',
  51. # <image name> - if you got following message
  52. #       [responseOnNPCImage] Image name >> "????"
  53. # then the ???? is a <image name>.
  54. #
  55. # <response> - Any text that contained in NPC response choice(s) or number.
  56. my %imageTable = (
  57.         'cbot_1' => 'poring',
  58.         'cbot_2' => 'lunatic',
  59.         'cbot_3' => 'fabre',
  60.         'cbot_4' => 'drops',
  61.  
  62.         '29028246' => '1',
  63.         '29029000' => '2',
  64.         '29029754' => '3',
  65.         '29030508' => '4',
  66.         '29031262' => '5',
  67.         '29032016' => '6',
  68.  
  69.         'one' => '1'
  70.         'two' => '2'
  71.         'three' => '3'
  72.         'four' => '4'
  73.  
  74.         'botcheck1' => '234',
  75.         'botcheck2' => '786',
  76.         'botcheck3' => '568',
  77.         'botcheck4' => '311',
  78.         'botcheck5' => '682',
  79.         'botcheck6' => '166',
  80.         'botcheck7' => 'PORING',
  81.         'botcheck8' => 'RODA',
  82.         'botcheck9' => 'ALICE',
  83.         'botcheck10' => 'ACIDUS',
  84.         'botcheck11' => 'HARPY',
  85.         'botcheck12' => 'HEATER',
  86.         'botcheck13' => 'KIEL',
  87.         'botcheck14' => 'ORC',
  88.         'botcheck15' => 'PRIEST',
  89.         'botcheck16' => 'PALADIN',
  90. );
  91.  
  92. sub onUnload {
  93.         Plugins::delHooks($hooks);
  94.         Commands::unregister($cmd);
  95.         undef %imageTable;
  96.         undef $imageName;
  97.         undef @NPCresponses;
  98.         message "responseOnNPCImage plugin unloading or reloading\n", 'success';
  99. }
  100.  
  101. sub onNPCImage {
  102.         my (undef, $args) = @_;
  103.         $imageName = bytesToString($args->{npc_image});
  104.         return unless $imageName;
  105.         message "[responseOnNPCImage] Image name >> \"$imageName\"\n", "info";
  106. }
  107.  
  108. sub onNPCTalkInput {
  109.         my (undef, $args) = @_;
  110.         $talk{ID} = $args->{ID};
  111. }
  112.  
  113. sub onNPCResponses {
  114.         my (undef, $args) = @_;
  115.         my $msg = I18N::bytesToString(unpack("Z*", substr($args->{RAW_MSG}, 8)));
  116.         @NPCresponses = ();
  117.         my @preTalkResponses = split /:/, $msg;
  118.         foreach my $response (@preTalkResponses) {
  119.                 $response =~ s/\^[a-fA-F0-9]{6}//g;
  120.                 push @NPCresponses, $response if ($response ne '');
  121.         }
  122. }
  123.  
  124. sub cmdTalkImage {
  125.         my (undef, $args) = @_;
  126.         my $cmd = '';
  127.  
  128.         if ($args !~ /resp|num|text/) {
  129.                 error "Syntax Error in function 'talkImage' (Talk to NPC base on NPC image)\n" .
  130.                         "Usage: talkImage <resp | num | text>\n";
  131.                 return;
  132.         }
  133.         if ($imageName eq '') {
  134.                 error "[responseOnNPCImage] Doesn't seen any image yet!\n";
  135.                 return;
  136.         }
  137.         if (defined $imageTable{$imageName} && $imageTable{$imageName} ne '') {
  138.                 if ($args eq 'num') {
  139.                         $cmd = "talk num $imageTable{$imageName}";
  140.                 } elsif ($args eq 'text') {
  141.                         $cmd = "talk text $imageTable{$imageName}";
  142.                 } elsif ($args eq 'resp') {
  143.                         message "[responseOnNPCImage] Match \"$imageTable{$imageName}\" to response list.\n", "info";
  144.                         my $i = 0;
  145.                         foreach (@NPCresponses) {
  146.                                 last if ($_ =~ /$imageTable{$imageName}/i);
  147.                                 $i++;
  148.                         }
  149.                         if ($i < (scalar @NPCresponses)) {
  150.                                 $cmd = "talk resp $i";
  151.                         } else {
  152.                                 error "[responseOnNPCImage] Can not match \"$imageTable{$imageName}\" to response list.\n";
  153.                                 message "[responseOnNPCImage] You must response by yourself now!\n", "info";
  154.                         }
  155.                 }
  156.         } else {
  157.                 if ($args eq 'num') {
  158.                         if ($config{"responseOnNPCImage_equal"} eq 'num') {
  159.                                 $cmd = "talk num $imageName";
  160.                         } else {
  161.                                 error "[responseOnNPCImage] Image name not equal to number.\n";
  162.                                 message "[responseOnNPCImage] You must response by yourself now!\n", "info";
  163.                         }
  164.                 } elsif ($args eq 'text') {
  165.                         if ($config{"responseOnNPCImage_equal"} eq 'text') {
  166.                                 $cmd = "talk text $imageName";
  167.                         } else {
  168.                                 error "[responseOnNPCImage] Image name not equal to text.\n";
  169.                                 message "[responseOnNPCImage] You must response by yourself now!\n", "info";
  170.                         }
  171.                 } elsif ($args eq 'resp') {
  172.                         if ($config{"responseOnNPCImage_equal"} eq 'resp') {
  173.                                 message "[responseOnNPCImage] Match \"$imageName\" to response list.\n", "info";
  174.                                 my $i = 0;
  175.                                 foreach (@NPCresponses) {
  176.                                         next unless $_;
  177.                                         last if ($_ =~ /$imageName/i);
  178.                                         $i++;
  179.                                 }
  180.                                 if ($i < (scalar @NPCresponses)) {
  181.                                         $cmd = "talk resp $i";
  182.                                 } else {
  183.                                         error "[responseOnNPCImage] Can not match \"$imageName\" to response list.\n";
  184.                                         message "[responseOnNPCImage] You must response by yourself now!\n", "info";
  185.                                 }
  186.                         } else {
  187.                                 error "[responseOnNPCImage] Image name not equal to response choice.\n";
  188.                                 message "[responseOnNPCImage] You must response by yourself now!\n", "info";
  189.                         }
  190.                 }
  191.         }
  192.  
  193.         if ($cmd ne '') {
  194.                 message "[responseOnNPCImage] Executing command \"$cmd\".\n", "success";
  195.                 Commands::run($cmd);
  196.                 $imageName = '';
  197.         }
  198. }
  199.  
  200. 1;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top