Saturday, June 30, 2007

responseOnMatrixNumber v1.0.2a

  1. ###########################
  2. # responseOnMatrixNumber v1.0.2a
  3. #
  4. # For OpenKore 1.9.x
  5. #
  6. # (test in Creamsoda server >> http://creamsoda.i.am) 23/6/250
  7. #
  8. # NOTE: This plugin meant to be use with hakore's reactOnNPC
  9. package responseOnMatrixNumber;
  10. use strict;
  11. use Plugins;
  12. use Utils;
  13. use Globals qw(%talk);
  14. use Commands qw(run register unregister);
  15. use Log qw(message debug);
  16. use I18N qw(bytesToString);
  17. my %reactOnNPC;
  18. my @actOnNPC;
  19. my $num1;
  20. my $num2;
  21. my $num3;
  22. my $all_line;
  23. my $line;
  24. my $matrix;
  25. my @array;
  26. my @NPCresponses;
  27. Plugins::register('responseOnMatrixNumber', "response On MatrixNumber", \&Unload);
  28. my $cmd = Commands::register(['MatrixNumber', 'talk response On MatrixNumber', \&onMatrixCmd]);
  29. my $hooks = Plugins::addHooks(
  30. ['packet/npc_talk', \&onNPCTalk],
  31. ['packet/npc_talk_close', \&onClose]
  32. );
  33. sub onUnload {
  34. Plugins::delHooks($hooks);
  35. Commands::unregister($cmd);
  36. undef %reactOnNPC;
  37. undef @actOnNPC;
  38. undef $num1;
  39. undef $num2;
  40. undef $num3;
  41. undef $all_line;
  42. undef $line;
  43. undef $matrix;
  44. undef @array;
  45. undef @NPCresponses;
  46. }
  47. sub onClose {
  48. undef %reactOnNPC if defined %reactOnNPC;
  49. }
  50. sub onNPCTalk {
  51. my (undef, $args) = @_;
  52. my $msg = I18N::bytesToString(unpack("Z*", substr($args->{RAW_MSG}, 8)));
  53. if (!defined %reactOnNPC || $reactOnNPC{action}) {
  54. undef %reactOnNPC if defined %reactOnNPC;
  55. $reactOnNPC{index} = 1;
  56. $reactOnNPC{msg}[$reactOnNPC{index}] = $msg;
  57. } else {
  58. $reactOnNPC{index}++;
  59. $reactOnNPC{msg}[$reactOnNPC{index}] = $msg;
  60. }
  61. debug "01 $reactOnNPC{msg}[1]\n", "success";
  62. debug "02 $reactOnNPC{msg}[2]\n", "success";
  63. debug "03 $reactOnNPC{msg}[3]\n", "success";
  64. debug "04 $reactOnNPC{msg}[4]\n", "success";
  65. debug "05 $reactOnNPC{msg}[5]\n", "success";
  66. debug "06 $reactOnNPC{msg}[6]\n", "success";
  67. debug "07 $reactOnNPC{msg}[7]\n", "success";
  68. debug "08 $reactOnNPC{msg}[8]\n", "success";
  69. debug "09 $reactOnNPC{msg}[9]\n", "success";
  70. debug "10 $reactOnNPC{msg}[10]\n", "success";
  71. }
  72. sub onCheckMatrix {
  73. my (undef, $args) = @_;
  74. undef @actOnNPC if defined @actOnNPC;
  75. my $i = 0;
  76. for ($i=3;$i<8 ;$i++) {
  77. push (@actOnNPC , $reactOnNPC{msg}[$i]);
  78. }
  79. undef %reactOnNPC if defined %reactOnNPC;
  80. my $matrix = '';
  81. my $all_line = '';
  82. my $line = '';
  83. my @array = '';
  84. for $matrix (@actOnNPC) {
  85. @array = split(/\^/,$matrix);
  86. foreach $line (@array) {
  87. if ($line =~ s/\b[f|F,7|8|9|f|F]{6}//) {
  88. $line =~ s/./=/g;
  89. } else {
  90. $line =~ s/\b[a-f0-9A-F]{6}//;
  91. $line =~ s/./#/g;
  92. }
  93. $all_line .= $line;
  94. }
  95. }
  96. # get num 1
  97. $num1 = substr($all_line, 0, 5);
  98. $num1 .= substr($all_line, 19, 5);
  99. $num1 .= substr($all_line, 38, 5);
  100. $num1 .= substr($all_line, 57, 5);
  101. $num1 .= substr($all_line, 76, 5);
  102. debug "num 1 $num1\n", "success";
  103. # get num 2
  104. $num2 = substr($all_line, 7, 5);
  105. $num2 .= substr($all_line, 26, 5);
  106. $num2 .= substr($all_line, 45, 5);
  107. $num2 .= substr($all_line, 64, 5);
  108. $num2 .= substr($all_line, 83, 5);
  109. debug "num 2 $num2\n", "success";
  110. # get num 3
  111. $num3 = substr($all_line, 14, 5);
  112. $num3 .= substr($all_line, 33, 5);
  113. $num3 .= substr($all_line, 52, 5);
  114. $num3 .= substr($all_line, 71, 5);
  115. $num3 .= substr($all_line, 90, 5);
  116. debug "num 3 $num3\n", "success";
  117. # get line for print
  118. my $line1 = substr($all_line, 0, 19);
  119. my $line2 = substr($all_line, 19, 19);
  120. my $line3 = substr($all_line, 38, 19);
  121. my $line4 = substr($all_line, 57, 19);
  122. my $line5 = substr($all_line, 76, 19);
  123. message "$line1\n", "success";
  124. message "$line2\n", "success";
  125. message "$line3\n", "success";
  126. message "$line4\n", "success";
  127. message "$line5\n", "success";
  128. undef $all_line;
  129. undef $line;
  130. undef $matrix;
  131. undef @array;
  132. undef @actOnNPC if defined @actOnNPC;
  133. undef %reactOnNPC if defined %reactOnNPC;
  134. }
  135. sub onMatrixCmd {
  136. my (undef, $args) = @_;
  137. onCheckMatrix;
  138. my %digit = ("######===##===##===######" => 0,
  139. "==#===##====#====#==#####" => 1,
  140. "==#====#====#====#====#==" => 1,
  141. "==##====#====#====#====#=" => 1,
  142. "#####====#######====#####" => 2,
  143. "#####====######====######" => 3,
  144. "#===##===######====#====#" => 4,
  145. "===#===##==#=#=#####===#=" => 4,
  146. "######====#####====######" => 5,
  147. "#====#====######===######" => 6,
  148. "######====######===######" => 6,
  149. "#####====#====#====#====#" => 7,
  150. "#####===#===#===#====#===" => 7,
  151. "######===#######===######" => 8,
  152. "######===######====######" => 9);
  153. my $resutl1 = '';
  154. my $resutl2 = '';
  155. my $resutl3 = '';
  156. foreach (keys %digit) {
  157. if ($_ eq $num1) {
  158. $resutl1 = $digit{$_}
  159. }
  160. if ($_ eq $num2) {
  161. $resutl2 = $digit{$_}
  162. }
  163. if ($_ eq $num3) {
  164. $resutl3 = $digit{$_}
  165. }
  166. }
  167. $cmd = "talk $args " .$resutl1.$resutl2.$resutl3;
  168. message "[MatrixNumber] Executing command \"$cmd\".\n", "success";
  169. #add Delay 1-5 sec
  170. message "*** Delay before $cmd ***.\n", "connection";
  171. my $startTime = time;
  172. while (1) {
  173. last if (timeOut($startTime,5));
  174. }
  175. Commands::run($cmd);
  176. Commands::run("tele");
  177. undef $resutl1;
  178. undef $resutl2;
  179. undef $resutl3;
  180. undef $num1;
  181. undef $num2;
  182. undef $num3;
  183. }

