効果音追加
by
cutfloss
2 hours ago [2026/05/07 23:23:57]
キル時、ゲーム開始・終了時などに短い効果音が鳴るようになるぞっ
@@ -4,47 +4,70 @@
* @private
*/
javascript:(function(){
- const S = {
+ /* 1. 音源定義とプリロード */
+ const S_URL = {
s: 'https://actions.google.com/sounds/v1/alarms/beep_short.ogg',
k: 'https://actions.google.com/sounds/v1/cartoon/pop.ogg',
d: 'https://actions.google.com/sounds/v1/science_fiction/glitch_low_power.ogg',
e: 'https://actions.google.com/sounds/v1/alarms/digital_watch_alarm_long.ogg'
};
- const play = (u) => { const a = new Audio(u); a.volume = 0.5; a.play().catch(()=>{}); };
- /* 1. キル音の判定(自分の名前が含まれるメッセージを監視) */
- const _ok = window.addKillFeed;
- window.addKillFeed = (m) => {
- const me = players.find(p => p.id === myId);
- if (me && me.name && m.includes(me.name)) play(S.k);
- return _ok(m);
+ const S = {};
+ for (let key in S_URL) {
+ S[key] = new Audio(S_URL[key]);
+ S[key].preload = 'auto'; /* 事前にダウンロードしてメモリに置く */
+ }
+
+ /* 再生関数:ラグを消すために currentTime = 0 を指定 */
+ const play = (audio, duration) => {
+ if (!audio) return;
+ audio.volume = 0.5;
+ audio.currentTime = 0; /* 再生位置を瞬時に頭に戻す */
+ audio.play().catch(()=>{});
+
+ /* 音の長さを制限する場合(ミリ秒で指定) */
+ if (duration) {
+ setTimeout(() => {
+ audio.pause();
+ audio.currentTime = 0;
+ }, duration);
+ }
};
- /* 2. スタート・死亡・復活の監視 */
- let last = 'waiting';
+ /* 2. キル音の最速化(キルフィードではなく、killsの数値を監視) */
+ let lastKills = 0;
const _ol = window.loop;
+ let lastState = 'waiting';
+
window.loop = () => {
const me = players.find(p => p.id === myId);
if (me) {
- /* waiting または dead から active になった瞬間に鳴らす */
- if (last !== 'active' && me.state === 'active') {
+ /* キル数の増加を検知(フィード表示より早い) */
+ const currentKills = me.kills || 0;
+ if (currentKills > lastKills) {
+ play(S.k);
+ lastKills = currentKills;
+ }
+
+ /* 復活・スタート */
+ if (lastState !== 'active' && me.state === 'active') {
play(S.s);
}
- /* 生存から死亡(またはゴースト)になった瞬間に鳴らす */
- else if (last === 'active' && (me.state === 'dead' || me.state === 'ghost')) {
+ /* 死亡 */
+ else if (lastState === 'active' && (me.state === 'dead' || me.state === 'ghost')) {
play(S.d);
}
- last = me.state;
+ lastState = me.state;
}
return _ol();
};
- /* 3. リザルト音 */
+ /* 3. リザルト音(長さを3000ms = 3秒に制限) */
const _or = window.showResultScreen;
window.showResultScreen = function() {
- play(S.e);
+ play(S.e, 3000); /* 3秒経ったら強制終了 */
return _or.apply(this, arguments);
};
- alert('【サウンドパッチ改】\nリスポーン・キル音を最適化しました。');
+ alert('【サウンドパッチ・プロ】\n・低遅延ロード完了\n・キル音最速化\n・エンド音長調整済み');
})();
/*
* @title 効果音追加
* @description キル時、ゲーム開始・終了時などに短い効果音が鳴るようになるぞっ
* @private
*/
javascript:(function(){
/* 1. 音源定義とプリロード */
const S_URL = {
s: 'https://actions.google.com/sounds/v1/alarms/beep_short.ogg',
k: 'https://actions.google.com/sounds/v1/cartoon/pop.ogg',
d: 'https://actions.google.com/sounds/v1/science_fiction/glitch_low_power.ogg',
e: 'https://actions.google.com/sounds/v1/alarms/digital_watch_alarm_long.ogg'
};
const S = {};
for (let key in S_URL) {
S[key] = new Audio(S_URL[key]);
S[key].preload = 'auto'; /* 事前にダウンロードしてメモリに置く */
}
/* 再生関数:ラグを消すために currentTime = 0 を指定 */
const play = (audio, duration) => {
if (!audio) return;
audio.volume = 0.5;
audio.currentTime = 0; /* 再生位置を瞬時に頭に戻す */
audio.play().catch(()=>{});
/* 音の長さを制限する場合(ミリ秒で指定) */
if (duration) {
setTimeout(() => {
audio.pause();
audio.currentTime = 0;
}, duration);
}
};
/* 2. キル音の最速化(キルフィードではなく、killsの数値を監視) */
let lastKills = 0;
const _ol = window.loop;
let lastState = 'waiting';
window.loop = () => {
const me = players.find(p => p.id === myId);
if (me) {
/* キル数の増加を検知(フィード表示より早い) */
const currentKills = me.kills || 0;
if (currentKills > lastKills) {
play(S.k);
lastKills = currentKills;
}
/* 復活・スタート */
if (lastState !== 'active' && me.state === 'active') {
play(S.s);
}
/* 死亡 */
else if (lastState === 'active' && (me.state === 'dead' || me.state === 'ghost')) {
play(S.d);
}
lastState = me.state;
}
return _ol();
};
/* 3. リザルト音(長さを3000ms = 3秒に制限) */
const _or = window.showResultScreen;
window.showResultScreen = function() {
play(S.e, 3000); /* 3秒経ったら強制終了 */
return _or.apply(this, arguments);
};
alert('【サウンドパッチ・プロ】\n・低遅延ロード完了\n・キル音最速化\n・エンド音長調整済み');
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。