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
964
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
964
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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