Local Player Sound upon Ability Cast

Status
Not open for further replies.
Level 7
Joined
Apr 18, 2010
Messages
102
Is there a way to create a sound for only 1 player when an ability is casted?

Trying to create a small system for it, (by system, I meant to just run a trigger instead of copy pasting its contents on every spell)

*On the Ability trigger*
>Set ABILITY_SOUND = some sound file
>set ABILITY_PLAYER = owner of casting unit
>Run "Play Sound" trigger

*On Play Sound trigger*
See image posted..
 

Attachments

  • Untitled.png
    Untitled.png
    8 KB · Views: 59
Level 7
Joined
Apr 18, 2010
Messages
102
Using GetLocalPlayer() to filter out the desired player in an if-then statement should do the trick.

JASS:
if GetLocalPlayer() == myPlayer then
    // Do your actions here...
endif

Hmm.. I cant seem to make it work

ABILITY TRiGGER: Theres an action there that:
Sets udg_ABILITY_Caster = Get Owner of casting unit
Sets ABILITY_SOUND = sound file
Runs Play Sound trigger


  • Kanshou Bakuya
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to EMIYA - 1
    • Actions
      • -------- ============== --------
      • -------- SET UP HASHTABLE --------
      • -------- ============== --------
      • Set SYSTEM_HANDLE = (Owner of (Triggering unit))
      • Set ABILITY_LOC[1] = (Position of (Triggering unit))
      • Unit - Create 1 Spell ID for (Owner of (Triggering unit)) at ABILITY_LOC[1] facing Default building facing degrees
      • Set ABILITY_HANDLE = (Last created unit)
      • Unit Group - Add (Last created unit) to ABILITY_ID[14]
      • Custom script: call RemoveLocation(udg_ABILITY_LOC[1])
      • -------- ============== --------
      • -------- END OF SETUP --------
      • -------- ============== --------
      • Set ABILITY_CASTER = (Triggering unit)
      • Set ABILITY_ANGLE = (Load 3 of (Key SYSTEM_HANDLE) from SYSTEM_HASHTABLE)
      • Unit - Pause ABILITY_CASTER
      • Unit - Order ABILITY_CASTER to Stop
      • Unit - Add CANNOT WALK to ABILITY_CASTER
      • Unit - Add CANNOT TURN to ABILITY_CASTER
      • Unit - Add CANNOT MOVE to ABILITY_CASTER
      • Set ABILITY_DAMAGE = 6.00
      • Set ABILITY_PLAYER = (Owner of ABILITY_CASTER)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of EMIYA - 1 for ABILITY_CASTER) Equal to 1
        • Then - Actions
          • Set ABILITY_SOUND = EMY_ATK_1 <gen>
          • Set ABILITY_RANGE = 100.00
          • Set ABILITY_ANIMATIONSPEED = 115.00
          • Set ABILITY_CASTTIME = 0.12
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of ALTERNATE ANIMATION for ABILITY_CASTER) Greater than 0
            • Then - Actions
              • Animation - Play ABILITY_CASTER's Attack One Alternate animation
            • Else - Actions
              • Animation - Play ABILITY_CASTER's Attack One animation
          • Set ABILITY_INTEGER = 1
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of EMIYA - 1 for ABILITY_CASTER) Equal to 2
            • Then - Actions
              • Set ABILITY_SOUND = EMY_ATK_2 <gen>
              • Set ABILITY_RANGE = 50.00
              • Set ABILITY_ANIMATIONSPEED = 115.00
              • Set ABILITY_CASTTIME = 0.09
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of ALTERNATE ANIMATION for ABILITY_CASTER) Greater than 0
                • Then - Actions
                  • Animation - Play ABILITY_CASTER's Attack Two Alternate animation
                • Else - Actions
                  • Animation - Play ABILITY_CASTER's Attack Two animation
              • Set ABILITY_INTEGER = 2
            • Else - Actions
              • Set ABILITY_SOUND = EMY_ATK_3 <gen>
              • Set ABILITY_RANGE = 50.00
              • Set ABILITY_ANIMATIONSPEED = 125.00
              • Set ABILITY_CASTTIME = 0.18
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of ALTERNATE ANIMATION for ABILITY_CASTER) Greater than 0
                • Then - Actions
                  • Animation - Play ABILITY_CASTER's Attack Three Alternate animation
                • Else - Actions
                  • Animation - Play ABILITY_CASTER's Attack Three animation
              • Set ABILITY_DAMAGE = 10.00
              • Set ABILITY_INTEGER = 3
      • Trigger - Run Play Sound <gen> (checking conditions)
      • Set ABILITY_OFFSET = 75.00
      • Set ABILITY_AREAOFEFFECT = 175.00
      • Set ABILITY_CASTSPEEDREDUX = (Game_Castspeed_per_AGI x (Real((Agility of ABILITY_CASTER (Include bonuses)))))
      • Set ABILITY_CASTTIME = (ABILITY_CASTTIME x (1.00 - ABILITY_CASTSPEEDREDUX))
      • Set ABILITY_ANIMATIONSPEED = (ABILITY_ANIMATIONSPEED x (1.00 + ABILITY_CASTSPEEDREDUX))
      • Animation - Change ABILITY_CASTER's animation speed to ABILITY_ANIMATIONSPEED% of its original speed
      • Set ABILITY_TRAVEL = 0.00
      • Set ABILITY_SPEED = (ABILITY_RANGE / (ABILITY_CASTTIME / 0.03))
      • -------- ============== --------
      • -------- START --------
      • -------- ============== --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of ALTERNATE ANIMATION for ABILITY_CASTER) Greater than 0
        • Then - Actions
          • Set ABILITY_DAMAGE = (ABILITY_DAMAGE x OveredgeDamage)
          • Set ABILITY_AREAOFEFFECT = (ABILITY_AREAOFEFFECT x OveredgeRange)
          • Set ABILITY_OFFSET = (ABILITY_OFFSET x OveredgeRange)
        • Else - Actions
      • -------- ============== --------
      • -------- SAVING HASHTABLES --------
      • -------- ============== --------
      • Trigger - Turn on Kanshou Bakuya Loop <gen>
      • Hashtable - Save Handle OfABILITY_CASTER as 1 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_DAMAGE as 2 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_RANGE as 3 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_OFFSET as 4 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_AREAOFEFFECT as 5 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_CASTTIME as 6 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_TRAVEL as 7 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_SPEED as 8 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_ANGLE as 9 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • Hashtable - Save ABILITY_INTEGER as 10 of (Key ABILITY_HANDLE) in ABILITY_HASHTABLE
      • -------- ============== --------
      • -------- REFRESHING Z --------
      • -------- ============== --------
      • Unit Group - Add ABILITY_CASTER to RefreshZ_Group
      • Set RefreshZ_Duration = 2.00
      • Hashtable - Save RefreshZ_Duration as 1 of (Key (Triggering unit)) in RefreshZ_Hashtable
      • Trigger - Turn on Refreshing Z Skills Timed <gen>

