Execute default command on right mouse button press

Execute default command on right mouse button press

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
Godde
Posts: 268
Joined: 29 Mar 2010, 17:54

Execute default command on right mouse button press

Post by Godde »

This simple widget executes default commands on right mouse button press. Makes it easier to target stuff with default commands.
It has been disabled for move commands to make it easier to draw customFormation move lines.
Guard commands can be disabled easily aswell if you want it to be easier to draw lines of move commands on top of friendly units.
Attachments
cmd_execute_default_command_on_mouse_press.lua
(3.87 KiB) Downloaded 22 times
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Execute default command on right mouse button press

Post by Forboding Angel »

Can you explain this better?
Godde
Posts: 268
Joined: 29 Mar 2010, 17:54

Re: Execute default command on right mouse button press

Post by Godde »

A mouse button click consist of button press and button release. Default behaviour on mouse button click, for most commands, is that you get a single target command if you don't move the mouse between button press and button release and that you get an area command if you move the mouse between button press and button release.
The default commands, or "context-sensitive" commands, is the commands that you get when you have units selected and hover the mouse over a unit or feature. Then you can see the context-sensitive mouse cursor changing between different command cursors. If you have units with weapons selected and hover the mouse over an enemy, you will get an attack command for example.
This widget overrides the default behaviour for right mouse button click and gives the default command to your units directly on right mouse button press. This makes it easier to target a specific unit with a default command because it doesn't matter if you move the mouse between button press and button release. With the default mouse behavior, you will get an area command if you move the mouse and that area command could miss the intended target or target another unit first.
For further discussion, see topic: Targeting, precision and ambiguity when using the mouse.

While move commands could also be executed on mouse button press to target location, I personally find line move commands much more useful even if they are a bit slower to perform.
8611
XTA Developer
Posts: 242
Joined: 29 Dec 2014, 08:22

Re: Execute default command on right mouse button press

Post by 8611 »

Code: Select all

exceptions.CMD_MOVE		= CMD.MOVE
...
function CheckCommand(number, commandList)
	for _, command in pairs(commandList) do
		if command == number then
			return true
		end
	end
	
	return false
end
Why not: (untested)

Code: Select all

function CheckCommand(number, commandList)
 return commandList[number] or false
end
You already know the index where something is, so can just check that instead of looping through whole table.
Godde
Posts: 268
Joined: 29 Mar 2010, 17:54

Re: Execute default command on right mouse button press

Post by Godde »

8611 wrote:You already know the index where something is, so can just check that instead of looping through whole table.
True that. Yeah. I'm not thinking like its a Lua table.
Post Reply

Return to “Lua Scripts”