Wednesday, June 27, 2007

perl function

############
# code : Array
@book=("PHP","Perl");
@morebook=("database","internet");
@morebook=("database","internet",@book);
# Output: @morebook=("database","internet","PHP","Perl");

############
# Code: scalar(@arr)
# This function forces an array or hash to be interpreted as a scalar.
# This is useful to find out the number of elements in an array or hash.
# Use this function to find out the size of an array or hash, 
# preparatory to iterating over it in a loop and processing its contents.
# define array
@data = ('apple', 'peach', 'banana');
# get size
print "The array has " . scalar(@data) . " elements";
# Output: The array has 3 elements


############
# Code: exists $hash{$key}
# This function can be used to test if a particular key exists in a hash.
# define hash
%data = ('king' => 'queen', 'prince' => 'princess');
# check if key exists
if (exists $data{'king'}) {
  print "Found!";
}
# Output: Found!


############
# Code: push(@arr, $val)
# push จะเพิ่มค่าตัวแปรให้กับตัวแปรตัวสุดท้าย
# define array
@data = ('a', 'b', 'c');
# add element
push(@data, 'd');
print "@data ";
# Output: a b c d


############
# Code: pop(@arr)
# define array
@data = ('a', 'b', 'c');
# add element
pop(@data);
print "@data ";
# Output: a b