PLAY SOUND TRIGGER
  • Play Sound
    • Events
    • Conditions
    • Actions
      • Set Sound = No sound
      • Custom script: if GetLocalPlayer() == udg_ABILITY_CASTER then
      • Set Sound = ABILITY_SOUND
      • Custom script: endif
      • Sound - Play Sound
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
It's more helpful if you say what specifically isn't working rather than "it doesn't work". Are you sure the Play Sound trigger is actually being run? Is the sound playing for everyone or for nobody? Do any sounds play this way? Is the inside of that if block being executed? You can check things like this with debug messages (Game - Display to (All players) the text __), and you can disable/enable specific lines of triggers by pressing CTRL+F on them while highlighted.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
"Anything past" is inconclusive unless you also put a debug message after the endif and that also didn't show. The only way that can happen is if udg_ABILITY_CASTER is uninitialized and I can see that it clearly is set in the trigger.
  • Play Sound
    • Events
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg("Before")
      • Sound - Play ABILITY_SOUND
      • Sound - Set volume of ABILITY_SOUND to 0.00%
      • Custom script: if GetLocalPlayer() == udg_ABILITY_CASTER then
      • Custom script: call BJDebugMsg("During")
      • Sound - Set volume of ABILITY_SOUND to 100.00%
      • Custom script: endif
      • Custom script: call BJDebugMsg("After")
Tell me if you see Before, During, and/or After. You can apply this approach to the 'locally play' version of this trigger to se. You may also find there are problems trying to play a sound variable more than once simultaneously; AFAIK that can be an issue with (some?) sounds.
 
Level 7
Joined
Apr 18, 2010
Messages
102
Thanks for the Input Sir!! +REP

The trigger is now working, I made a couple of mistakes in the variable names....

The question is now: How do you know if the sound is also playing for Player 2 at the same time?
(Made a trigger that made another unit cast the same spell when my unit casted his)

  • Play Sound
    • Events
    • Conditions
    • Actions
      • Set Sound = No sound
      • Custom script: if GetLocalPlayer() == udg_ABILITY_PLAYER then
      • Set Sound = ABILITY_SOUND
      • Game - Display to (Player group(ABILITY_PLAYER)) the text: DEBUG
      • Custom script: endif
      • Sound - Play Sound
While Testing, The DEBUG message only appears once... Dunno if this is enough to say that the sound is being played for both players simultaneously...
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
Only way to check is to test in on Bnet or LAN with someone and see if the sound sounds right for both of you. You could get an idea if it works by doing something like this:

  • Events
    • Player - Player 1 (Red) skips a cinematic //this is ESC keypress event
  • Conditions
  • Actions
    • Set ABILITY_PLAYER = (Triggering Player)
    • Set ABILITY_SOUND = EMY_ATK_2 <gen> //or whatever sound you want that's long-ish
    • Trigger - Run Play Sound (checking conditions)
    • Wait 0.50 seconds
    • Trigger - Run Play Sound (checking conditions)
Do you hear 2 'copies' of the sound happening at once (out of sync by the wait time), or does the second one immediately cut off the first one from playing the rest?
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Yeah then it's not gonna work for all players simultaneously because it's just reusing the same sound object over and over again. Sounds in wc3 are total ass and really can't be used like you want them to be used without, effectively, rebuilding the sound object from the ground up each time you want to play it. In this regard you have three options:
  • Manually create instances of each sound object each time they need to play, a la this thread's explanation (but you don't need to attach them to units like that OP needed): [Solved] - 3D Sound Attachment
  • Use an old library that needs to be updated to use Structs/a soundEX variable type and relies on some older code as dependencies: SoundUtils - Wc3C.net
  • Use a newer but 'unapproved' (so who knows if anyone actually looked through it) library that might have some questionable syntax but has no dependencies: [vJASS] - Sound
None of these solutions is going to play nicely with GUI, but there isn't a GUI solution here.
 
Status
Not open for further replies.
Top