SC2Mapster Forums

Development > Triggers

How do I make an action that has a certain % chance of triggering?

  • 7 posts
    #1 Dec 11, 2012 at 18:25 UTC - 0 likes

    Hi guys, I'm trying to put in an action where there's like 2% chance a certain sound file is played in the middle of a trigger, and I basically have no idea as to how I should make this "chance" condition. I'd appreciate any help on the matter. Thanks in advance!

    #2 Dec 11, 2012 at 18:33 UTC - 0 likes

    @DeepCover187: Go You have to add an If, and in the conditions you do a simple math to compare a fixed number with a random Int. You can define the fixed number and interval of variation of your random Int to achieve the % you want. Making the interval be 0 ~ 100 makes it very easy to select % for any random action you want.

    #3 Dec 13, 2012 at 05:56 UTC - 0 likes

    @DeepCover187:

    Here's how I would do something like this.

    Initialization
        Events
            Game - Map initialization
        Local Variables
            Interger = 0 <Integer>
        Conditions
        Actions
            Variable - Set Interger = (Random integer between 0 and 100)
            General - If (Conditions) then do (Actions) else do (Actions)
                If
                    Interger == 1
                Then
                    Sound - Play Sound Link for (All players) (at 100.0% volume, skip the first 0.0 seconds)
                Else

    http://www.sc2pod.com/achievement.php?id=13914

    #4 Dec 13, 2012 at 15:27 UTC - 0 likes
    Quote from Projekton: Go

    @DeepCover187:

    Here's how I would do something like this.

    Initialization Events Game - Map initialization Local Variables Interger = 0 <Integer> Conditions Actions Variable - Set Interger = (Random integer between 0 and 100) General - If (Conditions) then do (Actions) else do (Actions) If Interger == 1 Then Sound - Play Sound Link for (All players) (at 100.0% volume, skip the first 0.0 seconds) Else

    For a 2% chance, you could do the condition "If Integer <= 1"

    My Projects:
    Malum Ruina: SC2Mapster
    Eternal Exile: SC2Mapster
    Spine Crawler Madness: SC2Mapster
    Xeno Crisis: SC2Mapster

    #5 Dec 13, 2012 at 16:35 UTC - 0 likes
    Quote from BasharTeg: Go

    @Projekton: Go

    For a 2% chance, you could do the condition "If Integer <= 1"

    Or instead of that, you could make the variable be from 0 to 50, that and make it only work if the variable is 1, it would still be a 2% chance.

    Assistant Team Leader of "Generic Code" and User of the All-Mighty Data Editor.

    My Amazing Cutscenes

    #6 Dec 14, 2012 at 09:09 UTC - 0 likes

    Thanks a ton guys, got it to work now! :)

    #7 Dec 14, 2012 at 18:18 UTC - 0 likes

    @DeepCover187:

    Awesome, glad to help. :)

  • 7 posts

You must login to post a comment. Don't have an account? Register to get one!