Condition to trigger macro when there are no players nearby

All about the macro plugin can be found in this forum. This forum is intended for the macro plugin only.

Moderator: Moderators

kaoru
Human
Human
Posts: 34
Joined: 20 Jun 2008, 17:47
Noob?: No

Condition to trigger macro when there are no players nearby

#1 Post by kaoru »

I need to reproduce an event which triggers a macro whenever a player is NOT on screen. I'd also like to add exceptions to that trigger.

Code: Select all

player /^(?![.*]$)/
I suppose that works for excluding all players from the player state, but how should I add an exception for player1 and player2, so the macro can successfully reproduce a hypothetical "player not player1, player2"?

EDIT: altered original topic title from "player not state and exceptions trough regexp" to "Condition to trigger macro when there are no players nearby"
Last edited by kaoru on 14 Nov 2012, 12:43, edited 1 time in total.
kaoru
Human
Human
Posts: 34
Joined: 20 Jun 2008, 17:47
Noob?: No

Re: Condition to activate macro when there are no players nearby

#2 Post by kaoru »

Just did some tests and the "player /^(?!.*$)/" condition didn't work as I expected... As there's no player specified, the macro simply doesn't trigger.

I'd be pretty satisfied by now if I could come up with a condition that triggers whenever players aren't nearby, much like the safe condition from onlyWhenSafe works, or something like a "hook player_exist", but the opposite.

Any suggestions?
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Condition to trigger macro when there are no players nearby

#3 Post by EternalHarvest »

It's probably easy to implement such condition, for example with syntax "player none", with something like this:

Code: Select all

Index: Macro/Automacro.pm
===================================================================
--- Macro/Automacro.pm	(revision 8296)
+++ Macro/Automacro.pm	(working copy)
@@ -302,6 +302,8 @@
 sub checkPerson {
 	my ($who, $dist) = $_[0] =~ /^(["\/].*?["\/]\w*)\s*,?\s*(.*)/;
 
+	return !scalar @{$playersList->getItems()} if $who = 'none';
+
 	foreach my $player (@{$playersList->getItems()}) {
 		next unless match($player->name, $who);
 		if ($dist > 0) {
gelo2012
Plain Yogurt
Plain Yogurt
Posts: 58
Joined: 17 Sep 2012, 13:54
Noob?: Yes
Location: Sa Puso Mo

Re: Condition to trigger macro when there are no players nearby

#4 Post by gelo2012 »

EternalHarvest wrote:It's probably easy to implement such condition, for example with syntax "player none", with something like this:

Code: Select all

Index: Macro/Automacro.pm
===================================================================
--- Macro/Automacro.pm	(revision 8296)
+++ Macro/Automacro.pm	(working copy)
@@ -302,6 +302,8 @@
 sub checkPerson {
 	my ($who, $dist) = $_[0] =~ /^(["\/].*?["\/]\w*)\s*,?\s*(.*)/;
 
+	return !scalar @{$playersList->getItems()} if $who = 'none';
+
 	foreach my $player (@{$playersList->getItems()}) {
 		next unless match($player->name, $who);
 		if ($dist > 0) {
I'm sorry but I can't understand this. How can I then use this code for an automacro? Any examples?