• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

disable space

One common way to do it is to periodically set the camera "quick position" to the player's current camera position. This controls where the camera goes when the spacebar button is pressed. Here is an example of how you'd do that:
  • Disable Spacebar Point
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • Custom script: call SetCameraQuickPosition(GetCameraTargetPositionX(), GetCameraTargetPositionY())
This does the same thing as "Camera - Set Spacebar-Point", but the custom script above is a lot more concise and works for all players. You can also feel free to tweak the interval (0.02 seconds) to your liking. I found that 0.02 seconds is a pretty good sweet spot--even when I'm panning the camera around while pressing the spacebar, I don't really notice any jitter.

Next, you'll need a trigger to detect when the spacebar is pressed. I don't think that function is available in GUI, so you'll need to use JASS or Lua (you can make a new trigger and go to the toolbar and hit Edit > Convert to Custom Text). Here is a sample trigger below:
JASS:
function Trig_Detect_Spacebar_Actions takes nothing returns nothing
    call TriggerExecute(gg_trg_On_Spacebar_Press)
endfunction

//===========================================================================
function InitTrig_Detect_Spacebar takes nothing returns nothing
    local integer i = 0
    set gg_trg_Detect_Spacebar = CreateTrigger()

    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER) then
            call BlzTriggerRegisterPlayerKeyEvent(gg_trg_Detect_Spacebar, Player(i), OSKEY_SPACE, 0, true)
        endif
        set i = i + 1
    endloop

    call TriggerAddAction( gg_trg_Detect_Spacebar, function Trig_Detect_Spacebar_Actions )
endfunction

This will loop through all playing players controlled by a user and then register when the spacebar (OSKEY_SPACE) is pressed. The last argument in BlzTriggerRegisterPlayerKeyEvent is "true", which means it'll fire the trigger when the spacebar is pressed. If you want it to fire when the key is released, you can change that to "false" instead.

For the actions, I just have it execute another trigger. You can see a full playable example attached below, hope it helps!
 

Attachments

  • SpacebarSample.w3m
    17.5 KB · Views: 5
Level 2
Joined
Jan 17, 2019
Messages
10
One common way to do it is to periodically set the camera "quick position" to the player's current camera position. This controls where the camera goes when the spacebar button is pressed. Here is an example of how you'd do that:
  • Disable Spacebar Point
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • Custom script: call SetCameraQuickPosition(GetCameraTargetPositionX(), GetCameraTargetPositionY())
This does the same thing as "Camera - Set Spacebar-Point", but the custom script above is a lot more concise and works for all players. You can also feel free to tweak the interval (0.02 seconds) to your liking. I found that 0.02 seconds is a pretty good sweet spot--even when I'm panning the camera around while pressing the spacebar, I don't really notice any jitter.

Next, you'll need a trigger to detect when the spacebar is pressed. I don't think that function is available in GUI, so you'll need to use JASS or Lua (you can make a new trigger and go to the toolbar and hit Edit > Convert to Custom Text). Here is a sample trigger below:
JASS:
function Trig_Detect_Spacebar_Actions takes nothing returns nothing
    call TriggerExecute(gg_trg_On_Spacebar_Press)
endfunction

//===========================================================================
function InitTrig_Detect_Spacebar takes nothing returns nothing
    local integer i = 0
    set gg_trg_Detect_Spacebar = CreateTrigger()

    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER) then
            call BlzTriggerRegisterPlayerKeyEvent(gg_trg_Detect_Spacebar, Player(i), OSKEY_SPACE, 0, true)
        endif
        set i = i + 1
    endloop

    call TriggerAddAction( gg_trg_Detect_Spacebar, function Trig_Detect_Spacebar_Actions )
endfunction

This will loop through all playing players controlled by a user and then register when the spacebar (OSKEY_SPACE) is pressed. The last argument in BlzTriggerRegisterPlayerKeyEvent is "true", which means it'll fire the trigger when the spacebar is pressed. If you want it to fire when the key is released, you can change that to "false" instead.

For the actions, I just have it execute another trigger. You can see a full playable example attached below, hope it helps!
I knew about the timer with setting a point, I was just thinking. maybe there is some other way) nevertheless, thank you very much
 
Top