Tutorials

Streamer.bot

The following tutorials assume you imported the Streamer.bot code from the setup provided in the StreamSocket configuration.

Switchboard

Example Streamer.bot import code

Assume you want a category where only one event can be active at a time. For example, you have a color source in OBS, and want viewers to select the color of it. It wouldn’t make sense to allow viewers to select the same color multiple times.

Example Switchboard in StreamSocket

So, how do we make sure the current background color is locked, while all others are active and can be selected? With StreamSocket and Streamer.bot, such an implementation is easy.

  1. Add a new event for each color. In our example, we are going to use the event IDs “background_black”, “background_red” and “background_blue”.

  2. Set a maximum limit of 1 for each event in the advanced options.

  3. Add the corresponding actions in Streamer.bot:

List of background events

  1. In OBS, create a color source and set it to a default value.

  2. For each action in Streamer.bot, add a sub-action “OBS Set Color Source Color” to the corresponding color.

  3. You should already be able to test whether the events work by using the “Test Event” button in the configuration toolbar of each event.

  4. We need to set a global variable to the executed event id, so we know which event to reset should another background color be redeemed.

    1. We need to save the current event ID to an argument, so we can use it later.

      Add a new sub-action Core - Globals - Global (Get) and transfer the non-persisted global variable StreamSocketEventId to destination variable StreamSocketEventId (Yes, just duplicate the name).

    2. Retrieve the previous BackgroundEventId to reset it.

      Add a new sub-action Core - Globals - Global (Get) and transfer the variable BackgroundEventId to argument StreamSocketEvents.

    3. Add a new sub-action Core - C# - Execute Method and select the method SendNotificationEventReset from the StreamSocket Code Library.

      The method uses the argument StreamSocketEvents to decide which events to reset.

    4. Now, we save the background event_id to a global variable.

      Add a new sub-action Core - Globals - Global (Set) and set the non-persisted variable BackgroundEventId to argument StreamSocketEventId

    5. Make sure you place the sub-action where you set BackgroundEventId last in the list of sub-actions.

    6. Put all the sub-actions besides the OBS one into a group and copy & paste it to the other background actions.

  5. Each event should have sub-actions that look like this:

Example sub-actions

  1. You are done! You can test the result by testing it with the panel/component provided to viewers (test events from the configuration ignore limits and locks). The limit makes sure the event is locked after it is redeemed by a viewer, and the logic provided by Streamer.bot resets the previous event.

Custom Point System

Example Streamer.bot import code

StreamSocket only allows you to use bits for redeeming events by default. Sadly, extensions do not have access to channel points. What if you want to use your own custom point system?

We can combine StreamSocket with Points System (Core) to provide such functionality.

  1. Make sure you imported and setup Points System (Core) according to the link.

  2. Create a new event for redeeming the current points (like get_points). Set the global duration to 0, disable write in chat, and enable “use custom redeem response” in the advanced options.

  3. Create the corresponding action in Streamer.bot (“Event_get_points”).

  4. Add the following sub-actions:

    1. Get the (non-persisted) global variable StreamSocketUserDisplayName and save it to StreamSocketUserDisplayName (Core - Globals - Global (Get)).

    2. Add the sub-action Twitch - User - Get User Info for Target, set source type to “Variable” and Variable to StreamSocketUserDisplayName.

    3. Add the sub-action Core - Globals - Global (Get), set source to “User (target)”, variable name to points and destination variable to pointsArgs with default of 0.

    4. Combine the previous three sub actions into a group, since we need them later again.

    5. Add the sub-action Core - Arguments - Set Argument, set variable name to StreamSocketResponse, and the value to the message **%StreamSocketUserDisplayName%**, you have %pointsArgs% points..

    6. Add the sub-action Core - C# - Execute Method and select method SendResponseEventData from the StreamSocket Code Library.

Example get_points

  1. You should now be able to redeem the event and get a message with your current point amount, all within the extension.

  2. Next, we add an example event that can only be executed successfully if the user has enough points. Similarly to the first event, we set global duration to 0, disable write in chat and use a custom redeem response.

  3. Create the corresponding action in Streamer.bot. We also need two additional events - one for successful redeem and one for an unsuccessful one (not enough points).

Example get_points

  1. In the default action (not fail or success), we add the following sub actions:

    1. Add the group we created in the previous action here as well.

    2. Add a new sub-action Core - Logic - If/Else. Set the variable to pointArgs, the operator to “less than” and the value to however much you want the event to cost.

      Set “do action” to the fail action, then break. In the else condition, set the do action to the success action, then continue.

    3. Add a final sub-action Core - Globals - Global (Set), set source to “User (target)”, variable name to points and decrement it by the value you defined in the if/else condition.

Example get_points

  1. In the “fail” action:

    1. Add a sub-action Core - Arguments - Set Argument and set variable StreamSocketResponse to a message like “You don’t have enough points for the event.”

    2. Add the sub-action Core - C# - Execute Method and select method SendResponseEventData from the StreamSocket Code Library.

    3. You can always add more information to the response message, like the display name of the user. Just follow the same approach that we used for the Event_get_points action.

Example get_points

  1. In the “success action”

    1. Add a sub-action Core - Arguments - Set Argument and set variable StreamSocketResponse to a message like “You successfully redeemed the event.”

    2. (Optional) Add a sub-action Core - Arguments - Set Argument and set variable StreamSocketUseDurationGlobal to how long you want to lock the extension in milliseconds.

    3. Add the sub-action Core - C# - Execute Method and select method SendResponseEventData from the StreamSocket Code Library.

    4. Add any further sub-actions you want to add for a successful redeem, like play sound, switch scenes etc.

Example get_points

  1. Users should now be able to redeem the event if they have enough points (and get their points subtracted), while those without enough points receive an error message.