[alertsound] plugin - plays sounds on certain events

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
Mushroom
Perl Monk
Perl Monk
Posts: 427
Joined: 04 Apr 2008, 14:04
Noob?: No
Location: Brazil

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#21 Post by Mushroom »

Code: Select all

package alertSound;

use strict;
use Plugins;

use Globals qw(%cities_lut %config $field);
use Utils qw(existsInList);
use Log qw(message);
use Utils::Win32;

Plugins::register('alertSound', 'Plays sounds on certain events.', \&Unload);

my $hooks = Plugins::addHooks(
	['packet_pubMsg', \&onPubChat, undef],
	['packet_privMsg', \&onPrivMsg, undef],
	['self_died', \&onDeath, undef],
	['avoidGM_near', \&onGM, undef],
	['avoidGM_talk', \&onGM, undef],
	['Network::Receive::map_changed', \&onMapChange, undef]
);

my $dead;

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

sub onPubChat {
	my ($packet, $args) = @_;
	if ($args->{MsgUser} =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
		alertSound("Public GM Chat")
	} else {
		alertSound("Public Chat");
	}
}

sub onPrivMsg {
	my ($packet, $args) = @_;
	if ($args->{MsgUser} =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
		alertSound("Private GM Chat")
	} else {
	alertSound("Private Chat");
	}
}

sub onDeath {
	alertSound("Death");
	$dead = 1;
}

sub onMapChange {
   $dead = 0;
}

sub onGM {
	alertSound("GM Near");
}

sub alertSound {
	my ($event) = @_;
	for (my $i = 0; (exists $config{'alertSound_'.$i.'_eventList'}); $i++) {
		next if (!existsInList($config{'alertSound_'.$i.'_eventList'}, $event) || $config{'alertSound_'.$i.'_disabled'} || ($config{'alertSound_'.$i.'_notInTown'} && $cities_lut{$field->name().'.rsw'}) || ($config{"alertSound_".$i."_inLockOnly"} && $field->name() eq $config{'lockMap'}));
		message "Sound alert: $event.\n", "alertSound";
		Utils::Win32::playSound($config{"alertSound_".$i."_play"});
		return;
	}
}

1;
ONLY works using .wav files.

Config example:

Code: Select all

alertSound {
	eventList Public Chat, Private Chat
	notInTown 0
	inLocOnly 0
	disabled 0
	play C:\Documents and Settings\Camila\My Documents\Etc\openkoreSVN\Test.wav
}
Quit.

ProfessorX
Noob
Noob
Posts: 10
Joined: 12 Apr 2009, 07:56
Noob?: No

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#22 Post by ProfessorX »

Thanks Mushroom for all your help. Works great.

Taiko
Noob
Noob
Posts: 8
Joined: 08 Apr 2008, 05:48

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#23 Post by Taiko »

Great plugin, but i have request/suggestion.

Can the plugin be incorporated in macros.txt so that the sound can be played from macro command.

example;
automacro BoTChEcK {
console /BotChecker -101/
call {
play C:\Documents and Settings\Sun\My Documents\Sound1.wav
}
timeout 5
}

Mushroom
Perl Monk
Perl Monk
Posts: 427
Joined: 04 Apr 2008, 14:04
Noob?: No
Location: Brazil

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#24 Post by Mushroom »

Code: Select all

package alertSound;

use strict;
use Plugins;

use Globals qw(%cities_lut %config $field);
use Utils qw(existsInList);
use Log qw(message);
use Utils::Win32;

Plugins::register('alertSound', 'Plays sounds on certain events.', \&Unload);

my $hooks = Plugins::addHooks(
	['packet_pubMsg', \&onPubChat, undef],
	['packet_privMsg', \&onPrivMsg, undef],
	['self_died', \&onDeath, undef],
	['avoidGM_near', \&onGM, undef],
	['avoidGM_talk', \&onGM, undef],
	['Network::Receive::map_changed', \&onMapChange, undef]
);

