[Tk Mission]Macro creation help needed (interesting topic !)

All resolved question will be found here. It is recommended that you browse / search through this section first and see if your question has been answered before

Moderators: Moderators, Documentation Writers

Message
Author
Gnagna
Noob
Noob
Posts: 7
Joined: 11 Dec 2013, 07:52
Noob?: Yes

[Tk Mission]Macro creation help needed (interesting topic !)

#1 Post by Gnagna »

Hy,

I'm new to Perl and the macro writing, i read the faq on openkore wiki and searched many things in the forum and others and in the google code of openkore too.
Here is my problem.

I'm trying to write a macro in order to cast "Taekwon Mission" until i'm out of mana or the "monster" changed and has a base lvl < 70, then use a sound to alert me for example. The problem is i don't find how i could have the information required concerning the monster and his base lvl after i cast "Taekwon Mission" (monster name, monster id, monster base lvl, etc.) and then use it in my loop whastover.
Here is my beginning, if someone could help me i would be grateful

Code: Select all

automacro tkMissionChange{
	sp < 10
	call tkMissionChange
}

macro tkMissionChange {
	log Begin macro tkMissionChange
	log SP at first : $.sp
	do sit
	if ($.sp == 191) {		# will do a while loop in the end
		log Mana is full
		do ss TK_MISSION
#	        $monster = -> here i would like to get the information of the monster i need (id, name, base level, etc.)
		log \$monster : $monster
	}
	log End macro tkMissionChange
}

I have see those lines in the openkore files but i don't see if it is usable or not

Code: Select all

# TODO test if we must use ID to know if the packets are meant for us.
# ID is monsterID
sub taekwon_packets {
	my ($self, $args) = @_;
	my $string = ($args->{value} == 1) ? T("Sun") : ($args->{value} == 2) ? T("Moon") : ($args->{value} == 3) ? T("Stars") : TF("Unknown (%d)", $args->{value});
	if ($args->{flag} == 0) { # Info about Star Gladiator save map: Map registered
		message TF("You have now marked: %s as Place of the %s.\n", bytesToString($args->{name}), $string), "info";
	} elsif ($args->{flag} == 1) { # Info about Star Gladiator save map: Information
		message TF("%s is marked as Place of the %s.\n", bytesToString($args->{name}), $string), "info";
	} elsif ($args->{flag} == 10) { # Info about Star Gladiator hate mob: Register mob
		message TF("You have now marked %s as Target of the %s.\n", bytesToString($args->{name}), $string), "info";
	} elsif ($args->{flag} == 11) { # Info about Star Gladiator hate mob: Information
		message TF("%s is marked as Target of the %s.\n", bytesToString($args->{name}), $string);
	} elsif ($args->{flag} == 20) { #Info about TaeKwon Do TK_MISSION mob
		message TF("[TaeKwon Mission] Target Monster : %s (%d%)"."\n", bytesToString($args->{name}), $args->{value}), "info";
	} elsif ($args->{flag} == 30) { #Feel/Hate reset
		message T("Your Hate and Feel targets have been resetted.\n"), "info";
	} else {
		warning TF("flag: %s gave unknown results in: %s\n", $args->{flag}, $self->{packet_list}{$args->{switch}}->[0]);
	}
}
I found the code here : https://code.google.com/p/koretw/source ... 0.pm?r=185

I don't know how i can have access to those informations, i'm new to Perl, the macros and the syntax :s, so i don't know if there are some kind of global variables or something like this to access to informations that may have been stored somewhere after the cast of my skill "Taekwon Mission".

Thanks in advance ;-)

EDIT: I tried to modify the code here

Code: Select all

elsif ($args->{flag} == 20) { #Info about TaeKwon Do TK_MISSION mob
		message TF("[TaeKwon Mission] Target Monster : %s (%d%)"."\n", bytesToString($args->{name}), $args->{value}), "info";[/color]
	} 
after trying many things, $args seems to be a class, but i don't find which one, i tried to look at some ".pm" files such as "Actor.pm" or "Monster.pm" to see if there were any getter/setter useful, but i don't see getter/setter such as "baseLvl", "id", etc, so it may be not those classes, the problem is that the file "ServerType0.pm" is difficult to understand because in every "sub" the $args does not seem to be the same, so i don't understand how could the programmers know which were the proper $args->(THE_INFORMATION_I_WANT) and how to classify all the informations coming from the server ?

