[Help]How to do activate plugin when...

For everything NOT server specific support. Do NOT ask for connectivity help here!.

Moderator: Moderators

Post Reply
Message
Author
Unknown6996
Human
Human
Posts: 24
Joined: 07 Oct 2011, 11:21
Noob?: No

[Help]How to do activate plugin when...

#1 Post by Unknown6996 »

on determined text .
I had tried this :

Code: Select all

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 ?

EternalHarvest
Developers
Developers
Posts: 1800
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: [Help]How to do activate plugin when...

#2 Post by EternalHarvest »

That't documented (with examples) in Log.pm - there are different kind of hooks for console output.

Unknown6996
Human
Human
Posts: 24
Joined: 07 Oct 2011, 11:21
Noob?: No

Re: [Help]How to do activate plugin when...

#3 Post by Unknown6996 »

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: Select all

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: Select all

$format =~ s/d/$tmpdate[3]/g;
But don't understand.
and I realized that is used too this :

Code: Select all

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

jealkeja
Noob
Noob
Posts: 4
Joined: 31 Oct 2011, 00:31
Noob?: No

Re: [Help]How to do activate plugin when...

#4 Post by jealkeja »

someone will have to confirm but I think, for example,

Code: Select all

console /Not Enough SP/i
would work as a condition

EternalHarvest
Developers
Developers
Posts: 1800
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: [Help]How to do activate plugin when...

#5 Post by EternalHarvest »

Something like that:

Code: Select all

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);

Unknown6996
Human
Human
Posts: 24
Joined: 07 Oct 2011, 11:21
Noob?: No

Re: [Help]How to do activate plugin when...

#6 Post by Unknown6996 »

Ok,thanks,i got.
:D
But,i realized that,when the plugin have this line :

Code: Select all

return if $domain eq 'test';
In console appears :

Code: Select all

[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: Select all

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: Select all

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: Select all

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: Select all

in_game 
mainLoop_pre 
Other,other,other :

Code: Select all

'test'
Whats is this ? and what is influence of this in my plugin ?

Code: Select all

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: Select all

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: Select all

   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: Select all


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: Select all

my (undef, $domain, undef, undef, $msg) = @_;
Why many " undef's " ?
I remove a undef and the plugin has not activated.
Example :

Code: Select all

my (undef, $msg) = @_;
if ($msg =~ /Olá/i)
{
warning "Olá is hello in portuguese";
}
doesn't work.
Why ?
Thanks ! Now i will stay quiet

EternalHarvest
Developers
Developers
Posts: 1800
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: [Help]How to do activate plugin when...

#7 Post by EternalHarvest »

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.

Unknown6996
Human
Human
Posts: 24
Joined: 07 Oct 2011, 11:21
Noob?: No

Re: [Help]How to do activate plugin when...

#8 Post by Unknown6996 »

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: Select all

Expression Regular : (Thanks)*

EternalHarvest
Developers
Developers
Posts: 1800
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: [Help]How to do activate plugin when...

#9 Post by EternalHarvest »

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".

Unknown6996
Human
Human
Posts: 24
Joined: 07 Oct 2011, 11:21
Noob?: No

Re: [Help]How to do activate plugin when...

#10 Post by Unknown6996 »

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: Select all

mercenary [0|1]
Ok,ok.
Second,i tried search for mercenary_hp and appears :

Code: Select all

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: Select all

[target {<player names> | @homunculus | @mercenary}]
I Created many configurations from heal mercenary :

Code: Select all

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: Select all

doesn't work
I was to :

Code: Select all

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: Select all

(Thanks)*
Can you help me here :
http://forums.openkore.com/viewtopic.php?f=10&t=16125
http://forums.openkore.com/viewtopic.ph ... t=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: Select all

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

Post Reply