Openkore.com

OpenKore Forums
It is currently 12 Dec 2018, 08:17

All times are UTC - 5 hours [ DST ]





Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: [Help]How to do activate plugin when...
PostPosted: 30 Oct 2011, 13:36 
Offline
Human
Human

Joined: 07 Oct 2011, 11:21
Posts: 24
on determined text .
I had tried this :
Code:
use strict;
use Plugins;
use Log qw( warning message error );
use Globals;

Plugins::addHook('mainLoop_pre', \&onCommand, undef);

sub onCommand {
my (undef, $args) = @_;
if ($args->{msg} =~ /Hello World/i)
{
warning " Olá ";
}
}

1;

In this plugin,i created to be activated when receive a message in console,chat,etc...
This hook (mainLoop_pre) its alright for my case ?
My case,in this case,rs,would during the game.
I have used as example,Plugin retreat,kgRelogger,to recognizes the text.
But i don't could.
Someone help ?


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 30 Oct 2011, 17:21 
Offline
Developers
Developers

Joined: 05 Dec 2008, 05:42
Posts: 1811
That't documented (with examples) in Log.pm - there are different kind of hooks for console output.


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 30 Oct 2011, 18:46 
Offline
Human
Human

Joined: 07 Oct 2011, 11:21
Posts: 24
I Will have who use the command ' split ' ?
Good,i read the LOG.PM , Plugins ( kgRelogger, hideConsole, petFeeder, spamBlock ) , all modes i tried and don't could.
Severeal ways i tried to activate the plugins.
I Use all examples of this plugins,and others,don't remember the names,but don't could,don't could.
But,when i use :
Code:
if ($msg =~ /Olá/i) {
warning "Olá is 'Hello World' in Portuguese";
}

I did not say this.
But,remember,i read the LOG.PM and i found it :
Code:
$format =~ s/d/$tmpdate[3]/g;

But don't understand.
and I realized that is used too this :
Code:
our %messageConsole;

Too don't know what is this.
Sorry,i'am a newbie and you know how is hard start with a hard plugin,and for understand,i need read some archives.pm very hard,because the archives.pm is same who my plugins objective.In language,course. !

When you said there are several ways to hook the output of the console, I did not find any
Sorry. :D


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 00:35 
Offline
Noob
Noob

Joined: 31 Oct 2011, 00:31
Posts: 4
someone will have to confirm but I think, for example,
Code:
console /Not Enough SP/i
would work as a condition


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 04:26 
Offline
Developers
Developers

Joined: 05 Dec 2008, 05:42
Posts: 1811
Something like that:
Code:
my $logHook = Log::addHook(sub {
   my (undef, $domain, undef, undef, $msg) = @_;
   return if $domain eq 'test';
   warning "Hook: $msg", 'test';
});

# in unload:
Log::delHook($logHook);


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 11:45 
Offline
Human
Human

Joined: 07 Oct 2011, 11:21
Posts: 24
Ok,thanks,i got.
:D
But,i realized that,when the plugin have this line :
Code:
return if $domain eq 'test';

In console appears :
Code:
[Oct 31 13:27:48 2011.48] Loading control\mon_control.txt...
[Oct 31 13:27:48 2011.49] Hook: Loading control\mon_control.txt...
[Oct 31 13:27:48 2011.53] Loading control\items_control.txt...
[Oct 31 13:27:48 2011.57] Hook: Loading control\items_control.txt...
[Oct 31 13:27:48 2011.66] Loading control\shop.txt...
[Oct 31 13:27:48 2011.71] Hook: Loading control\shop.txt...

But,when i delete him,appears :
Code:
Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook

In a plugin,with that line deleted,I Have modified some lines or added some,and i got that the plugin has been activated when message : " Olá " appears in console,ok.
And the message who appears :
Code:
Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Hook : Input: c Olá

Don't remember as,but appears Input .
Ok,i try this : Plugins:addHook('input'....)
But don't work :D
Er...
Then,when i use a plugin for activate when appears a message in console, need use
Code:
log::addHook (sub {
....
...
}
);

The plugin flood my Kore.
Have a way to the plugin has activated and after time,the plugin activate again ?
Thanks for help,sorry my Nooobisse :)
Other ask,which best hook :
Code:
in_game
mainLoop_pre

Other,other,other :
Code:
'test'

Whats is this ? and what is influence of this in my plugin ?
Code:
return if $domain eq 'test';

I Don't understand this line.I search in google : return if and don't understand nothing.
I'am braziilian,you know how is very hard found some in a other language forum.But,english it's nice.
:D
thanks for help,you is excellent . :)
My plugin :
Code:
use strict;
use Plugins;
use Log qw( warning message error );
use Globals;

Plugins::register('Olá', 'Olá is hello in english', \&inUnload);
Plugins::addHook('in_game', \&onCommand, undef);