My main problem is also that i don't know how to get the information of "ServerType0.pm" when my spell "Taekwon mission" is cast in the "macros.txt" files what is the way to communicate between those two ? Is there some kind of global variable or global object that can be summoned from the "macros.txt" file ?

Please Help me :s

User avatar
SkylorD
Moderators
Moderators
Posts: 1167
Joined: 16 Dec 2011, 02:53
Noob?: No
Location: Brazil
Contact:

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#2 Post by SkylorD »

Code: Select all

	} elsif ($args->{flag} == 20) { #Info about TaeKwon Do TK_MISSION mob
	    Plugins::callHook('taekwon_packets_getmob', {monsterName => bytesToSring($args->{name})});
		message TF("[TaeKwon Mission] Target Monster : %s (%d%)"."\n", bytesToString($args->{name}), $args->{value}), "info";
	}
macros.txt :

Code: Select all

sub tkpackets {
my (undef, $args) = @_;
$tkmission = $args->{monsterName};
return $tkmission;
}

automacro exp {
hook taekwon_packets_getmob
run-once 1 
call {
do eval tkpackets warning "Monster name : $tkmission";
}
}
Could you test it ?
Learn rules

Gnagna
Noob
Noob
Posts: 7
Joined: 11 Dec 2013, 07:52
Noob?: Yes

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#3 Post by Gnagna »

Thanks for your answer, yes it is working, but i don't see how to use the information after that. The value $tkmission is only available in the "do eval" command, and i'm force to use the command just after hooking the "taekwon_packets_getmob" or else it is empty. here is what i'm trying to do:

The code is no longer truely valid, i should do something easier now just to cast tk mission and trigger the hook each time modify a variable and so on until the mob name changes, then stopping the macro/automacro (here is the old code half/modified trying some stuffs)

Code: Select all

sub tkpackets {
	my (undef, $args) = @_;
	$tkmission = $args->{monsterName};
	return $tkmission;
}

automacro exp {
	hook taekwon_packets_getmob
	run-once 1
	call {
		do eval tkpackets "$lastmonster = $tkmission"; # wrong syntax, i want to store the value in a variable i can re-use after that in order to do some test on the value condition and refresh the value each time i cast the "TK_MISSION" in order to kno when to stop the loop
		
		log Begin macro tmc
		log SP au depart : $.sp
		
		log Initial monster = $lastmonster
		
		while ($.sp < 191) as spempty
			do sit
		end spempty
		
		if ($.sp >= 191) goto theloop
		:theloop
			while ($.sp >= 10) as castmission
				do ss TK_MISSION
				do eval tkpackets warning "Current Monster Name : $tkmission"; #useless too, just to show i want to refresh and test the new "hooked" value
				$lastmonster = $tkmission;
				if ($lastmonster != $tkmission) {
					log NEW Monster : $tkmission
					do sit
					stop
				}
				log loop: before endwhile
			end castmission
			
			while ($.sp < 191) as spemptyif
				do sit
			end spemptyif
			if ($.sp >= 191) goto theloop
			
			log End macro tmc
	}
}
Thanks in advance.

(it's indeed more a syntax knowledge problem for me :s, i tried things to hook the event before but unsuccessfully, yet it seems to only work inside an automacro and not inside a macro)

User avatar
SkylorD
Moderators
Moderators
Posts: 1167
Joined: 16 Dec 2011, 02:53
Noob?: No
Location: Brazil
Contact:

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#4 Post by SkylorD »

sub tkpackets {
my (undef, $args) = @_;
my $tkmission = $args->{monsterName};
return "$tkmission";
}

automacro exp {
hook taekwon_packets_getmob
run-once 1
call {
$mob = tkpackets()
do eval warning "Monster name : $mob\n";
}
}
See if it helps.
I forgot of "my" in "$tkmission = $args->{name}"; #sorry for this Worked with do eval tkpackets warning , and not with variable. Now is working with var.
I forgot 2 of quotes in return.

Read this : http://www.openkore.com/index.php/Macro ... ubroutines
Learn rules

Gnagna
Noob
Noob
Posts: 7
Joined: 11 Dec 2013, 07:52
Noob?: Yes

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#5 Post by Gnagna »

Thanks man :)

I modified my macro/automacro, but i still get warnings ??? do you know why it's not working ?