############
# Code: unshift(@arr, $val)
# This function adds a new element to the beginning of an array.
# define array
@data = ('a', 'b', 'c');
# add element
unshift(@data, 'z');
print "@data ";
# Output: z a b c


############
# Code: shift(@arr)
# This function removes an element from the beginning of the array.
# define array
@data = ('a', 'b', 'c');
# remove element
shift(@data);
print "@data ";
# Output: b c


############
# Code: splice(@arr, $offset, $length, @arr2)
# This function removes a segment of an array, starting from the element at position $offset 
# and continuing until $length elements have been removed. If the optional @arr2 argument is present,
# the extracted segment is replaced with the element of array @arr2.
# Use this function to extract subsets of an array, or to replace elements in an array with new values.
# define array
@data = ('king', 'queen', 'knight', 'bishop');
# remove middle elements
splice(@data, 1, 2);
print "@data ";
# Output: king bishop


############
# Code: delete $hash{$key}
# This function deletes a key from a hash, together with its associated value.
# Use this function to remove elements from a hash. 
# define hash
%data = ('king' => 'queen', 'prince' => 'princess');
# remove element with key 'king'
delete $data{'king'};


############
# Code: split($delim, $str)
# This function decomposes a string by splitting it on delimited $delim and returns the individual 
# components as elements of a numerically-indexed array. These elements can then be processed in a loop.
# Use this function to split comma-delimited lists into independent array elements.
# define string
$str = "cat,hog,dog,log";
# split string on comma delimiter
@words = split(",", $str);
foreach $w (@words) {
  print "$w\n";
}
#Output:
#cat
#hog
#dog
#log


############
# Code: join($sep, @arr)
# This function joins the various elements of an array into a single string, 
# using the value of $sep to separate them from each other.
# Use this function to create a single string from multiple independent array elements,
# using spaces, commas or other separators to glue them together.
# define array
@data = ("Harry", "Joan", "Tom");
# create string from array
print join(" and ", @data) . " are friends";
# Output: Harry and Joan and Tom are friends


############
# Code: keys(%hash)
# This function returns the keys of a hash as a numerically-indexed array. 
# The function is the counterpart of the values() function, discussed next.
# Use this function to extract the keys of a hash into a separate data structure for further processing.
# define hash
%data = ('a' => 'apple', 'b' => 'bat', 'c' => 'cat');
# get and print hash keys
@keys = keys(%data);
print "@keys\n";
# Output: c a b


############
# Code: values(%hash)
# This function returns the values of a hash as a numerically-indexed array.
# The function is the counterpart of the keys() function, discussed previously.
# Use this function to extract the values of a hash into a separate data structure for further processing.
# define hash
%data = ('a' => 'apple', 'b' => 'bat', 'c' => 'cat');
# get and print hash keys
@vals = values(%data);
foreach $v (@vals) {
  print "$v ";
}
# Output: cat apple bat