my $chooks = Commands::register(
   ['play', 'play a sound', \&onCmd, undef],
);

my $dead;

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

sub onPubChat {
	my ($packet, $args) = @_;
	if ($args->{MsgUser} =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
		alertSound("Public GM Chat")
	} else {
		alertSound("Public Chat");
	}
}

sub onPrivMsg {
	my ($packet, $args) = @_;
	if ($args->{MsgUser} =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
		alertSound("Private GM Chat")
	} else {
	alertSound("Private Chat");
	}
}

sub onDeath {
	alertSound("Death");
	$dead = 1;
}

sub onMapChange {
   $dead = 0;
}

sub onGM {
	alertSound("GM Near");
}

sub alertSound {
	my ($event) = @_;
	for (my $i = 0; (exists $config{'alertSound_'.$i.'_eventList'}); $i++) {
		next if (!existsInList($config{'alertSound_'.$i.'_eventList'}, $event) || $config{'alertSound_'.$i.'_disabled'} || ($config{'alertSound_'.$i.'_notInTown'} && $cities_lut{$field->name().'.rsw'}) || ($config{"alertSound_".$i."_inLockOnly"} && $field->name() eq $config{'lockMap'}));
		message "Sound alert: $event.\n", "alertSound";
		Utils::Win32::playSound($config{"alertSound_".$i."_play"});
		return;
	}
}

sub onCmd {
	my ($cmd, $args) = @_;
	Utils::Win32::playSound($args);
}

1;
Here it is.
If the sound doesn't play then the sound directory is wrong or it's not in .wav
Quit.

Taiko
Noob
Noob
Posts: 8
Joined: 08 Apr 2008, 05:48

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#25 Post by Taiko »

I don't know if your'e showing me a code already existed or personally dished up a code for me, but thanks alot !

tried by replacing the above mentioned codes into alertsound.txt and failed to load.
So I copy pasted and renamed alertsound.pl and it didn't work.
So I changed the original suggestion/request;

example;
automacro Botcheck {
console /BotChecker -101/
call {
play C:\Documents and Settings\Sun\My Documents\Sound1.wav
}
timeout 5
}

to

automacro Botcheck {
console /BotChecker -101/
call {
do play C:\Documents and Settings\Sun\My Documents\Sound1.wav
}
timeout 5
}

and it did work !
thanks alot sir !
So we have a new command revealed by Mushroom !

Code: Select all

play "<file directory\soundfilename.wav>"

Mushroom
Perl Monk
Perl Monk
Posts: 427
Joined: 04 Apr 2008, 14:04
Noob?: No
Location: Brazil

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#26 Post by Mushroom »

You should have known that in macros, all the console commands must be used with do. So, do <console command>. Always.
Quit.

Sylph
Noob
Noob
Posts: 5
Joined: 10 Sep 2009, 15:48
Noob?: No

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#27 Post by Sylph »

I use multiple bots, so when the plugin activates I don't know which bot is calling for me. Is there any way that or something that can make the window at taskbar to blink, or change Its color during alertsound or maybe macro events?

CuteHunter
Noob
Noob
Posts: 4
Joined: 04 Apr 2008, 10:47

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#28 Post by CuteHunter »

It easy...
Use different sound or music to each bot to identify each other...

Sylph
Noob
Noob
Posts: 5
Joined: 10 Sep 2009, 15:48
Noob?: No

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#29 Post by Sylph »

Yeah, I do that, but it's annoying x.x
Is there a way to make what I said?

ProfessorX
Noob
Noob
Posts: 10
Joined: 12 Apr 2009, 07:56
Noob?: No

Re: Sound alerts plugin [win32] - v1.3 [1.9] by Joseph

#30 Post by ProfessorX »

Sylph wrote:I use multiple bots, so when the plugin activates I don't know which bot is calling for me. Is there any way that or something that can make the window at taskbar to blink, or change Its color during alertsound or maybe macro events?
making the window at taskbar blink would be awesome

Post Reply