Jump to content

Script Magic effect to randomly play a different sound on each cast


morrowind1979

Recommended Posts

So as the title says I am trying to make a magic effect randomly play one of 3 different sounds each time it is cast. I am struggling with the random papyrus function. This is far as I can get but it isnt playing any sound when the spell is cast. Any help would be appreciated. Thanks:

Scriptname NSShadowFlareScript extends activemagiceffect  

Sound Property MSFS1  Auto  
Sound Property FSFS1  Auto  
Sound Property MSFS2  Auto  
Sound Property FSFS2  Auto 
Sound Property MSFS3  Auto  
Sound Property FSFS3  Auto 

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

int random = Utility.RandomInt()

		If (Game.GetPlayer().GetActorBase().GetSex() == 0)
			If random <= 33
				MSFS1.play(Game.GetPlayer())
			ElseIf random <= 67
				MSFS2.play(Game.GetPlayer())
			ElseIf random <= 100
				MSFS3.play(Game.GetPlayer())
			EndIf
		ElseIf (Game.GetPlayer().GetActorBase().GetSex() == 1)
			If random <= 33
				MSFS1.play(Game.GetPlayer())
			ElseIf random <= 67
				MSFS2.play(Game.GetPlayer())
			ElseIf random <= 100
				MSFS3.play(Game.GetPlayer())
			EndIf
		EndIf
EndEvent
Link to comment
Share on other sites

Not the random part, but I would drop an actor property with a PlayerRef and use that instead of all that Game.GetPlayer, as it will fire faster than having to reference the game script multiple times.

Everyone says that but in reality it actually makes no difference at all. You can use Game.GetPlayer() fine as many times as u like

Link to comment
Share on other sites

Finally got it working using the following script. The answer was staring me right in the face all I had to do was simplify the random utiliy:

Scriptname NSShadowFlareScript extends ReferenceAlias

Sound Property MSFS1  Auto  
Sound Property FSFS1  Auto  
Sound Property MSFS2  Auto  
Sound Property FSFS2  Auto 
Sound Property MSFS3  Auto  
Sound Property FSFS3  Auto 
SPELL Property SFS Auto
Actor Property PlayerRef Auto

Event OnSpellCast(Form akSpell)

int random = Utility.RandomInt(0,2)

	If akSpell == SFS
		If (PlayerRef.GetActorBase().GetSex() == 0)
			If random == 0
				MSFS1.play(PlayerRef)
			ElseIf random == 1
				MSFS2.play(PlayerRef)
			ElseIf random == 2
				MSFS3.play(PlayerRef)
			EndIf
		ElseIf (PlayerRef.GetActorBase().GetSex() == 1)
			If random == 0
				FSFS1.play(PlayerRef)
			ElseIf random == 1
				FSFS2.play(PlayerRef)
			ElseIf random == 2
				FSFS3.play(PlayerRef)
			EndIf
		EndIf
	EndIf
EndEvent
Link to comment
Share on other sites

  • 2 years later...

Yep, two year old post. But it caught my eye on a late-night meandering...

 

Event OnSpellCast(Form akSpell)
    
    if akSpell == SFS
        string racket = "MSFS"
        if PlayerRef.GetActorBase().GetSex()
            racket = "FSFS"
        endIf
        racket += Utility.Randomint(1, 3) as string
        racket.Play(PlayerRef)
    endIf
endEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...