[plugin help] basic movements (move, attack, skill)

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

Moderator: Moderators

NiTRO106
Plain Yogurt
Plain Yogurt
Posts: 64
Joined: 30 Nov 2012, 20:27
Noob?: No

[plugin help] basic movements (move, attack, skill)

#1 Post by NiTRO106 »

hello. i'm trying to write a plugin for educational purposes only. i just want to create a plugin that makes the character move to a specific location. i understand now the basics on creating the plugin and i also learned perl language for a while with the help of the examples that i found but i find a hard time making a command to move the character.

here is an example plugin that i found on the SVN:

Code: Select all

package ExamplePlugin;

use strict;
use Plugins;
my $count = 0 if (!defined my $count);


Plugins::register('example', 'Example Plugin', \&Unload, \&Reload);
Plugins::addHook('AI_pre', \&Called);

sub Unload {
	print "I have just been unloaded\n";
}

sub Reload {
	print "I have just been reloaded\n";
}

sub Called {
	if ($count == 0) {
		$count++;
		print "I am example.pl and I will spam this message the first time the AI sequence is started.\n";
	}
}

# Important! Otherwise plugin will appear to fail to load.
return 1;
any sample code, line or anything that can shared to this topic is greatly appreciated :)
flashdbest
Plain Yogurt
Plain Yogurt
Posts: 61
Joined: 12 Nov 2012, 09:22
Noob?: Yes

Re: [plugin help] basic movements (move, attack, skill)

#2 Post by flashdbest »

The easiest method would be Commands::run

EX:

Commands::run("move 123 456")
NiTRO106
Plain Yogurt
Plain Yogurt
Posts: 64
Joined: 30 Nov 2012, 20:27
Noob?: No

Re: [plugin help] basic movements (move, attack, skill)

#3 Post by NiTRO106 »

@flashdbest

thanks! with Commands::run, can i do such as doCommands? what about if, else statements? it is the same as writing a macro?
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: [plugin help] basic movements (move, attack, skill)

#4 Post by EternalHarvest »

What do you mean? Commands::run is the thing that executes console commands, just that. User interface, doCommand block logic, macro plugin etc all use it to execute console commands.
NiTRO106
Plain Yogurt
Plain Yogurt
Posts: 64
Joined: 30 Nov 2012, 20:27
Noob?: No

Re: [plugin help] basic movements (move, attack, skill)

#5 Post by NiTRO106 »

@EternalHarvest

i was just curious about Commands::run because i was trying to understand some plugins that are found in the SVN and i never saw a command or a call like that in the scripts.
NiTRO106
Plain Yogurt
Plain Yogurt
Posts: 64
Joined: 30 Nov 2012, 20:27
Noob?: No

Re: [plugin help] basic movements (move, attack, skill)

#6 Post by NiTRO106 »

thanks guys! i can now move my character using a plugin. i want to ask again on how to integrate a plugin to a config block on config.txt?

BTW, here's a sample plugin that i just created today. just wanted to share some little knowledge here for those people who are learning by just looking some examples. :)

Code: Select all

package samplePlugin;

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

Plugins::register("example", "An Example Plugin by NiTRO106", \&on_unload, \&on_reload);
my $aiHook = Plugins::addHook("AI_pre", \&on_AI);

sub on_unload {
	Plugins::delHook("AI_pre", $aiHook);
}

sub on_reload {
	&on_unload;
}

sub on_AI {
	Commands::run("conf route_randomWalk 0");
	Commands::run("move 58 112");
	Commands::run("c hello Ragnarok Online! :)");
	message "Plugin Done.\n";
	on_unload();
}

return 1;
NiTRO106
Plain Yogurt
Plain Yogurt
Posts: 64
Joined: 30 Nov 2012, 20:27
Noob?: No

Re: [plugin help] basic movements (move, attack, skill)

#7 Post by NiTRO106 »

