########################### # responseOnMatrixNumber v1.0.2a # # For OpenKore 1.9.x # # (test in Creamsoda server >> http://creamsoda.i.am) 23/6/250 # # NOTE: This plugin meant to be use with hakore's reactOnNPC package responseOnMatrixNumber; use strict; use Plugins; use Utils; my %reactOnNPC; my @actOnNPC; my $num1; my $num2; my $num3; my $all_line; my $line; my $matrix; my @array; my @NPCresponses; Plugins::register('responseOnMatrixNumber', "response On MatrixNumber", \&Unload); my $cmd = Commands::register(['MatrixNumber', 'talk response On MatrixNumber', \&onMatrixCmd]); my $hooks = Plugins::addHooks( ['packet/npc_talk', \&onNPCTalk], ['packet/npc_talk_close', \&onClose] ); sub onUnload { Plugins::delHooks($hooks); Commands::unregister($cmd); undef %reactOnNPC; undef @actOnNPC; undef $num1; undef $num2; undef $num3; undef $all_line; undef $line; undef $matrix; undef @array; undef @NPCresponses; } sub onClose { } sub onNPCTalk { } else { } debug "01 $reactOnNPC{msg}[1]\n", "success"; debug "02 $reactOnNPC{msg}[2]\n", "success"; debug "03 $reactOnNPC{msg}[3]\n", "success"; debug "04 $reactOnNPC{msg}[4]\n", "success"; debug "05 $reactOnNPC{msg}[5]\n", "success"; debug "06 $reactOnNPC{msg}[6]\n", "success"; debug "07 $reactOnNPC{msg}[7]\n", "success"; debug "08 $reactOnNPC{msg}[8]\n", "success"; debug "09 $reactOnNPC{msg}[9]\n", "success"; debug "10 $reactOnNPC{msg}[10]\n", "success"; } sub onCheckMatrix { my $i = 0; for ($i=3;$i<8 ;$i++) { } my $matrix = ''; my $all_line = ''; my $line = ''; my @array = ''; for $matrix (@actOnNPC) { foreach $line (@array) { $line =~ s/./=/g; } else { } $all_line .= $line; } } # get num 1 debug "num 1 $num1\n", "success"; # get num 2 debug "num 2 $num2\n", "success"; # get num 3 debug "num 3 $num3\n", "success"; # get line for print message "$line1\n", "success"; message "$line2\n", "success"; message "$line3\n", "success"; message "$line4\n", "success"; message "$line5\n", "success"; undef $all_line; undef $line; undef $matrix; undef @array; } sub onMatrixCmd { onCheckMatrix; my %digit = ("######===##===##===######" => 0, "==#===##====#====#==#####" => 1, "==#====#====#====#====#==" => 1, "==##====#====#====#====#=" => 1, "#####====#######====#####" => 2, "#####====######====######" => 3, "#===##===######====#====#" => 4, "===#===##==#=#=#####===#=" => 4, "######====#####====######" => 5, "#====#====######===######" => 6, "######====######===######" => 6, "#####====#====#====#====#" => 7, "#####===#===#===#====#===" => 7, "######===#######===######" => 8, "######===######====######" => 9); my $resutl1 = ''; my $resutl2 = ''; my $resutl3 = ''; if ($_ eq $num1) { $resutl1 = $digit{$_} } if ($_ eq $num2) { $resutl2 = $digit{$_} } if ($_ eq $num3) { $resutl3 = $digit{$_} } } $cmd = "talk $args " .$resutl1.$resutl2.$resutl3; message "[MatrixNumber] Executing command \"$cmd\".\n", "success"; #add Delay 1-5 sec message "*** Delay before $cmd ***.\n", "connection"; while (1) { last if (timeOut($startTime,5)); } Commands::run($cmd); Commands::run("tele"); undef $resutl1; undef $resutl2; undef $resutl3; undef $num1; undef $num2; undef $num3; } return 1;
Saturday, June 30, 2007
responseOnMatrixNumber v1.0.2a
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
Labels:
perl
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;