Here is the macro.txt file, i launch manually first the "macro tmc" on the console then it should loop alone until the mob name changed:

Code: Select all

sub tkpackets {
	my (undef, $args) = @_;
	my $tkmission = $args->{monsterName};
	return "$tkmission";
}

automacro changeTkMission {
	hook taekwon_packets_getmob
	run-once 1
	call changemission	
		
}
			
macro tmc {
	$counter = -1
	do ss TK_MISSION
}

macro changemission{
	do eval warning "Loop number : $counter\n";
	$counter++
	if ($counter == 0) goto counter0
	if ($counter != 0) goto notcounter0
	:counter0
		log if counter 0
		$1stmob = tkpackets()
		my $mob = $1stmob
		do eval warning "1stmob : $1stmob, mob: $mob";
		if ($.sp >= 10) {
			log if sp >= 10
			do ss TK_MISSION
		}
		else {
			log else sp >= 10
			while ($.sp < 191) as spempty
				do sit
			end spempty
			do eval warning "SP replenished";
			do ss TK_MISSION
		}
	:notcounter0
		log else counter 0
		my $mob = tkpackets()
		if ($1stmob != $mob) {
			do eval warning "NEW Monster!!!!!\n";
			do eval warning "1stmob : $1stmob, newmob: $mob";
			do sit
			stop
			log End macro tmc
		}
		else {
			if ($.sp >= 10) {
				do ss TK_MISSION
			}
			else {
				while ($.sp < 191) as spempty
					do sit
				end spempty
				do eval warning "SP replenished";
				do ss TK_MISSION
			}
		}
}
Here is the warning log:
Image

Thanks in advance.

I've taken a look at the link you gave me thanks for the tips :)

User avatar
SkylorD
Moderators
Moderators
Posts: 1167
Joined: 16 Dec 2011, 02:53
Noob?: No
Location: Brazil
Contact:

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#6 Post by SkylorD »

http://forums.openkore.com/viewtopic.ph ... 50#p197350

else and if statments.

An example :

Change this :

