System MultiClick

Reaction score
341
MultiClick

Simple system that allows you to register double or tripple click events.

Also allows you to easily add your clicks easily.

JASS:
library MultiClick
    
    globals
        private constant real TIMER_TIMEOUT = 0.40
        private constant integer SUBTRACT = 0x100000
    endglobals
    // Don't modify below this line
    
    private function True takes nothing returns boolean
        return true
    endfunction
    
    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    //! textmacro MULTICLICK takes NAME,CLICKS
    
    globals
        private integer array INDEXED_TIMERS_$NAME$
    endglobals
    
    private struct $NAME$
        
        trigger pointer
        trigger execute
        timer expire
        integer max
        integer clicks
        boolean b
        
        static method create takes trigger t, player p, integer max returns $NAME$
            local $NAME$ d = GetPlayerId(p)
            set d.execute = CreateTrigger()
            set d.pointer = t
            set d.expire = CreateTimer()
            set d.b = true
            set d.max = max
            set d.clicks = 0
            set INDEXED_TIMERS_$NAME$[H2I(d.expire)] = d
            return d
        endmethod
        
    endstruct
    
    private function $NAME$_GetTimerId takes timer t returns integer
        return H2I(t)-SUBTRACT
    endfunction
    
    private function $NAME$_Reset takes nothing returns nothing
        set $NAME$(INDEXED_TIMERS_$NAME$[$NAME$_GetTimerId(GetExpiredTimer())]).clicks = 0
    endfunction
    
    private function $NAME$_Execute takes nothing returns nothing
        local $NAME$ d = GetPlayerId(GetTriggerPlayer())
        set d.clicks = d.clicks + 1
        if d.clicks == 1 then
            call TimerStart(d.expire, TIMER_TIMEOUT, false, function $NAME$_Reset)
        endif
        if d.clicks == d.max then
            if IsTriggerEnabled(d.pointer) and TriggerEvaluate(d.pointer) then
                call TriggerExecute(d.pointer)
            endif
        endif
    endfunction
    
    function TriggerRegister$NAME$Click takes trigger t, player p returns nothing
        local $NAME$ d = GetPlayerId(p)
        if d.b == null then
            set d = $NAME$.create(t, p, $CLICKS$)
        else
            debug call BJDebugMsg("You already have a $NAME$Click registered for " + GetPlayerName(p))
            return
        endif
        call TriggerRegisterPlayerUnitEvent(d.execute, p, EVENT_PLAYER_UNIT_SELECTED, Filter(function True))
        call TriggerAddAction(d.execute, function $NAME$_Execute)
    endfunction
    //! endtextmacro
    
    //! runtextmacro MULTICLICK("Double", "2")
    //! runtextmacro MULTICLICK("Tripple", "3")
endlibrary


Example

JASS:
function double takes nothing returns nothing
    call BJDebugMsg("DoubleClick")
    call BJDebugMsg(" ")
endfunction

//===========================================================================
function InitTrig_mc_test takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterDoubleClick(t, Player(0))
    call TriggerAddAction(t, function double)
endfunction


Changelog

Version 1.1 - Latest
  • Removed O(n) search.
 

Azlier

Old World Ghost
Reaction score
461
JASS:
private function $NAME$_GetTimerId takes timer t returns integer
        local $NAME$ d
        local integer i = 0
        loop
            exitwhen i > 11
            set d = i
            if d.expire == t then
                return i
            endif
            set i = i + 1
        endloop
        return -1
    endfunction

That is one stylish O(n) search...

JASS:
private function True takes nothing returns boolean
        return true
    endfunction

Nice 'n useless.

JASS:
call TriggerAddAction(d.execute, function $NAME$_Execute)

Use conditions at the very least.
 

Romek

Super Moderator
Reaction score
964
Don't you think it'd have been better to just tell Azlier to add triple-click support into his system, than create a brand new system which does basically the same thing?

Why would you need triple-click anyway?
"Mini-Games" isn't really a descriptive answer.
 

_whelp

New Member
Reaction score
54
Umm... it could it be used to:

play a game where you click a certain number of times,

click a car to make it move,

destroy everything that was clicked x times.
 
Reaction score
341
Don't you think it'd have been better to just tell Azlier to add triple-click support into his system, than create a brand new system which does basically the same thing?

I did. (Link)

Why would you need triple-click anyway?

#1,#2.

As for #2, maybe the more clicks you get in for that spell the more damage it will do.

Or maybe bigger the effect.
 

Romek

Super Moderator
Reaction score
964
> I did. (Link)
And yet you still make this?
If Azlier did add triple (note the spelling) clicks, then we'd have 2 identical systems.

------

> play a game where you click a certain number of times,
Why would you need triple for that?

> click a car to make it move,
That's not triple-clicking

> destroy everything that was clicked x times.
Acceptable. But "Triple Click Everything to Destroy It" is pretty silly...
Double Click would still be better for that though.
Select a unit to see the damage, stats, etc. Double-click to kill.

> Like, stunning a unit, and for each double click your unit deals damage and plays an animation bla bla
I don't see triple-click there.

Anything 'extra' someone will need to do with clicking works fine with double-clicks.
 

Romek

Super Moderator
Reaction score
964
> He said he couldn't make it in his systems current state.
I was unaware.
Well, that's his choice then.

I still don't see the usefulness of Triple Clicks, and we've already got a system like this.

Once I get to reviewing Azliers DoubleClick, I'll graveyard either this or that.

This is the second time I remember you copying something else which someone made. The other being Jesus4Lyf's Gamecache.
 
Reaction score
341
This is the second time I remember you copying something else which someone made. The other being Jesus4Lyf's Gamecache

Copying? first of all there have been a lot of double clicks made before, all of our codes are different.

As for SimCache, our methods were completely different.
 

_whelp

New Member
Reaction score
54
Errmmm... let me revise what I said in click multiple times...

You multi-click a fast moving unit as fast as you can, until the click-limit is up.
If you pass the limit, you uhh lose the round/point/whatever. Whoever clicks the most without passing the limt or whoever clicks the least out of all if they all passed the limit, they umm. win.
 

Romek

Super Moderator
Reaction score
964
> Copying? first of all there have been a lot of double clicks made before, all of our codes are different.
Let's put it this way:
How would you feel if I created "Quad-Click Library" and released it now.
Assuming this couldn't support that with an extra macro. (Looking at this from Azliers point of view).

> You multi-click a fast moving unit as fast as you can, until the click-limit is up.
This system would be useless in that case, as you'd need to count the amount of times a unit is clicked, not do something when it's clicked 3 times within 0.4 seconds.
 

Azlier

Old World Ghost
Reaction score
461
I'll just modify DoubleClick to handle more clicks, because some people actually "need" that.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Pretty sure they were quite similar (both string id as array key, was it not?).

>Filter(function True)
Remove it.

>call TriggerAddAction(d.execute, function $NAME$_Execute)
Use a condition returning false. If you want to impress, find a way to put this condition in the event as a filter. Test it thoroughly first.

This system is poor compared to Azlier's.
  • Your system pretends to look something like a Warcraft III event, but it only allows it to be registered once. I find this disappointing considering the Event snippet is a good quality JASS script invented specifically for making this easy, and you probably even saw it in Azlier's system. You also provide no warning to users with any documentation of this system flaw. Covering this up is very poor practice.
  • This uses H2I and subtraction. You could've at least hashed it. This is unstable. I don't care that you subtract a global constant, you didn't document it, nor does that make it as stable as Azlier's system!
  • Your reason this is better is that it supports triple clicks. Your reason for triple clicks being useful was in minigames. In a minigames map you usually have multiple minigames, and hence probably want to register the same event twice. Which your system doesn't support. If you argue spells, same deal.

The least you can do is make this use Event to support... events.

And making this system actually stable would be great too. But hey, then you'd probably end up with Azlier's. He did quite a clever timer trick to achieve that stability.

By the way, I like your struct typecasting instead of allocate(). But don't tell anyone I said that! ;)
 
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