Hello, guys, I need your help.
I tried to make script for several LLM NPC actions, that were parsed from the output. All works good, but sound effect plays only from the first executed command. I need sounds from all commands to be played sequentially.
Here is my script:
var commandsArray = JSON.parse($gameVariables.value(8));
var npcInventory = $gameVariables.value(5);
function executeCommand(command) {
return new Promise(function (resolve) {
switch (command.action) {
case 'givePlayer':
var amount = command.quantity;
$gameParty.gainGold(amount);
npcInventory["gold"] -= amount;
resolve();
break;
case 'restrainPlayer':
$gameParty.gainItem($dataWeapons[49], 1);
$gameActors.actor(9).changeEquip(0, $dataWeapons[49]);
npcInventory["handcuffs"]--;
AudioManager.playBgs({ name: 'Handcuffs', volume: 90, pitch: 100, pan: 0 });
var timerDuration = 3000;
setTimeout(function () {
AudioManager.stopBgs();
resolve();
}, timerDuration);
break;
case 'shoutPlayer':
var amount = command.quantity * 800;
AudioManager.playBgs({ name: 'shout_09', volume: 90, pitch: 100, pan: 0 });
var timerDuration = amount;
setTimeout(function () {
AudioManager.stopBgs();
resolve();
}, timerDuration);
break;
default:
resolve(); // Если необходимо что-то по умолчанию
break;
}
});
}
function executeCommandsSequentially(commands) {
var index = 0;
function executeNextCommand() {
if (index < commands.length) {
var command = commands[index];
executeCommand(command).then(function () {
index++;
setTimeout(function () {
executeNextCommand();
}, command.timerDuration + 500);
});
} else {
$gameVariables.setValue(8, JSON.stringify([])); // Очищаем массив команд
$gameVariables.setValue(6, 0);
}
}
executeNextCommand();
}
executeCommandsSequentially(commandsArray);
I tried to make script for several LLM NPC actions, that were parsed from the output. All works good, but sound effect plays only from the first executed command. I need sounds from all commands to be played sequentially.
Here is my script:
var commandsArray = JSON.parse($gameVariables.value(8));
var npcInventory = $gameVariables.value(5);
function executeCommand(command) {
return new Promise(function (resolve) {
switch (command.action) {
case 'givePlayer':
var amount = command.quantity;
$gameParty.gainGold(amount);
npcInventory["gold"] -= amount;
resolve();
break;
case 'restrainPlayer':
$gameParty.gainItem($dataWeapons[49], 1);
$gameActors.actor(9).changeEquip(0, $dataWeapons[49]);
npcInventory["handcuffs"]--;
AudioManager.playBgs({ name: 'Handcuffs', volume: 90, pitch: 100, pan: 0 });
var timerDuration = 3000;
setTimeout(function () {
AudioManager.stopBgs();
resolve();
}, timerDuration);
break;
case 'shoutPlayer':
var amount = command.quantity * 800;
AudioManager.playBgs({ name: 'shout_09', volume: 90, pitch: 100, pan: 0 });
var timerDuration = amount;
setTimeout(function () {
AudioManager.stopBgs();
resolve();
}, timerDuration);
break;
default:
resolve(); // Если необходимо что-то по умолчанию
break;
}
});
}
function executeCommandsSequentially(commands) {
var index = 0;
function executeNextCommand() {
if (index < commands.length) {
var command = commands[index];
executeCommand(command).then(function () {
index++;
setTimeout(function () {
executeNextCommand();
}, command.timerDuration + 500);
});
} else {
$gameVariables.setValue(8, JSON.stringify([])); // Очищаем массив команд
$gameVariables.setValue(6, 0);
}
}
executeNextCommand();
}
executeCommandsSequentially(commandsArray);