• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] CameraEQNoise

Level 19
Mar 18, 2012

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:
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.
        private timer array clock

    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
        if (GetLocalPlayer() == whichPlayer) then
            call CameraSetSourceNoise(0, 0)
            call CameraSetTargetNoise(0, 0)
    private function TimerExpire takes nothing returns nothing
        call StopCameraEQNoise(Player(GetTimerData(GetExpiredTimer())))
    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.
        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)                

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:
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.