Code: Select all

  if ($.sp >= 10) {
         log if sp >= 10
         do ss TK_MISSION
      }
      else {
for this :

Code: Select all

  if ($.sp >= 10) {
         log if sp >= 10
         do ss TK_MISSION
      } else {
No one problem here.

PS :

Code: Select all

      log else counter 0
      my $mob = tkpackets()
You don't need pre-declare my before $mob. Only on sub tkpackets.
Now use $mob.

I want to know what are you trying to do :

Code: Select all

log if counter 0
And this :

Code: Select all

:notcounter0
      log else counter 0

Code: Select all

$1stmob = tkpackets()
my $mob = $1stmob
Again : You don't need set 'my' at now. That's because tkpackets is an PERL subroutine and use strict. Works totally different!
Learn rules

Gnagna
Noob
Noob
Posts: 7
Joined: 11 Dec 2013, 07:52
Noob?: Yes

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#7 Post by Gnagna »

i was thinking that the my meant it was local and not global as the variables seems to be global with the "macros.txt"

for the

Code: Select all

log if counter 0

Code: Select all

log else counter 0
Those lines are just some logs to see if i do enter the if or else statement
I did some other macros with the:

Code: Select all

if (mycondition) {
			log blabla
			do ss TK_MISSION
		}
		else {
with a proper white space being careful with going to the line with "enter key on keyboard" just after the "}" of the if statement in order to have no additionnal white space and it was working :s
And am i constraint to use the "tkpackets()" as the first instruction of the call

Code: Select all

call { $mob = tkpackets() }
Or could i use it as i did after doing some logs and setting a "$counter++" in order to separte the first time the hook is triggered (my 1st monster will stay the same forever and will be compared with the $mob which change each time the hook is triggered)

Thanks in advance.

EDIT:

With your correction here is the code :

Code: Select all

sub tkpackets {
	my (undef, $args) = @_;
	my $tkmission = $args->{monsterName};
	return "$tkmission";
}

automacro changeTkMission {
	hook taekwon_packets_getmob
	run-once 1
	call changemission	
		
}
			
macro tmc {
	$counter = -1
	do ss TK_MISSION
}

macro changemission {
	do eval warning "Loop number : $counter\n";
	$counter++
	if ($counter == 0) goto counter0
	if ($counter != 0) goto notcounter0
	:counter0
		log inside counter0
		$firstmob = tkpackets()
		$mob = $firstmob
		do eval warning "firstmob : $firstmob, mob: $mob";
		if ($.sp >= 10) {
			log if sp >= 10
			do ss TK_MISSION
		} else {
			log elsesp >= 10
			while ($.sp < 191) as spempty
				do sit
			end spempty
			do eval warning "SP replenished";
			do ss TK_MISSION
		}
	:notcounter0
		log insidenotcounter0
		$mob = tkpackets()
		if ($firstmob != $mob) {
			do eval warning "NEW Monster!!!!!\n";
			do eval warning "firstmob : $firstmob, newmob: $mob";
			do sit
			stop
			log End macro tmc
		} else {
			if ($.sp >= 10) {
				do ss TK_MISSION
			} else {
				while ($.sp < 191) as spempty
					do sit
				end spempty
				do eval warning "SP replenished";
				do ss TK_MISSION
			}
		}
}
I have got no more warnings but, the value $firstmob is empty after the

Code: Select all

$firstmob = tkpackets()
Image
It seems

Code: Select all

$firstmob = tkpackets()
is not working being written here
Last edited by Gnagna on 16 Dec 2013, 10:22, edited 1 time in total.

User avatar
SkylorD
Moderators
Moderators
Posts: 1167
Joined: 16 Dec 2011, 02:53
Noob?: No
Location: Brazil
Contact:

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#8 Post by SkylorD »

Use varvar condition.

Yes, your Counter is resulting in 1 because :

$counter = -1

Instead of this, use $counter--
Learn rules

Gnagna
Noob
Noob
Posts: 7
Joined: 11 Dec 2013, 07:52
Noob?: Yes

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#9 Post by Gnagna »

srry read the post again please, i just modified it at the same time u answered :(, i got one error because of the var name "1stmonster" i change it to "firstmonster" it's better, then i have no problem with the counter, i initialized it with "$counter = -1" then i log then i do "$counter++" so it's ok for it to log " -1 ", the true problem is what i modified, it is the empty thing :s
The tkpackets() seems to be lost if i don't do $mob = tkpackets() as first instruction of the call

Even when modifying and doing it as first instruction it's empty now !?

Code: Select all

$mob = tkpackets()
	do eval warning "Mob : $mob";
	do eval warning "Loop number : $counter\n";
	$counter++
	if ($counter == 0) goto counter0
	if ($counter != 0) goto notcounter0
	:counter0
		log inside counter0
		$firstmob = $mob
		do eval warning "firstmob : $firstmob, mob: $mob";
		if ($.sp >= 10) {
			log if sp >= 10
			do ss TK_MISSION
		} else {
			log elsesp >= 10
			while ($.sp < 191) as spempty
				do sit
			end spempty
			do eval warning "SP replenished";
			do ss TK_MISSION
		}
I'm quite lost, i looked my screen for a too long period of time i'm not lucid xD, i'm not seeing what's wrong it should be obvious :s

User avatar
SkylorD
Moderators
Moderators
Posts: 1167
Joined: 16 Dec 2011, 02:53
Noob?: No
Location: Brazil
Contact:

Re: [Tk Mission]Macro creation help needed (interesting topic !)

#10 Post by SkylorD »

Try this code :

Code: Select all

sub tkpackets {
   my (undef, $args) = @_;
   my $tkmission = $args->{monsterName};
   return "$tkmission";
}
  

automacro changeTkMission {
run-once 1
hook taekwon_packets_getmob
varvar Counter unset
varvar OldMonsters unset
call {
$Counter++

if ($Counter == 1) goto nomission
if ($Counter >= 2) goto yesmission
 
:nomission
$Counter++
$OldMonsters = tkpackets()
do eval warning "First time - Get Monster\n";
goto end



:yesmission
$Counter--
$NewMonsters = tkpackets()
do eval warning "Not first time. It's your $Counter time...\n";


if ($NewMonsters != $OldMonsters) goto newdetect
do eval warning "No monsters detected\n";
goto end


:newdetect
do eval warning "New monsters : $NewMonsters ~ Old monsters : $OldMonsters\n"
goto end


:end


}

}

macro tmc {
do ss TK_MISSION
}
Just test it.
Try to get $mob even after call. Set varvar mob unset. :
varvar mob unset
call {
$mob = tkpackets()
Learn rules

Locked