Как создать счетчик смертей со звуковым эффектом в чате Twitch
Этот пример скрипта прослушивает увеличение (или уменьшение) счетчика смертей и воспроизводит звуковой эффект, прослушивая определенные команды чата Twitch. Счетчик смертей сохраняется в файле, чтобы OBS Studio могла легко отображать его в стриме.
Посмотрите видео
Пример скрипта
import com.squiso.*;
import com.squiso.exception.*;
import com.squiso.scripting.*;
import com.squiso.scripting.data.*;
import com.squiso.keyboard.*;
import com.squiso.twitch.*;
import com.squiso.datatypes.*;
import com.squiso.utils.*;
import com.squiso.sysinfo.*;
// Important - Please do not change the row below - otherwise you will get a compilation error!
public class Script_Example extends SquisoScript {
    
    // Create a death counter integer variable, assign it to 0 as default
    SquisoInteger deathCounter = new SquisoInteger(0);
    // When the script is initiated
    @Override
    public void onInitiated(API api) throws SquisoException {
        // If the file "death_counter_value.txt" exists
        if (FileUtil.exists("death_counter_value.txt")) {
            // Get the numeric value from the file "counter.txt"
            deathCounter = SquisoInteger.readFromFile("death_counter_value.txt");
        }
    }
    @Override
    public void onTwitchChatMessage(OnTwitchChatMessageData data, API api) throws SquisoException {
        // If the user is NOT the broadcaster and is NOT a moderator
        // End here by doing a return
        if (!data.isUserBroadcaster() && !data.isUserModerator()) {
            return;
        }
        // If the message is "!dc" or "!dc up"
        if (data.getMessageText().equals("!dc") || data.getMessageText().equals("!dc up")) {
            // Increase the counter
            deathCounter.increment();
            // Play a dramatic death sound
            api.playAudio("mario_death.mp3");
        }
        // If the message is "!dc down"
        if (data.getMessageText().equals("!dc down")) {
            // Decrease the counter
            deathCounter.decrement();
        }
        // Write the numeric file in case we restart Squiso
        deathCounter.writeToFile("death_counter_value.txt");
        
        // Compose what should be in the file for OBS Studio
        SquisoString contents = new SquisoString("Deaths: " + deathCounter);
        // Write the file that is displayed to OBS Studio
        contents.writeToFile("death_counter_obs.txt");
    }
}
    