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.
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.
-
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”.
-
Set a maximum limit of 1 for each event in the advanced options.
-
Add the corresponding actions in Streamer.bot:
-
In OBS, create a color source and set it to a default value.
-
For each action in Streamer.bot, add a sub-action “OBS Set Color Source Color” to the corresponding color.
-
You should already be able to test whether the events work by using the “Test Event” button in the configuration toolbar of each event.
-
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.
-
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 variableStreamSocketEventId
to destination variableStreamSocketEventId
(Yes, just duplicate the name). -
Retrieve the previous BackgroundEventId to reset it.
Add a new sub-action
Core - Globals - Global (Get)
and transfer the variableBackgroundEventId
to argumentStreamSocketEvents
. -
Add a new sub-action
Core - C# - Execute Method
and select the methodSendNotificationEventReset
from the StreamSocket Code Library.The method uses the argument
StreamSocketEvents
to decide which events to reset. -
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 variableBackgroundEventId
to argumentStreamSocketEventId
-
Make sure you place the sub-action where you set
BackgroundEventId
last in the list of sub-actions. -
Put all the sub-actions besides the OBS one into a group and copy & paste it to the other background actions.
-
-
Each event should have sub-actions that look like this:
- 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.
-
Make sure you imported and setup Points System (Core) according to the link.
-
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. -
Create the corresponding action in Streamer.bot (“Event_get_points”).
-
Add the following sub-actions:
-
Get the (non-persisted) global variable
StreamSocketUserDisplayName
and save it toStreamSocketUserDisplayName
(Core - Globals - Global (Get)
). -
Add the sub-action
Twitch - User - Get User Info for Target
, set source type to “Variable” and Variable toStreamSocketUserDisplayName
. -
Add the sub-action
Core - Globals - Global (Get)
, set source to “User (target)”, variable name topoints
and destination variable topointsArgs
with default of 0. -
Combine the previous three sub actions into a group, since we need them later again.
-
Add the sub-action
Core - Arguments - Set Argument
, set variable name toStreamSocketResponse
, and the value to the message**%StreamSocketUserDisplayName%**, you have %pointsArgs% points.
. -
Add the sub-action
Core - C# - Execute Method
and select methodSendResponseEventData
from the StreamSocket Code Library.
-
-
You should now be able to redeem the event and get a message with your current point amount, all within the extension.
-
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.
-
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).
-
In the default action (not fail or success), we add the following sub actions:
-
Add the group we created in the previous action here as well.
-
Add a new sub-action
Core - Logic - If/Else
. Set the variable topointArgs
, 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.
-
Add a final sub-action
Core - Globals - Global (Set)
, set source to “User (target)”, variable name topoints
and decrement it by the value you defined in the if/else condition.
-
-
In the “fail” action:
-
Add a sub-action
Core - Arguments - Set Argument
and set variableStreamSocketResponse
to a message like “You don’t have enough points for the event.” -
Add the sub-action
Core - C# - Execute Method
and select methodSendResponseEventData
from the StreamSocket Code Library. -
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.
-
-
In the “success action”
-
Add a sub-action
Core - Arguments - Set Argument
and set variableStreamSocketResponse
to a message like “You successfully redeemed the event.” -
(Optional) Add a sub-action
Core - Arguments - Set Argument
and set variableStreamSocketUseDurationGlobal
to how long you want to lock the extension in milliseconds. -
Add the sub-action
Core - C# - Execute Method
and select methodSendResponseEventData
from the StreamSocket Code Library. -
Add any further sub-actions you want to add for a successful redeem, like play sound, switch scenes etc.
-
- 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.