Jump to content

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


ethanwdp

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
Link to comment
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);

 

Link to comment
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

 

Link to comment
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!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...