System SpacebarDetection

Reaction score
341
SpacebarDetection
TriggerHappy187​

Introduction

This is a system that can detect whenever the spacebar is hit.

But before anyone uses it, your map must not contain any of the following;

  • Locked cameras (yes units count).
  • Can't set spacebar points via triggers.
If your map doesn't have those then you can use this script.

The Code

JASS:
//***************************************************************************
//*
//*  SpacebarDetect - By TriggerHappy187
//*
//***************************************************************************
//*   
//*  CONS
//*    - Cannot define custom spacebar points.
//*    - Doesn't work if camera is locked
//
//*  Only added cons because the pros obvious (it detects when a spacebar is hit)
//*
//***************************************************************************
//*  configurables
library SpacebarDetect initializer InitTrig

    globals
        private constant real TIMEOUT = 0.03 // Accuracy of spacebar detect.
    endglobals
//*  endconfigurables
//***************************************************************************
//*
//*  Don't modify below this line!
//*
//***************************************************************************

    globals
        private integer COUNT = 0
        private trigger array T
        private player array P
        private real array X
        private real array Y
        private timer TIMER = CreateTimer()
    endglobals
    
    private function callback takes nothing returns nothing
        local integer i = 0
        local real x
        local real y
        local integer c
        local boolean b
        loop
            exitwhen i > COUNT
            set b = GetLocalPlayer() == P<i>
            set c = GetPlayerId(P<i>)
            if b then
                set x = GetCameraTargetPositionX()
                set y = GetCameraTargetPositionY()
            endif
            if x == X[c] and y == Y[c] then
                if TriggerEvaluate(T<i>) and IsTriggerEnabled(T<i>) then
                    call TriggerExecute(T<i>)
                endif
            endif
            set X[c] = x+.1
            set Y[c] = y+.1
            if b then
                call SetCameraQuickPosition(X[c], Y[c])
            endif
            set i = i + 1
        endloop
    endfunction
    
    function TriggerRegisterPlayerSpacebarEvent takes trigger whichTrigger, player whichPlayer returns nothing
        set T[COUNT] = whichTrigger
        set P[COUNT] = whichPlayer
        set COUNT = COUNT + 1
        if COUNT == 1 then
            call TimerStart(TIMER, TIMEOUT, true, function callback)
        endif
    endfunction
    
    private function InitTrig takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i &gt; 11
            if GetLocalPlayer() == Player(i) then
                set X<i> = GetCameraTargetPositionX()+.1
                set Y<i> = GetCameraTargetPositionY()+.1
                call SetCameraQuickPosition(X<i>, Y<i>)
            endif
            set i = i + 1
        endloop
    endfunction
    
endlibrary</i></i></i></i></i></i></i></i></i>


Demo

Check out the demo :D

Whenever you press the spacebar your unit will jump.
 

Attachments

  • spacebar.w3m
    63 KB · Views: 219

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
The little flash could make someone have an epileptic crisis.
Any example of how it could be used?!
And the jump is a good idea tought.

>Sometimes it brings my view to the corner, without showing back to hero.
Why?
 
Reaction score
341
The little flash could make someone make an epileptic crisis.
Any example of how it could be used?!
And the jump is a good idea tought.

>Sometimes it brings my view to the corner, without showing back to hero.
Why?

I've noticed that too, but only after submitting.

I think I may have found a fix that can remove the flashing (and the bug you just pointed out).
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
It isn't related to the system, but if you spam spacebar the jump physics mess up.
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
As far as you explained, yes. I noticed that bug where if you click on portrait it won't detect, so that's all I've noticed.

Edit: Holy... My hero disappeared when I spammed it really fast.
 

wraithseeker

Tired.
Reaction score
122
Actually why don't you detect whether the camera position is at their start location when pressed or other units if modified, seems easier.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
JASS:
if x == X[c] and y == Y[c] then
                if TriggerEvaluate(T<i>) and IsTriggerEnabled(T<i>) then
                    call TriggerExecute(T<i>)
                endif
            endif</i></i></i>


Would desynch, and also i think using ExecuteFunc, and TriggerExecute alone locally make also a desynch (because of a "new thread").

Btw i think you don't know that the camera quick position is changed by war3 itself, when a structure is attacked at least.

Seriously it has too much cons to be a snippet or a system, you would need to make custom functions if the user plan to use cameras, or in general play with the camera position.
 

Romek

Super Moderator
Reaction score
963
> if TriggerEvaluate(T) and IsTriggerEnabled(T) then
No good evaluating a disabled trigger...
Those should be the other way around.

You may also want to note that the 'actions' and 'conditions' for the registered triggers are ridiculously desync-friendly.

Also, there's no need to do a loop, in which you only do stuff for GetLocalPlayer().
Use GetLocalPlayer directly instead.
JASS:
.
        loop
            exitwhen i &gt; 11
            if GetLocalPlayer() == Player(i) then
                set X<i> = GetCameraTargetPositionX()+.1
                set Y<i> = GetCameraTargetPositionY()+.1
                call SetCameraQuickPosition(X<i>, Y<i>)
            endif
            set i = i + 1
        endloop</i></i></i></i>

Use:
local integer i = GetPlayerId(GetLocalPlayer()), and remove the loop.
(I don't actually see the point in an array there.. But meh.)

Also, as I said before. You don't need to submit everything you create. My advice would be to only submit working, useful things.
 
Reaction score
341
My advice would be to only submit working, useful things.

Hmn, so this isn't useful and isn't working because you can't lock your camera or set a spacebar point..?

Btw i think you don't know that the camera quick position is changed by war3 itself, when a structure is attacked at least.

Well, I never used the spacebar for that so I didn't know. Anyways, the quick-pos resets in every loop anyways.

you would need to make custom functions if the user plan to use cameras

I'm planning on added functionnameEx to all functions so you can be allowed to lock the camera and set custom spacebar points.

I also don't see how this desyncs?

Is it because the x/y are defined in a local block?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Hmn, so this isn't useful and isn't working because you can't lock your camera or set a spacebar point..?
Most likely because of the awfull desynch. And also can't lock the cam is really annoying.

Well, I never used the spacebar for that so I didn't know. Anyways, the quick-pos resets in every loop anyways.
Sure but it still can fail sometimes.

I'm planning on added functionnameEx to all functions so you can be allowed to lock the camera and set custom spacebar points.
I don't think you will do it sucessly, at least for spacebar points, as i said war3 change it internally.

I also don't see how this desyncs?

Is it because the x/y are defined in a local block?
Because you evaluate and execute triggers locally ?
 
Reaction score
341
Because you evaluate and execute triggers locally ?

I don't see how I am doing that, it's not in a local block.

I don't think you will do it sucessly, at least for spacebar points, as i said war3 change it internally.

Well, I succesfully added custom spacebar points :thup: (will release after I fix everything else).

local integer i = GetPlayerId(GetLocalPlayer()), and remove the loop.
(I don't actually see the point in an array there.. But meh.)

The Inittrig actually isn't needed.
 

Romek

Super Moderator
Reaction score
963
> I don't see how I am doing that, it's not in a local block.
Oh well. You're doing it.

> The Inittrig actually isn't needed.
Then why'd you put it there..?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top