############
# Code: reverse(@arr)
# This function reverses the order of elements of an array, placing the last element first and vice-versa.
# Use this function to re-sort an array's elements in the opposite direction to their current sort.
# define array
@data = ('apple', 'peach', 'banana');
# reverse array
@rev = reverse(@data);
print "@rev ";
# Output: banana peach apple


############
# Code: sort(@arr)
# This function can be used to sort the elements of an array or hash. By default,
# this function sorts using standard string comparison rules; however,
# you can override this by passing it the name of a custom sorting subroutine.
# Use this function to reset the internal order of elements of an array,
# or to arrange elements alphabetically, numerically or in a custom order.
# define hash
@data = ('oranges', 'peaches', 'grapes', 'apples', 'lemons');
# sort alphabetically
@sorted = sort(@data);
print "@sorted ";
# Output: apples grapes lemons oranges peaches


############
# Code: foreach
@myNames = ('Larry', 'Curly', 'Moe');
foreach (@myNames) {
  print $_;
}
# Output: LarryCurlyMoe


############
# Code: foreach
@myNames = ('Larry', 'Curly', 'Moe');
foreach $name (@myNames) {
  print $name;
}
# Output: LarryCurlyMoe


############
# Code: qw
# quote word in Perl
@myNames1 = ('Jacob', 'Michael', 'Joshua', 'Matthew', 'Alexander', 'Andrew');
@myNames2 = qw(Jacob Michael Joshua Matthew Alexander Andrew);
@myNames3 = qw/Jacob Michael Joshua Matthew Alexander Andrew/;
print "\@myNames1 = @myNames1\n";
print "\@myNames2 = @myNames2\n";
print "\@myNames3 = @myNames3\n";
# Output: 
# @myNames1 = Jacob Michael Joshua Matthew Alexander Andrew
# @myNames2 = Jacob Michael Joshua Matthew Alexander Andrew
# @myNames3 = Jacob Michael Joshua Matthew Alexander Andrew


############
# Code: Single and Double Quoted Strings
$my_name = 'Bobby';
print "$my_name\n";
print '$my_name\n';
# Output: 
# Bobby
# $my_name\n

responseOnAntibotKiller v1.0.0

###########################
# responseOnAntibotKiller v1.0.0 
# 
# For OpenKore 1.9.x
#
# NOTE: This plugin meant to be use with hakore's reactOnNPC
#

package responseOnAntibotKiller;
use strict;
use Plugins;
use Utils;
use Globals qw(%talk);
use Commands qw(run register unregister);
use Log qw(message error);
use I18N qw(bytesToString);

my $imageName;
my $tempImage;
my @tempImage;

Plugins::register('responseOnAntibotKiller', "response On NPC Anti-Bot (Image continue)", \&Unload);
my $cmd = Commands::register(['AntibotKiller', 'talk response AntibotKiller (Image continue)', \&onCmd]);
my $hooks = Plugins::addHooks(
 ['packet/npc_image', \&onNPCImage],
);

sub onUnload {
 Plugins::delHooks($hooks);
 Commands::unregister($cmd);
 undef $imageName;
 undef $tempImage;
 undef @tempImage;
}

sub onNPCImage {
 my (undef, $args) = @_;
 $imageName = bytesToString($args->{npc_image});
 return unless $imageName;
 push @tempImage, $imageName if ($imageName ne '');
 message "[AntibotKiller] Image >> $imageName .\n", "success";
}

sub onCmd {
  my (undef, $args) = @_;
  if ($tempImage[3] ne '') {
    $tempImage = $tempImage[0].$tempImage[1].$tempImage[2].$tempImage[3];
    $tempImage =~ s/\D//g;
    $cmd = "talk $args " . $tempImage;
    message "[AntibotKiller] Executing command \"$cmd\".\n", "success";
    Commands::run($cmd);
    undef @tempImage;
    undef $tempImage;
  }
}

return 1;
Why You Don't LIKE My FaceBook Fanpage ?
×
blogger