VWS Slot Machine System [Full Script]
You need to own this item to leave a rating.
VWS SlotMachine System FULL version - Script
Current Version: r172, updated 05-23-2025
~~~~~ ~~~~~ ~~~~~
The VWS SlotMachineSystem script contains 4 subscripts:
1) The SlotMachine script - This is the script that comes with the default template, it goes directly on the group that contains each slot machines needed components
2) The SlotController script - This script allows more control of players, with a slot controller in the scene, your slot machines automatically will no longer be in local mode, and players will only be able to be playing one at a time. Their balances will also be kept short or long term, depending on the settings selected.
3) The SlotModInteraction script - This is just like the default Sansar Interaction.cs, but it only allows interactions to go thru when the clickee is the scene owner or someone that has had their handle added to the Moderators list on your SlotController in the scene
4) The SlotPrizeRedemption script - Allows you to create store areas, with clickable mesh/volumes in the scene where players can purchase store items (hidden ones work best), with their points earned from the slot system -- only works with PersistenceMode enabled
Now that we have an overview of each section of this script, we will give some details for each below...
##### SlotMachine script #####
The slot machine system supports one pay line only, thus the product identifier 'type1'
Each machine uses only script per copy of it in the scene, it does not need any custom group names or anything adjusted to duplicate in the scene, just dupe it and go!
The player can toggle between bet-amounts at runtime, but not in the middle of any bonus games!
While this script can only be officially supported by us using official VWS slot reel objects such as the ones that come with our machine template(s), as they have to be in a very specific format/configuration. However, if you are super interested in making your own, we are happy to provide you with a sample fbx and its details -- see our GitHub repo with extra files for this system.
~~~~~
Due to product description size limit of 10,000 characters, you will need to check our other product listing of the 'Customizable Slot Machine Template' to see all of full property descriptions for the SlotMachine script itself.
##### SlotController script #####
This is a preconfigured SlotController for the VWS Slot Machine template/system.
You only need one in the scene, it will work with all of the slot machines in the scene.
This one offers a persistence mode, that can be enabled in editor as well as at runtime via a chat command. If you use persistence mode, please set a long, unique string for the DataStoreId, as this is where all of your players balances will be stored over time.
With persistence mode off, players balances will still carry from slot machine to slot machine, but once the scene is reset/restarted those balances will go away. With persistence mode on, they are retained.
Mostly, the slot controller retains player balances across machines, it also prevents players from playing more than one machine at a time when one is present in the scene.
You cannot have more than one vws slot controller in the scene at a time, if you do, an error message will be presented in the Sansar DebugConsole, as well as the activity light on the mesh itself will turn emissive RED when you do this, and all slot controllers in the scene will end up disabled at runtime. Please do not put more than one in the scene, this failsafe has been added to prevent erroneous behavior with conflicting slot controllers in the scene.
The SlotController has a few chat commands, that are mostly self explanatory:
Add/remove a user as a moderator at runtime, you will still need to update your list on the slot controller script in editor to make the changes permanent, but this is useful for on-the-fly changes:
/addmod username-1234
/removemod username-1234
This turns wallet (points) persistence on or off at runtime, it is recommended to send the force cashout event to the SlotController after switching this mode:
/persistence on
/persistence off
Get or set a users wallet point balance (override):
/getpoints username-1234
/setpoints username-1234 500
Sign a specific user off their machine
/signoff username-1234
~~~~~
Provided below are all the various script properties for our SlotMachine script that is provided on this template, that will further explain the devices potential functionalities:
BootupDelay - Initialization Delay, this is recommended to keep the script running normally; Recommended value: 4;
DebugMode- When enabled, lots of debug info, including any configuration errors, for initialization and runtime will be shown in the Sansar Debug Console; Please do not leave enabled for production usage; DefaultValue: false
BlinkActivityLight: When enabled, this will flash a 'led light' mesh on the SlotController; DefaultValue: false
ActivityLightMaterialIndex - When BlinkActivityLight is enabled, this value must be set to the Material Index # of the activity LED light on the mesh this script is on; IsScriptable must be set to true on the mesh for this to work
ActivityLightDelay - How long the activity light stays on for when activated each time; Recommended value: 0.25 (250ms); DefaultValue: 0.25f
ShowErrorLights - When enabled, just like BlinkActivityLight, the same light indicator mesh will be used, and turned red, in the event of a fatal initialization error/issue due to mis-configuration; DefaultValue: false
EnableEvent - When this event is received, all slot machines will be enabled and available for use; DefaultValue: 'enable_all_slots'
DisableEvent - When this event is received, all slot machines will be disabled and not available for use until re-enabled; DefaultValue: 'disable_all_slots'
ResetBalance - The balance to set each users temporary wallet to when the ResetAllUserBalances event is received -- does not affect persistent wallet values for players, only works when UsePersistence is disabled in the editor or when disabled at runtime; DefaultValue: 100
ResetAllUserBalances - When this event is received, all user balances are reset to the 'ResetBalance', see tooltip on 'ResetBalance' for more info"; DefaultValue: 'resetbalances'
Group - The event group for the SlotController -- only used for receiving the custom events available on this script, not slot communications -- you only NEED and can only HAVE one slot controller per scene; DefaultValue: 'slotcontroller'
Moderators - Add moderators full handles to this list, and they will have access to any buttons that are using the SlotModInteraction script (like the example buttons that come with this controller), as well as chat commands for the SlotController/machines; They will also be able to force cashout/spin any other players machine at runtime, wield with caution!
EnablePersistence - The starting value for enabling/disabling persistence on player wallets for points when the scene starts, this can be toggled at runtime via the two events below; DefaultValue: false
DataStoreId - Unique key for your data store -- for storing user wallet balances
PersistenceEnableEvent / PersistenceDisableEvent - When this event is received, persistence on player wallets for points will be enabled/disabled; It is recommended to also send the forced cashout event after changing this at runtime;
##### SlotModInteraction script #####
This is a modified version of the Interaction.cs script from the Sansar ScriptAPI Examples folder, it has extra code added to it so that it asks for permission from any VWS SlotController (if one is in the scene), for that user, before allowing the interaction to go through or not. This script is useful with the VWS SlotSystem for buttons you might put in the scene that might possibly send events to the slot controller, or anything you wish really.. Only the scene-owner or those added to the moderator list can actually use the interaction on them at runtime.
##### SlotPrizeRedemption script #####
The PrizeRedemption script for the VWS SlotMachine System, is an add-on script that you can use many times in your scene. You can put this script on a group of objects (or any other way you like), and then slot the volume for each one to the 'Product Volumes' list, as well as provide the store GUID for each store item, and this makes each one clickable at runtime.
These interactions allows players to redeem points from persistent datastore, but only works if you have this option enabled via your SlotController in the scene, and both need to share the same unique DataStoreId string.
Once a player has clicked a prize, and agreed to exchange X number of points (defined for each, in the PrizePointsPrices list), it will take these points away from their balance and show the store listing in a UI store listing dialog that allows them to grab the item.
The only drawback to this, is the ScriptAPI currently does not allow us to check if the player actually already owns that store item via GUID -- but if they ever add it, this script will be updated and available for re-delivery with this safety check added. But for now, the drawback is, if they don't click 'Get Item', they loose the chance to ever get it again.
None the less, this is still a pretty neat add-on that allows you setup an actual prize shop for your experience, using actual store items (hidden store items work the best), as prizes they can get in exchange for points.
~~~~~ ~~~~~ ~~~~~
You can view an example of this mega script in action at the demo world here: https://atlas.sansar.com/experiences/freelight-1030/casino-games