sub onCommand {
my $logHook = Log::addHook(
sub {
   my (undef, $domain, undef, undef, $msg) = @_;
   return if $domain eq 'test';
   warning "Hook: $msg", 'test';
   }
   );
   
   sub inUnload {
   Log::delHook($logHook);
   }


All appears on console openkore,the plugin duplicate,understand :D
And the plugin lines,to activate on determinated message :
Code:
   my (undef, $domain, undef, undef, $msg) = @_;
   return if $domain eq 'test';
   if ($msg =~/Olá/i)
   {
   warning "Hook: $msg", 'test';
   }
   }
   );

But,i discover that's work too :
Code:

use strict;
use Plugins;
use Log qw( warning message error );
use Globals;

Plugins::register('Olá', 'Olá is hello in english', \&inUnload);

my $logHook = Log::addHook(
sub {
my (undef, $domain, undef, undef, $msg) = @_;
if ($msg =~/Olá/i)
{
warning "Bem vindo\n";
}
}
)
;
   
sub inUnload {
Log::delHook($logHook);
}

Other ask,last,please,please :
Code:
my (undef, $domain, undef, undef, $msg) = @_;

Why many " undef's " ?
I remove a undef and the plugin has not activated.
Example :
Code:
my (undef, $msg) = @_;
if ($msg =~ /Olá/i)
{
warning "Olá is hello in portuguese";
}

doesn't work.
Why ?
Thanks ! Now i will stay quiet


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 12:42 
Offline
Developers
Developers

Joined: 05 Dec 2008, 05:42
Posts: 1811
Since Log hook triggers every time anything is printed, you should be careful to properly filter the message and not to trigger your own hook (that's what all with message domain 'test' was in example), or else it would loop and flood like that. Actually, it's not a good idea to hook on Log at all. There are plenty of normal hooks for most things.

For Perl-related things, skim through some perl books to get familiar with basic things.

There's also an example of using Log hooks in macro plugin.


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 13:45 
Offline
Human
Human

Joined: 07 Oct 2011, 11:21
Posts: 24
Oh Man,Thanks very much,
Now,my next tentative will :
Create a Plugin or a macro to verify hp @mercenary and,when mercenary's hp is lesser that x%,use skill Heal on mercenary !
Don't is very hard,but,i have tried many times,but my objetive don't was reached
For you see how i much grateful,look my expression :
Code:
Expression Regular : (Thanks)*


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 17:27 
Offline
Developers
Developers

Joined: 05 Dec 2008, 05:42
Posts: 1811
Unknown6996 wrote:
verify hp @mercenary and,when mercenary's hp is lesser that x%,use skill Heal on mercenary

No plugins or macros needed for that, just use partySkill with "target @mercenary".


Top
 Profile  
 
 Post subject: Re: [Help]How to do activate plugin when...
PostPosted: 31 Oct 2011, 22:51 
Offline
Human
Human

Joined: 07 Oct 2011, 11:21
Posts: 24
Yes,yes .
I use the 'search' (box) and i tried to find somenthing associated with mercenary.
First i tried search for mercenary
And appears :
Code:
mercenary [0|1]

Ok,ok.
Second,i tried search for mercenary_hp and appears :
Code:
useSelf_skill White potion
hp < 80%

Then,if appears useSelf_skill,have as,possibly,heal with partySkill .
Then,i tried search by 'useSelf_skill!
Code:
[target {<player names> | @homunculus | @mercenary}]

I Created many configurations from heal mercenary :
Code:
partySkill Heal {
lvl 10
mercenary_hp < 60%
notWhileSitting 1
}

partySkill Heal {
lvl 10
target_hp < 60%
notWhileSitting 1
}

partySkill Heal {
lvl 10
target_hp < 60%
target @mercenary
notWhileSitting 1
}

partySkill Heal {
lvl 10
mercenary_hp < 60%
target @mercenary
notWhileSitting 1
}

But,this configurations,is for a friend.
And His response has :
Code:
doesn't work

I was to :
Code:
http://forums.openkore.com/viewtopic.php?f=36&t=7985

But okay.
Probably the problem are with my friend and not with openkore ! :B ( Troll face )
Thanks very much :)
Again !
Code:
(Thanks)*


Can you help me here :
viewtopic.php?f=10&t=16125
viewtopic.php?f=10&t=15983&hilit=ANTI+BOT

One day I will be,a openkore developers too.I want work with plugins and archives of openkore because this ;x

#Funny part :
The topics are closed after answered ?
Code:
Log:addHook(
sub {
my (undef, $resp) = @_;
if ($resp =~ /yes/)
{
warning " Please,close the topic.Thanks,oh thanks !"
}
else
{
warning " :B "
}
}

One day I'll be there at the top in creating plugin,you will see.rsrs


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group