how to get where someone clicked on a map

how to get where someone clicked on a map

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

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

how to get where someone clicked on a map

Post by smoth »

Image

Code: Select all

function widget:MousePress(mouseX, mouseY, mButton)
	local _, location = Spring.TraceScreenRay(mouseX, mouseY)

	if location ~= nil then
		Spring.Echo(location[1],location[2],location[3])
	end
end
because I could not find the answer searching the forum. Now it is here for someone else to use.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: how to get where someone clicked on a map

Post by Jools »

If mouse is above unit or feature, the "x"-coordinate will instead be the unitID/featureID. Just saying.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: how to get where someone clicked on a map

Post by gajop »

Add a third parameter that specifies you just want map coords instead:
local _, location = Spring.TraceScreenRay(mouseX, mouseY, true)
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: how to get where someone clicked on a map

Post by smoth »

Thanks for adding to the thread. I don't normally write this sort of thing so I just handled it all wrong :P

I did this :P

Code: Select all

if location ~= nil and type(location) == "table" then
Post Reply

Return to “Lua Scripts”