• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] CameraEQNoise

Level 19
Joined
Mar 18, 2012
Messages
1,716
CameraEQNoise

Create timed camera shake for a player.


library CameraEQNoise

You will need TimerUtils or a backwards compatible version of it, to use CameraEQNoise.
Be aware the the API is not safe in local traffic blocks, therefore avoid using GetLocalPlayer()
in combination with SetCameraEQNoise and StopCameraEQNoise.
Copy 'n' paste the following code into your map:
JASS:
library CameraEQNoise /* v1.0
*************************************************************************************
*
*   Create timed "cameraEQnoise".
*
*   The code is not 100% local traffic safe. Do not use
*   the listed API in a GetLocalPlayer block!
*
*************************************************************************************
*
*   */ requires /*
*
*       */ TimerUtils /*
*
************************************************************************************
*
*   1. Import instruction
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*       Copy CameraEQNoise and TimerUtils into to your map.
*       If you are using TimerUtilsEx, change the requirement
*       from TimerUtils to TimerUtilsEx.
**  
*   2. API
*   ¯¯¯¯¯¯
*
*   function CameraSetEQNoise takes player whichPlayer, real magnitude, real duration returns nothing
*       - Equal to the blizzard bj CameraSetEQNoiseForPlayer, but includes a timer callback.
*       - Do not use this function in a local traffic ( GetLocalPlayer() ) block.
*   
*   function StopCameraEQNoise takes player whichPlayer returns nothing
*       - Equal to the blizzard bj CameraClearNoiseForPlayer, but releases a running timer.
*            
************************************************************************************************
*/
    globals
        private timer array clock
    endglobals

    function StopCameraEQNoise takes player whichPlayer returns nothing
        local integer id = GetPlayerId(whichPlayer)
        if (clock[id] != null) then
            call ReleaseTimer(clock[id])
            set clock[id] = null
        endif
        if (GetLocalPlayer() == whichPlayer) then
            call CameraSetSourceNoise(0, 0)
            call CameraSetTargetNoise(0, 0)
        endif
    endfunction
    
    private function TimerExpire takes nothing returns nothing
        call StopCameraEQNoise(Player(GetTimerData(GetExpiredTimer())))
    endfunction
    
    function CameraSetEQNoise takes player whichPlayer, real magnitude, real duration returns nothing
        local real richter = magnitude
        local integer id   = GetPlayerId(whichPlayer)
        local real pow 
        if (richter > 5.) then
            set richter = 5.
        elseif (richter < 2.) then
            set richter = 2.
        endif
        call StopCameraEQNoise(whichPlayer)
        set clock[id] = NewTimerEx(id)
        call TimerStart(clock[id], duration, false, function TimerExpire)
        set pow = magnitude*Pow(10, richter)
        if (GetLocalPlayer() == whichPlayer) then
            call CameraSetTargetNoiseEx(magnitude*2., pow, true)
            call CameraSetSourceNoiseEx(magnitude*2., pow, true)                
        endif
    endfunction

endlibrary
 
Last edited:
Now here is a critical problem with this resource:

What if I want to play the noise only if the camera of the player is within a certain area, for example in range of an earthquake type of spell? I can not get camera data globally, so it will always be within a local block at this point.

So maybe add the following:
JASS:
function SetCameraEQNoiseXY takes player whichPlayer, real magnitude, real duration, real x, real y, real range returns nothing

... would also make your script complex enough to justify it here.

Bonus points for a function that gradually fades the magnitude between a start and end value over time.
 
Top