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:
Now you can register that the click on the object should lead to the evaluation of some trigger:
for ex.:
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.
To set it up you use:
JASS:
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
- 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
- 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)
- Events
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
- 'IF'-Conditions
- Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Events
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
- 'IF'-Conditions
- Multiple Functions If (All Conditions are True) then do (Then Actions) else do (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
- 'IF'-Bedingungen
- Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- Game - Force Player 1 (Red) to press the key T
- Custom script: call DestroyGroup( udg_TempGroup)
- Set TempGroup = (Units currently selected by Player 1 (Red))
- Events
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.