Jump to content
ethanwdp

getMouseXScaled() and getMouseYScaled() no longer returning correct coordinates

Recommended Posts

I'm unsure if this is a new bug with the game, or if something related to mouse coordinates were changed in the game (and thus breaking my mod), but ever since Build 34 the mouse coordinates returned from getMouseYScaled() and getMouseXScaled() are off.

 

CheatCoreCM.DoFireNow = function()
	if CheatCoreCM.FireBrushEnabled == true then
		local mx = getMouseXScaled();
		local my = getMouseYScaled();
		local player = getPlayer();
		local wz = math.floor(player:getZ());
		local wx, wy = ISCoordConversion.ToWorld(mx, my, wz);
		wx = math.floor(wx);
		wy = math.floor(wy);
		local cell = getWorld():getCell();
		local GridToBurn = cell:getGridSquare(wx, wy, wz)
		GridToBurn:StartFire();
	end
end

I hook a function to OnMouseDown. The function runs a simple variable check, gets the mouse coordinates with getMouseYScaled() and getMouseXScaled() , and assigns two variables with the results returned from ISCoordConversion.ToWorld(). It then gets the cell, and gets the grid square with said coordinates, and lights it the hell up.

 

It's simple, and it worked for ages. However, it stopped working correctly on B34. It now creates a fire several tiles away. It's like playing Russian roulette, but you're god and you just accidentally lit Smokey the Bear on fire.

 

I am running this on a school laptop running on 32bit. The resolution is 1366x760. Changing the in-game resolution does not affect where the fire lands at all. This happens on fullscreen, fullscreen borderless, and windowed. This issue stretches to all of the mouse-related square-editing functions I use in Cheat Menu.

 

At first I thought it was just this laptop, but a user of my Cheat Menu mod reported the same issue - all mouse-related functions are editing a square a dozen or so tiles from the target.

 

We both tried turning off all map mods, all mods other than Cheat Menu, and making a new save. None of these worked.

 

I'm posting this in Help first since I'm not certain this is a bug with B34. My question is this: what went wrong and how can I fix it?

Edited by ethanwdp

Share this post


Link to post
Share on other sites

In media/lua/server/ISCoordConversion.lua, it looks like these lines should be removed.   The 'weird offset' was fixed when doing the 2x tiles.

	-- weird offset required to get it exact...
	sy = sy + 256 + 128;

-- weird offset required to get it exact... need to look into this
    y = y - (256 + 128);

 

Share this post


Link to post
Share on other sites

The final file looks like this:


ISCoordConversion = {}

ISCoordConversion.ToScreen = function(x, y, z, cz)

    if cz == nil then
        cz = 0;
    end

	local sx = IsoUtils.XToScreen( x, y, z, cz );
	local sy = IsoUtils.YToScreen( x, y, z, cz );

	sx = sx - getCameraOffX();
	sy = sy - getCameraOffY();

	return sx, sy;
end

ISCoordConversion.ToWorld = function(x, y, z)

	local wx = IsoUtils.XToIso( x, y, z );
	local wy = IsoUtils.YToIso( x, y, z );

 --   --print("Output of ToWorld: "..wx..", "..wy)
	return wx, wy;
end

 

Share this post


Link to post
Share on other sites
18 hours ago, EasyPickins said:

The final file looks like this:


ISCoordConversion = {}

ISCoordConversion.ToScreen = function(x, y, z, cz)

    if cz == nil then
        cz = ;
    end

	local sx = IsoUtils.XToScreen( x, y, z, cz );
	local sy = IsoUtils.YToScreen( x, y, z, cz );

	sx = sx - getCameraOffX();
	sy = sy - getCameraOffY();

	return sx, sy;
end

ISCoordConversion.ToWorld = function(x, y, z)

	local wx = IsoUtils.XToIso( x, y, z );
	local wy = IsoUtils.YToIso( x, y, z );

 --   --print("Output of ToWorld: "..wx..", "..wy)
	return wx, wy;
end

 

Thanks!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...