-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageSounds.js
More file actions
98 lines (91 loc) · 3.14 KB
/
MessageSounds.js
File metadata and controls
98 lines (91 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//=============================================================================
// RPG Maker MZ - Message Window Sounds
//=============================================================================
/*:
* @target MZ
* @plugindesc [MZ] [Message]
* @author Eden
* @url https://github.com/ashifolfi/RMMZ-Plugins
*
* @help Adds sounds to text appearing in the message window.
* In message events use \S[number] to select a sound effect. Setting the id to 0 will stop sounds from playing.
*
* @param Sound Effects
* @desc List of sound effects, the order is used to determine which id to use in messages.
* @type file[]
* @dir audio/se/
* @default Default
*
* @param Playback Frequency
* @desc The amount of tics that should pass between each playback
* @type number
* @default 2
*
* @param Minimum Pitch
* @desc The low end of pitch variance
* @type number
* @default 80
*
* @param Maximum Pitch
* @desc The high end of pitch variance
* @type number
* @default 100
*/
const soundParams = PluginManager.parameters("MessageSounds");
soundParams["Sound Effects"] = JSON.parse(soundParams["Sound Effects"]);
soundParams["Minimum Pitch"] = Number(soundParams["Minimum Pitch"]);
soundParams["Maximum Pitch"] = Number(soundParams["Maximum Pitch"]);
soundParams["Playback Frequency"] = Number(soundParams["Playback Frequency"]);
function RandomRange(min, max)
{
// stupid math that checks out
return Math.floor(Math.random() * (max - min)) + min;
}
(function()
{
Window_Message.prototype.clearFlags_orig = Window_Message.prototype.clearFlags;
Window_Message.prototype.clearFlags = function()
{
this.clearFlags_orig();
this._soundEffect = 0;
this._soundWait = soundParams["Playback Frequency"];
}
Window_Message.prototype.processEscapeCharacter_orig = Window_Message.prototype.processEscapeCharacter;
Window_Message.prototype.processEscapeCharacter = function(code, textState)
{
switch (code)
{
case "S":
this.processSoundControl(this.obtainEscapeParam(textState));
break;
default:
this.processEscapeCharacter_orig(code, textState);
break;
}
};
Window_Message.prototype.processSoundControl = function(id)
{
this._soundEffect = id;
};
Window_Message.prototype.flushTextState_orig = Window_Message.prototype.flushTextState;
Window_Message.prototype.flushTextState = function(textState)
{
this.flushTextState_orig(textState);
if (this._soundEffect > 0)
{
if (this._soundWait > 0)
{
this._soundWait--;
}
else
{
AudioManager.playSe({
name: soundParams["Sound Effects"][this._soundEffect - 1],
volume: 100,
pitch: RandomRange(soundParams["Minimum Pitch"], soundParams["Maximum Pitch"])
});
this._soundWait = soundParams["Playback Frequency"];
}
}
};
})();