効果音追加
by
cutfloss
2 hours ago [2026/05/07 23:23:57]
キル時、ゲーム開始・終了時などに短い効果音が鳴るようになるぞっ
@@ -8,7 +8,8 @@
/* 1. 音源定義とプリロード */
const S_URL = {
s: 'https://actions.google.com/sounds/v1/alarms/beep_short.ogg',
- k: 'https://soundeffect-lab.info/sound/various/mp3/glass-break2.mp3',
+ /* 正しいURLに修正済み */
+ k: 'https://soundeffect-lab.info/sound/battle/mp3/glass-break2.mp3',
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'
};
@@ -16,10 +17,11 @@
const S = {};
for (let k in S_URL) {
S[k] = new Audio(S_URL[k]);
+ /* 外部サイトの音源を許可する設定 */
+ S[k].crossOrigin = 'anonymous';
S[k].preload = 'auto';
}
- /* 再生関数(ラグ対策:0秒に戻して再生) */
const play = (a, dur) => {
if (!a) return;
a.volume = 0.5;
@@ -28,11 +30,11 @@
if (dur) setTimeout(() => { a.pause(); a.currentTime = 0; }, dur);
};
- /* 2. キル音の判定(addKillFeedを監視) [cite: 397] */
+ /* 2. キル音の判定(メッセージ監視) [cite: 397] */
const _ok = window.addKillFeed;
window.addKillFeed = (msg) => {
const me = players.find(p => p.id === myId);
- /* メッセージに自分の名前が含まれていれば再生 [cite: 528, 895] */
+ /* [cite: 528, 895] 名前にタグが付くことを考慮し includes で判定 */
if (me && me.name && msg.includes(me.name)) {
play(S.k);
}
@@ -45,8 +47,14 @@
window.loop = () => {
const me = players.find(p => p.id === myId);
if (me) {
- if (last !== 'active' && me.state === 'active') play(S.s);
- else if (last === 'active' && (me.state === 'dead' || me.state === 'ghost')) play(S.d);
+ /* 復活・スポーン */
+ if (last !== 'active' && me.state === 'active') {
+ play(S.s);
+ }
+ /* 死亡・ゴースト(判定を「active以外」に広げて確実に捉える) */
+ else if (last === 'active' && (me.state === 'dead' || me.state === 'ghost' || me.isGhost)) {
+ play(S.d);
+ }
last = me.state;
}
return _ol();
@@ -55,9 +63,9 @@
/* 4. ラウンド終了音 [cite: 411, 453] */
const _or = window.showResultScreen;
window.showResultScreen = function() {
- play(S.e, 3000); /* 3秒でカット */
+ play(S.e, 3000);
return _or.apply(this, arguments);
};
- alert('【サウンドパッチ:キル音復活版】\n自分の名前を含むキルメッセージに反応します。');
+ alert('【サウンドパッチ:完全版】\nURL修正と判定強化を適用しました。');
})();
/*
* @title 効果音追加
* @description キル時、ゲーム開始・終了時などに短い効果音が鳴るようになるぞっ
* @private
*/
javascript:(function(){
const d=document;
/* 1. 音源定義とプリロード */
const S_URL = {
s: 'https://actions.google.com/sounds/v1/alarms/beep_short.ogg',
/* 正しいURLに修正済み */
k: 'https://soundeffect-lab.info/sound/battle/mp3/glass-break2.mp3',
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 k in S_URL) {
S[k] = new Audio(S_URL[k]);
/* 外部サイトの音源を許可する設定 */
S[k].crossOrigin = 'anonymous';
S[k].preload = 'auto';
}
const play = (a, dur) => {
if (!a) return;
a.volume = 0.5;
a.currentTime = 0;
a.play().catch(()=>{});
if (dur) setTimeout(() => { a.pause(); a.currentTime = 0; }, dur);
};
/* 2. キル音の判定(メッセージ監視) [cite: 397] */
const _ok = window.addKillFeed;
window.addKillFeed = (msg) => {
const me = players.find(p => p.id === myId);
/* [cite: 528, 895] 名前にタグが付くことを考慮し includes で判定 */
if (me && me.name && msg.includes(me.name)) {
play(S.k);
}
return _ok(msg);
};
/* 3. スタート・復活・死亡の監視 [cite: 686-691] */
let last = 'waiting';
const _ol = window.loop;
window.loop = () => {
const me = players.find(p => p.id === myId);
if (me) {
/* 復活・スポーン */
if (last !== 'active' && me.state === 'active') {
play(S.s);
}
/* 死亡・ゴースト(判定を「active以外」に広げて確実に捉える) */
else if (last === 'active' && (me.state === 'dead' || me.state === 'ghost' || me.isGhost)) {
play(S.d);
}
last = me.state;
}
return _ol();
};
/* 4. ラウンド終了音 [cite: 411, 453] */
const _or = window.showResultScreen;
window.showResultScreen = function() {
play(S.e, 3000);
return _or.apply(this, arguments);
};
alert('【サウンドパッチ:完全版】\nURL修正と判定強化を適用しました。');
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。