Jump to content

PlaySound if Equals specific value


Recommended Posts

Hi all,

 

I am trying to get a buff to play a sound when a specific number is output from the CraftingOutputCount value.

 

For example I have slot machine on my mod that uses buffs to generate odds/wins etc

 

First it generates a random number:

<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="$machineoutput" operation="setvalue" value="randomint(1,5)"/>


This cvar ticks constantly in the background...

 

Whenever a player crafts an item (read places a bet), whichever number this cvar is on at that precise moment determines the odds of winning.

 

If the number is between 1 and 4, the player loses, if it is on 5, the player wins.

 

It is basically a 1 in 5 chance of winning.

 

To limit losses I have included the following bit of code:

<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="$machineoutput" operation="setvalue" value="0.1"><!-- If random number is less than/equal to 40, set it to 10% of stake: 0.1 -->
					<requirement name="CVarCompare" cvar="$machineoutput" operation="LTE" value="4"/><!-- value must match with multiplication range-->
				</triggered_effect>


Which basically says if the number is between 1 and 4 give them 10% of their original stake back.

 

And then the output is as follows:

<passive_effect name="CraftingOutputCount" operation="perc_set" value="@$machineoutput" tags="SlotOdds1"/>

 

This works 100%. No issues.

 

What I would like to also include to enhance the gameplay is for a sound to play if the player wins.

 

Since CraftingOutputCount is the only way of knowing if the player has won or not I have tried using the following:

<triggered_effect trigger="onSelfBuffUpdate" action="PlaySound" sound="Slot_Open" play_in_head="true">
					<requirement name="CraftingOutputCount" cvar="$machineoutput" operation="Equals" value="5"/>
				</triggered_effect>

 

However, nothing works.

 

Calling on the cvar continually plays the sound over and over again since it is always ticking in the background.

 

I can't think of any other way to achieve this?

 

By calling on the values of CraftingOutputCount is it possible to add a buff with a sound?

 

Any help or suggestions appreciated

Link to comment
Share on other sites

I have isolated the effect groups for losses and wins:

 

<effect_group>
				<passive_effect name="CraftingOutputCount" operation="perc_set" value="@$machineoutput" tags="SlotOdds1">
					<requirement name="CVarCompare" cvar="$machineoutput" operation="LTE" value="4"/>
				</passive_effect>
			</effect_group>
				
			<effect_group><!-- WINS -->
				<passive_effect name="CraftingOutputCount" operation="perc_set" value="@$machineoutput" tags="SlotOdds1">
					<requirement name="CVarCompare" cvar="$machineoutput" operation="Equals" value="5"/>
                  	<!- possible to add a trigger in this effect group anywhere for sound? or to trigger a second buff? -->
				</passive_effect>
			</effect_group>

 

Code works 100%, just need to figure out how to implement the sound effect into the WINS group - maybe by triggering a second buff containing the PlaySound action?

 

I have been tweaking and testing since my original post 4 hours ago with no success haha

Link to comment
Share on other sites

I have created a second buff with the PlaySound trigger inside, tested it working on something else, but can't figure out how to link it to the code above...

 

I have tried a new effect group:

 


			<effect_group>
				<triggered_effect trigger="onSelfBuffUpdate" action="AddBuff" buff="buffBigWin">
					<requirement name="CVarCompare" cvar="$machineoutput" operation="Equals" value="5"/>
				</triggered_effect>
			</effect_group>

 

But that fires the buff constantly 🙃

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...