Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Randomly add items to Bazaar merchant each restart
- ### Stores items in merchantlist_temp
- ### Reads items from Bazaar.txt list
- ### Author: Vallik
- ##################################################################################
- ##################################################################################
- #::: Variables ::: Change as required.
- @merchants = (500000..500002); ## List of merchant npcid's. Does not need to be consecutive. As few or as many as you like.
- $max_items = 12;
- $min_items = 3;
- $random_number_of_items = 1; ## 1 = true, 0 = false. If true, each merchant will have a random number of items betwen $max_items and $min_items. If false, each merchant will have exactly $max_items.
- $file = 'Bazaar.txt'; ## Name of text file containing item id list. One entry per line, no delimiter's.
- @items = ();
- #::: Script Body ::: Do not modify anything below this.
- #::: Read database name, user and password from eqemu config file
- read_eqemu_config_xml();
- get_mysql_path();
- #::: Read bazaar items from text file stored in $file
- read_bazaar_items();
- #::: Clear previous entries from merchantlist_temp table
- foreach my $m (@merchants){
- clear_existing_merchantlist_temp($m);
- #::: Add random items from @items to merchantlist_temp table for merchant
- add_merchantlist_temp_items($m);
- }
- sub read_eqemu_config_xml {
- open (CONFIG, "eqemu_config.xml");
- while (<CONFIG>){
- chomp;
- $o = $_;
- if($o=~/\<\!--/i){
- next;
- }
- if($o=~/database/i && $o=~/\<\//i){
- $in_database_tag = 0;
- }
- if($o=~/database/i){
- print "IN DATABASE TAG\n" if $debug;
- $in_database_tag = 1;
- }
- if ($o=~/<longname>/i){
- ($long_name) = $o =~ /<longname>(.*)<\/longname>/;
- print "Long Name: '" . $long_name . "'/n" if $debug;
- }
- if($in_database_tag == 1){
- @left = split (">", $o);
- @right = split ("<", $left[1]);
- $tag_data = trim($right[0]);
- if($o=~/<username>/i && $in_database_tag){
- $user = $tag_data;
- print "Database User: '" . $user . "'\n" if $debug;
- }
- if($o=~/<password>/i && $in_database_tag){
- $pass = $tag_data;
- print "Database Pass: '" . $pass . "'\n" if $debug;
- }
- if($o=~/<db>/i){
- $db = $tag_data;
- print "Database Name: '" . $db . "'\n" if $debug;
- }
- if($o=~/<host>/i){
- $host = $tag_data;
- print "Database Host: '" . $host . "'\n" if $debug;
- }
- }
- }
- close(CONFIG);
- }
- sub get_mysql_path {
- $has_mysql_path = `echo %PATH%`;
- if($has_mysql_path=~/MySQL|MariaDB/i){
- @mysql = split(';', $has_mysql_path);
- foreach my $v (@mysql){
- if($v=~/MySQL|MariaDB/i){
- $v =~s/\n//g;
- $path = trim($v) . "/mysql";
- last;
- }
- }
- }
- #::: Path not found, error and exit
- if($path eq ""){
- print "[Error:Bazaar.pl] MySQL path not found, please add the path for automatic merchant script to continue... \n\n";
- exit;
- }
- }
- sub get_mysql_result {
- my $run_query = $_[0];
- if(!$db){ return; }
- return `"$path" --host $host --user $user --password="$pass" $db -N -B -e "$run_query"`;
- }
- sub clear_existing_merchantlist_temp {
- my $merchant = $_[0];
- print get_mysql_result("DELETE FROM `merchantlist_temp` WHERE `npcid` = " . $merchant);
- print "Cleared Temp Merchantlist For NPC: '" . $merchant . "'\n" if $debug;
- }
- sub read_bazaar_items {
- open my $info, $file or die "Could not open $file: $!";
- while (my $line = <$info>){
- push(@items, $line);
- }
- close $info;
- }
- sub add_merchantlist_temp_items {
- my $merchant = $_[0];
- my $slot = 0;
- my @tmp_items = @items;
- my @add_items = ();
- if ($random_number_of_items) {
- my $number_of_items = int(rand(($max_items - $min_items) + 1)) + $min_items;
- } else {
- my $number_of_items = $max_items;
- }
- for (my $i = 0; $i < $number_of_items; $i++){
- push(@add_items, splice(@tmp_items, rand @tmp_items, 1));
- }
- while (@add_items){
- my $item = pop @add_items;
- print get_mysql_result("INSERT INTO `merchantlist_temp` VALUES ('" . $merchant . "', '" . ++$slot . "', '" . $item . "', '1');");
- }
- }
- sub trim {
- my $string = $_[0];
- $string =~ s/^\s+//;
- $string =~ s/\s+$//;
- return $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement