Tutorial How to access the Mouse in Wc3

Executor

I see you
Reaction score
57
How to access the Mouse in Wc3
by Executor​

  • Sense of this tutorial
  • Basics
    • The object 'trackable'
  • The 2 possibilities
    • Trackable fields
    • Hotkey forcing
      • How to do in GUI
  • Credits

Sense of this tutorial:

Wouldn't it be great being able to cast spells just by clicking somewhere on the ground or by drawing runes in the earth just by using your cursor?


In this tutorial I will explain HOW you could create such features and the problems they comprise.

I won't include 'RtC'.

Basics

The object 'trackable'

(skip if you know trackables)

A trackable is simply a model, which is able to inform the game "hey the user clicked me" or "hey the cursor touched me".

To set it up you use:
JASS:
native CreateTrackable takes string trackableModelPath, real x, real y, real facing returns trackable


Now you can register that the click on the object should lead to the evaluation of some trigger:
JASS:
native TriggerRegisterTrackableHitEvent takes trigger whichTrigger, trackable t returns event


for ex.:

JASS:
function Trig_SomeTrigger_Actions takes nothing returns nothing
    call BJDebugMsg("HEY! you clicked me!")
endfunction

//===========================================================================
function InitTrig_SomeTrigger takes nothing returns nothing
    local trackable someTrackable = CreateTrackable("units\\human\\Footman\\Footman",0.,0.,90.)

    set gg_trg_SomeTrigger = CreateTrigger(  )
    call TriggerAddAction( gg_trg_SomeTrigger, function Trig_SomeTrigger_Actions )
    
    call TriggerRegisterTrackableHitEvent(gg_trg_SomeTrigger, someTrackable)
endfunction


This will generate a footman model on the ground looking to the north and if you click him you will see the message "HEY! you clicked me!".

Note: Trackables can NOT be removed.

The 2 possibilities

Trackable fields:

The first way of reacting to mouse actions is to generate thousands of trackables for every player (as a trackable doesn't know WHO touched it) over the whole map.
By doing so with a transparent model the map looks like before but you can access mouse movement and clicking.

Advantages:
  • Accessing clicks on the ground
  • Accessing mouse movement
  • Accessing cursor position
Disadvantages:
  • You cannot issue orders on the ground
  • The trackable field cannot be destroyed
  • [Clicks on] or [movements over] other objects aren't recognized

Here is a system which allows the setup of such a field Click

Hotkey forcing:

The second possibility is to force the user to select a dummy unit, followed by periodically forcing the user to hotkey the dummy unit's dummy spell. This means your cursor becomes the "target cursor" and everytime you click on the ground you can react to the dummy spell cast, followed by hotkey being forced again.

JASS:
native ForceUIKey takes string key returns nothing


Advantages:
  • You can disable the "detect click" mode
  • You can react to clicks on objects
  • Highest precision possible
Disadvantages:
  • No mouse movement reaction
  • Mouse position is unclear until you click somewhere
  • You cannot select other units while in this mode

How to do in GUI:
Trigger:
  • ForceKey GUI Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set TempLoc = (Center of (Playable map area))
      • Unit - Create 1 Force Key Dummy for Player 1 (Red) at TempLoc facing 270.0 degrees
      • Set TheDummyUnit = (Last created unit)
      • Unit - Hide TheDummyUnit
      • Trigger - Add to ForceKey GUI Response <gen> the event (Einheit - TheDummyUnit is issued an order targeting a point)
      • Custom script: call RemoveLocation( udg_TempLoc)

Trigger:
  • ForceKey GUI Start Stop
    • Events
      • Player - Player 1 (Red) types a chat message containing -StartGUI as exact match
      • Player - Player 1 (Red) types a chat message containing -StopGUI as exact match
    • Conditions
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Conditions
          • (Entered chat string) Equals (==) -StartGUI
        • 'THEN'-Actions
          • Countdown-Timer - Start TheTimer as a repetitive timer that will expire in 0.05 seconds
          • Unit - Unhide TheDummyUnit
        • 'ELSE'-Actions
          • Countdown-Timer - Pause TheTimer
          • Unit - Hide TheDummyUnit

Trigger:
  • ForceKey GUI Periodic
    • Events
      • Time - TheTimer expires
    • Conditions
    • Actions
      • Set TempGroup = (Units currently selected by Player 1 (Red))
        • Multiple Functions If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • 'IF'-Conditions
            • (TheDummyUnit is in TempGroup) Equals (==) False
          • 'THEN'-Actions
            • Selection - Add TheDummyUnit to selection
          • 'ELSE'-Actions
      • Unitgroup - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Bedingungen
              • TheDummyUnit not equal (!=) (Picked unit)
            • 'THEN'-Aktionen
              • Selection - Remove (Picked unit) from selection
            • 'ELSE'-Aktionen
      • Game - Force Player 1 (Red) to press the key T
      • Custom script: call DestroyGroup( udg_TempGroup)

Trigger:
  • ForceKey GUI Response
    • Events
    • Conditions
    • Actions
      • Set TempLoc = (Target point of issued order)
      • Game - Display to (All players) the text: (GUI ForceKey: You clicked + ((String((X of TempLoc))) + (/ + (String((Y of TempLoc))))))
      • Unit - Order TheDummyUnit to stop
      • Custom script: call RemoveLocation( udg_TempLoc)

Here is a system which allows the easy and effective setup of the ForceKey-method Azlier or mine's.

Credits

Credits to Azlier for informing me about the 'Hotkey forcing' method.

If you have criticism and/or ideas, tell me.

Maybe I'll add a Demo Map comprising both possibilities later.

Greetings.
 

Azlier

Old World Ghost
Reaction score
461
Hey, I didn't think about modifying the hotkey forced ability to accept objects as well as points for targets. That's useful. :)
 

UndeadDragon

Super Moderator
Reaction score
447
Is it just me who feels that this "advertises" (not nessesarily in a bad way) his TrackMaps system? And yes, the Force Key stuff is good.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Disadvantage for hotkey forcing: you can't cast abilities.

I don't know how useful this is in general. But it's not bad.
It needs to actually teach you how to set up these things. I'd say this is not a tutorial until it contains demo triggers and explanations on how to set up hotkey forcing (so a GUI user could do it perhaps even) and understand it, and same for a trackable grid (even if it is using your system).
 

Azlier

Old World Ghost
Reaction score
461
Actually, I'm trying to brew a hotkey forcing method that allows ability casting.

I'll get back to you people on that.
 

Executor

I see you
Reaction score
57
I don't know how useful this is in general. But it's not bad.
It needs to actually teach you how to set up these things. I'd say this is not a tutorial until it contains demo triggers and explanations on how to set up hotkey forcing (so a GUI user could do it perhaps even) and understand it, and same for a trackable grid (even if it is using your system).

k, I will add some code snippets over the next days.
 

Romek

Super Moderator
Reaction score
963
This is awfully short and undetailed in my opinion.
I was surprised it ended so quickly when I read it.

- A trackable is something that tracks
- You can create them all over the map
- You can also force a UI key.
That's all that's covered, it seems.
 

Executor

I see you
Reaction score
57
That IS all!
Well if you have some topics which should be added... then tell me.
I only want explain users how to access the mouse..
In moment im working on a library which allows the easy use of ForceKey, which shall be added.
 

Romek

Super Moderator
Reaction score
963
Remember that this should be more of a "How to do blah", not "To import my system...".
Bare that in mind whilst working on your library.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top