wildcard on looting control?

Discussion about everything RO and OpenKore related. This place is NOT for ANY kind of support questions.

Moderator: Moderators

Tomslucky7
Noob
Noob
Posts: 4
Joined: 09 Nov 2013, 03:44
Noob?: Yes

wildcard on looting control?

#1 Post by Tomslucky7 »

Hey guys, love your bot! use it on multiple accounts lol.

I'm just curious.. Is it possible to use a wildcard within the "pickupitems" control text document in the control folder to loot all of a certain type of item?

example: * Card 2

would loot all cards that drop without hesitation.
Beechbone
Noob
Noob
Posts: 7
Joined: 01 Nov 2013, 17:47
Noob?: No

Re: wildcard on looting control?

#2 Post by Beechbone »

No, the current check does a literal compare.

But, if you change the file src/Misc.pm:

Code: Select all

sub items_control {
	my $name = lc shift;

	return $items_control{$name} if exists $items_control{$name};
	
	my $result = $items_control{all} || {};
	
	foreach my $key (keys %$items_control) {
		next unless $key =~ m!^/(.*)/$!;
		my $regex = $1;
		if ($name =~ /$regex/) {
			$result = $items_control{$key};
		}
	}
	
	return $items_control{$name} = $result;
}
it will support regular expressions, e.g.

Code: Select all

/.* Card/ 2
Tomslucky7
Noob
Noob
Posts: 4
Joined: 09 Nov 2013, 03:44
Noob?: Yes

Re: wildcard on looting control?

#3 Post by Tomslucky7 »

Awesome! so if i modify it to look like that, it will work? why the /./?
Tomslucky7
Noob
Noob
Posts: 4
Joined: 09 Nov 2013, 03:44
Noob?: Yes

Re: wildcard on looting control?

#4 Post by Tomslucky7 »

So.. I tried your method (both for items_control and for pickupitems. Pickupitems is the one that I wanted to change)

Then I get this error when trying to start it.

What's going on??

Image

(edit) here is what the codes look like

Pickupitems

Code: Select all

sub pickupitems {
   my $name = lc shift;

   return $pickupitems{$name} if exists $pickupitems{$name};
   
   my $result = $pickupitems{all} || {};
   
   foreach my $key (keys %$pickupitems) {
      next unless $key =~ m!^/(.*)/$!;
      my $regex = $1;
      if ($name =~ /$regex/) {
         $result = $pickupitems{$key};
      }
   }
   
   return $pickupitems{$name} = $result;
}
Items_control

Code: Select all

sub items_control {
   my $name = lc shift;

   return $items_control{$name} if exists $items_control{$name};
   
   my $result = $items_control{all} || {};
   
   foreach my $key (keys %$items_control) {
      next unless $key =~ m!^/(.*)/$!;
      my $regex = $1;
      if ($name =~ /$regex/) {
         $result = $items_control{$key};
      }
   }
Beechbone
Noob
Noob
Posts: 7
Joined: 01 Nov 2013, 17:47
Noob?: No

Re: wildcard on looting control?

#5 Post by Beechbone »

Oops, I was tricked by changing code that was done by someone who uses a different style than me. (Technical: Perl has Hashes and References of Hashes. As you can always use a reference instead of a hash, but not the other way around, I only use references. Openkore uses hashes here, but I used the syntax for hash references...)

The line

foreach my $key (keys %$items_control) {

must be

foreach my $key (keys %items_control) {

Also, check your {} pairs, you seem to be short a } or two.

Edit:

Oops, forgot to explain the regexes:

There are plenty of tutorials on regular expression on the net, so here just the bare basics:

'/' are just the default delimiters used for regular expressions. My code uses them to decide if a entry in items_control is a regex or just plain text.

'.' means "any character", just like the "?" would be in command line wildcards.

'*' means "0 or more of the thing before". So "a*" would match "", "a", "aa", "aaa", "aaaa", and so on. In combination with "." this gives us a match on "anything, even nothing".

'+' means "1 or more of the thing before". So "a+" would match "a", "aa", "aaa", "aaaa", and so on. In combination with "." this gives us a match on "anything, but at least something".

'^' means "beginning of string". So "^Card" would match "Card Monster" but not "Monster Card".

'$' means "end of string". So "Card$" would match "Monster Card" but not "Card Monster".

Note: My code does NOT automatically anchor the regex from the config file with ^$. So actually "/card/" would be enough, as it matches "Card Monster", "Monster Card" and even "Ricardo". Use "/^.* Card$/" if you want to be thorough to the extreme ;)
Beechbone
Noob
Noob
Posts: 7
Joined: 01 Nov 2013, 17:47
Noob?: No

Re: wildcard on looting control?

#6 Post by Beechbone »

BTW: Good work on adapting the code for pickupitems. Just one correction:

Code: Select all

return $pickupitems{$name} if $pickupitems{$name} ne '';
pickupitems uses a different check to see if there is an entry for an item. I don't know if it actually makes a difference, but better safe than sorry. Maybe even

Code: Select all

return $pickupitems{$name} if exists $pickupitems{$name} and $pickupitems{$name} ne '';
Otherwise we could compare a non-existing value with a string. Not an error, but Perl would spit out a warning. Although the current code does not spit out warning, so this may not be needed...
Tomslucky7
Noob
Noob
Posts: 4
Joined: 09 Nov 2013, 03:44
Noob?: Yes

Re: wildcard on looting control?

#7 Post by Tomslucky7 »

this makes a HUGE amount of sense!

thanks for your help man!

I will test this out to see if it works and will give results :)

Also FYI not sure if it matters or not, but I'm using start.exe. Not the PERL one.