Openkore.com

OpenKore Forums
It is currently 13 Dec 2018, 11:09

All times are UTC - 5 hours [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: question about : hook vending_item_sold
PostPosted: 31 May 2017, 02:38 
Offline
Noob
Noob

Joined: 31 May 2017, 01:12
Posts: 4
hi, i'm trying to make plugin that notify me if my vending item sold, so far i found hook/function in openkore that suit my needs

https://github.com/OpenKore/openkore/bl ... erType0.pm

Code:
# Your shop has sold an item -- one packet sent per item sold.
#
sub shop_sold {
   my ($self, $args) = @_;

   # sold something
   my $number = $args->{number};
   my $amount = $args->{amount};

   $articles[$number]{sold} += $amount;
   my $earned = $amount * $articles[$number]{price};
   $shopEarned += $earned;
   $articles[$number]{quantity} -= $amount;
   my $msg = TF("sold: %s - %s %sz\n", $amount, $articles[$number]{name}, $earned);
   shopLog($msg);
   message($msg, "sold");

   # Call hook before we possibly remove $articles[$number] or
   # $articles itself as a result of the sale.
   Plugins::callHook(
      'vending_item_sold',
      {
         #These first two entries are equivalent to $args' contents.
         'vendShopIndex' => $number,
         'amount' => $amount,
         'vendArticle' => $articles[$number], #This is a hash
      }
   );

   # Adjust the shop's articles for sale, and notify if the sold
   # item and/or the whole shop has been sold out.
   if ($articles[$number]{quantity} < 1) {
      message TF("sold out: %s\n", $articles[$number]{name}), "sold";
      #$articles[$number] = "";
      if (!--$articles){
         message T("Items have been sold out.\n"), "sold";
         closeShop();
      }
   }
}##end shop_sold()


this is what i write so far, mostly based on sli's koreGrowl.

Quote:
package tmNotify;

use Plugins;
use Globals;

Plugins::register('tmNotify','vending notification using terminal-notifier', \&onUnload);
my $hooks = Plugins::addHooks(
['start3', \&onLoad, undef],
['packet_privMsg', \&onPrivMsg, undef],
['map_loaded', \&onMapLoaded, undef],
['vending_item_sold', \&onItemSold, undef],
['packet_vender_store', \&onItemSold, undef]
);
my $cmd = Commands::register(
["tmnotify", "test notification", \&cmdNotify],
);

my $dead = 0;

sub cmdNotify {
my @args = @_;
print qx(terminal-notifier -title 'cmdNotify' -message 'tmNotify is working !');
}

sub onLoad {
print qx(terminal-notifier -title 'onLoad' -message 'Notify is loaded !');
}

sub onPrivMsg {
my @args = @_;
# growlMessage("From $args[1]{'privMsgUser'} : $args[1]{privMsg}", 1);
$user = $args[1]{'privMsgUser'};
$msg = $args[1]{'privMsg'};
print qx(terminal-notifier -title 'onPrivMsg' -message '$user : $msg');
}

sub onItemSold {
my $number = $args->{number};
my $amount = $args->{amount};

$articles[$number]{sold} += $amount;
my $earned = $amount * $articles[$number]{price};
$shopEarned += $earned;
$articles[$number]{quantity} -= $amount;

my $msg = $args->{RAW_MSG};

print qx(terminal-notifier -title 'onItemSold' -message '$number - $amount - $msg');
}

sub onMapLoaded {
# Prevents multiple notifications on death.
$dead = 0;
}

sub onUnload {
Plugins::delHooks($hooks);
undef $ucname;
}

1;


but i can only get values from $args->{amount}, other $args return nothing.
how to get other $args value so i can get item name ?
thanks


Top
 Profile  
 
 Post subject: Re: question about : hook vending_item_sold
PostPosted: 31 May 2017, 05:16 
Offline
Plain Yogurt
Plain Yogurt

Joined: 03 Apr 2017, 00:19
Posts: 53
You are able to write This function by using macro.

If the item sold
Then does this or this to notify you.


Top
 Profile  
 
 Post subject: Re: question about : hook vending_item_sold
PostPosted: 05 Jun 2017, 22:31 
Offline
Noob
Noob

Joined: 31 May 2017, 01:12
Posts: 4
Code:
automacro soldout {
   hook vending_item_sold
   save number
   save amount
   save vendArticle
   call {
      log vendShopIndex $.hooksave0 amount $.hooksave1 vendArticle $.hooksave2
   }
}


Code:
[b][Jun 6 09:25:23 2017.73] sold: 2 - Flower 4z[/b]
[Jun 6 09:25:23 2017.36] [macro] $args->{number} does not exist
[Jun 6 09:25:23 2017.36] [macro] $.hooksave2 is of type HASH. Take care!
[Jun 6 09:25:23 2017.36] [macro] automacro soldout triggered.
[Jun 6 09:25:23 2017.36] [macro log] vendShopIndex  amount 2 vendArticle HASH(0x7fb09f081420)


still got the same question even in macros, how to get those $args->{number} value ?how can i print like sold: 2 - Flower 4z
in macro log ?


Top
 Profile  
 
 Post subject: Re: question about : hook vending_item_sold
PostPosted: 08 Jun 2017, 19:12 
Offline
Moderators
Moderators
User avatar

Joined: 16 Dec 2011, 02:53
Posts: 1212
Location: Brazil
Your solution :
======================================================================================
Code:
'vendShopIndex' => $number,
'amount' => $amount,
'vendArticle' => $articles[$number], #This is a hash


Code:
$args->{vendShopIndex} to get the $number
$args->{amount} to get $amount
$args->{vendArticle} to get the article.


$.hooksave0 = vendShopIndex = $number
$.hooksave1 = amount = $amount
$.hooksave2 = vendArticle = $articles[$number] (is only missing the {name} hash access)

Using :

Code:
save vendArticle
save amount
save vendShopIndex

Since you can't get $articles at a unusual way.

To get $articles, i believe you should use something such as :

Instead of use $.hooksave2 straight (#this is hash), try :

$realArticles = @eval ($.hooksave2[$.hooksave0]{name}) or
$realArticles = @eval (return $.hooksave2[$.hooksave0]{name}) or
$realArticles = @eval (return $.hooksave0{name}) or
$realArticles = @eval ($.hooksave0{name})

'cause i believe that using :
$realArticles = $articles[$number]

won't work. :/

======================================================================================
https://github.com/Slipxxliose/-unknown ... hopSold.pl

Code:
use strict;
use warnings;
use Plugins;
use Log qw (warning message debug error);
#-----------------
# Plugin: settings
#-----------------
Plugins::register("shopSold", "shopSold", \&on_unload, \&on_reload);
# Log hook
my $logHook = Log::addHook(\&on_Log, "shopsold");
#---------------
# Plugin: on_unload
#---------------
sub on_unload {
Log::delHook($logHook);
}
sub on_reload {
&on_unload;
}
#-------------
# Log: handler
#-------------
sub on_Log {
my ($type, $domain, $level, $globalVerbosity, $message, $user_data) = @_;
   if ( $type eq "message" ){
      if ($message =~ /(sold|vendido): (\d+) - (.*) (\d+)z/ig) {
      Utils::Win32::playSound("C:\\coin.wav");
      }      
   }
}



It's my github post.
Well, i've done this code too for beginners!

How to use timeout :
Code:
https://github.com/Slipxxliose/-unknown_plugins-openkore/blob/master/tips/st_timeout.pl

from kgRelogger.

How to get console messages :

Code:
https://github.com/Slipxxliose/-unknown_plugins-openkore/blob/master/tips/koreLogConsole.pl


The same thing i've used to make the itemSold plugin !

_________________
"'There are three things all wise men fear: the sea in storm, a night with no moon, and the anger of a gentle man.'" :P

viewtopic.php?f=10&t=16117

Thanks for this Eternal! =D <3<3


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group