Forum
Scripts
How does mousemap work?
How does mousemap work?
10 replies
1

player mousex and mousey represent the current mouse position on the screen (0 to screenWidth for X and 0 to screenHeight for Y).mousemapx and mousemapy represent the current mouse position in the game world (relative to the currently visible part of the map).
So the math is:
1
2
2
mouseMapX = ownPlayerX - screenWidth/2 + mouseX mouseMapY = ownPlayerY - screenHeight/2 + mouseY
The screenWidth/2 and screenHeight/2 part is because the player is at the center of the screen.
Rule of thumb:
Use mousex/mousey if you want to display HUD images/texts at the mouse position
Use mousemapx/mousemapy for everything else e.g. spawning things on the map at the mouse position.
DC, One more thing so now I want whenever my pointer is on my enemy team then it should return true, else return false. I'm currently using this code but it's not working properly.1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
local mouseMapX = player(myID, "x") - player(myID, "screenw")/2 + player(myID, "mousex")
local mouseMapY = player(myID, "y") - player(myID, "screenh")/2 + player(myID, "mousey")
addhook("second", "OnSecond")
OnSecond = (function()
	if (mouseMapX == player(enemyID, "x") and mouseMapY == player(enemyID, "y")) then
		msg("Yes")
	else
		msg("No")
	end
end)
Would be appreciated
player(id "mousemapx") and
player(id "mousemapy")?!You don't have to (and you shouldn't!) calculate that stuff yourself. There's mousemapx and y so you don't have to do it yourself!
2. You are only calculating the position once. You would have to do it each time you want to check it (inside the hook) because it's changing all the time.
3. The position is in pixels. When you are comparing pixel coordinates you would have to point exactly at one specific pixel of an enemy to make that stuff work. You should calculate the distance between player and mouse and check if that is below a certain threshold like 20 pixels or something.
second for that because it would not be precise and accurate, use one which gets triggered more frequently, like
ms100 or
always, or maybe even create your own
timer.
DC I have no idea how to do that
DC has written3. The position is in pixels. When you are comparing pixel coordinates you would have to point exactly at one specific pixel of an enemy to make that stuff work. You should calculate the distance between player and mouse and check if that is below a certain threshold like 20 pixels or something.
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
addhook("always", "OnAlways")
OnAlways = (function()
	if (player(myID, "mousemapx") == player(enemyID, "x") and player(myID, "mousemapy") == player(enemyID, "y")) then
		parse("hudtxt 0 Yes")
	else
		parse("hudtxt 0 No")
	end
end)
DC suggested you check if it's within a threshold instead of being exact).1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("always", "OnAlways")
function onAlways()
	--[[
	Some way to get myID and enemyID
	]]
	-- Check if it's within 20 pixel threshold
	local inrangex, inrangey
	inrangex = player(myID,"mousemapx") >= player(enemyID,"x")-10 and player(myID,"mousemapx") <= player(enemyID,"x")+10
	inrangey = player(myID,"mousemapy") >= player(enemyID,"y")-10 and player(myID,"mousemapy") <= player(enemyID,"y")+10
	if inrangex and inrangey then
		parse("hudtxt 0 Yes")
	else
		parse("hudtxt 0 No")
	end
end
always for things which update UI stuff. That will cause TONS of traffic and lead to very bad conditions when many players are on the server.I guess
ms100 (that's 10 times a second instead of 50 times a second) should be ok too.Even better would be to save the displayed state and to only call that parse("hudtxt ...") (or whatever you do to visualize things on the client side) when the displayed stuff really changed.
DC has writtenI guess
ms100 (that's 10 times a second instead of 50 times a second) should be ok too.
ms100 (that's 10 times a second instead of 50 times a second) should be ok too.Isn't the always hook running 60 times a second?
Also it's sometimes a little higher (62~) or lower.
Mami Tomoe: It makes sense to assume that due to the increased "new" FPS cap at 60 but no, it has been capped at 50 executions in order to keep it compatible with older CS2D versions which had the 50 FPS cap.It's documented here
always
1

Offline