can anyone help me with this problem again? im trying to create a plugin that can simply walk using if, else statements and main::ai_route but the problem is it is doing repetitive messages. is there a way to run the subroutine once? if i call the subroutine unload, it will call the moveChar once but it will not respond to it, thus resuming to the normal AI sequence. since i don't really have any knowledge about writing plugins or hooks, i just copy some lines from this plugin and trying to understand it (LINK: http://forums.openkore.com/viewtopic.php?f=34&t=15714).

here's a screenshot and the code:
https://www.dropbox.com/s/1voy090r0rmoj85/openkore.bmp [screenshot]

Code: Select all

package samplePlugin;

use Plugins;
use Globals;
use Misc;
use Utils;
use Log qw(message);
use I18N qw(bytesToString);

Plugins::register("samplePlugin", "An Example Plugin by NiTRO106", \&unload, \&reload);
my $hooks = Plugins::addHooks(
['packet/npc_talk', \&responseNPC, undef],
['AI_pre', \&on_AI, undef]
);

my $time = time;
my $qtimeout = 1;

sub reload {
   &unload;
}

sub unload {
   Plugins::delHooks($hooks);
}

sub moveChar {
   main::ai_route($field->{name} eq "payon", "$_[1]", "$_[2]", attackOnRoute => 0, noSitAuto => 1);
   message "Moving to Payon $_[0]. ($_[1], $_[2])\n", "info";
}

sub on_AI {
   if(($field->{name} eq "payon")) {
      message "I am currently now at Payon\n", "info";
      last;
   }
   else {
      $moveChar;
      &moveChar("Tool Dealer", "160", "96");
      last;
   }
}

return 1;
any help about this matter is greatly appreciated. thanks in advance! :)
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: [plugin help] basic movements (move, attack, skill)

#8 Post by EternalHarvest »

NiTRO106 wrote:thanks guys! i can now move my character using a plugin. i want to ask again on how to integrate a plugin to a config block on config.txt?
You do not integrate anything into config. You just check config for your options, as all other features do. There is no centralized API for working with blocks (except Misc::checkSelfCondition etc), but there's plenty of examples of how it's done in AI::CoreLogic.
NiTRO106 wrote:is there a way to run the subroutine once? if i call the subroutine unload, it will call the moveChar once but it will not respond to it, thus resuming to the normal AI sequence.
There's legacy AI queue with both legacy AI logic and tasks; there's task manager with tasks too. You should to look into how AI logic and tasks done. Also examples of what you're trying there is exactly why we have macro plugin, which makes seemingly trivial things like these trivial to do.

You don't use strict and warnings. It's kind of the first thing ever explained in all Perl materials (including "Learn Perl in about 2 hours 30 minutes" you claim to have partially read) and there's generally no need to go with no strict, you will only get a ton of problems if you don't know Perl well.
ai_route($field->{name} eq "payon"
So you will move either to field named "1" or to field named "".
"$_[1]", "$_[2]"
No need for quotes.
"160", "96"
Same there.
$moveChar;
What's this? Just use strict already.
NiTRO106
Plain Yogurt
Plain Yogurt
Posts: 64
Joined: 30 Nov 2012, 20:27
Noob?: No

Re: [plugin help] basic movements (move, attack, skill)

#9 Post by NiTRO106 »

EternalHarvest wrote:You do not integrate anything into config. You just check config for your options, as all other features do. There is no centralized API for working with blocks (except Misc::checkSelfCondition etc), but there's plenty of examples of how it's done in AI::CoreLogic.
EternalHarvest wrote:There's legacy AI queue with both legacy AI logic and tasks; there's task manager with tasks too. You should to look into how AI logic and tasks done. Also examples of what you're trying there is exactly why we have macro plugin, which makes seemingly trivial things like these trivial to do.
those things confuses me a lot. after you posted that, ive checked the CoreLogic.pm to see if there are some functions that can be called and understand to me but so far i am trying to understand the processLockMap subtask because it has some similar commands to 'move'. i also check some hooks here on the wiki (LINK: http://www.openkore.com/index.php/Hooks). i'm studying it now.