Jump to content

[HELP] Cursor tracking


DNaumov

Recommended Posts

Posted

 

Good afternoon, how can I make the cursor react only in a certain position? That part is circled on the screen, if the cursor is on it, then it is necessary that it grows

 

I am writing through a translator, sorry for my English

Example

 

  • Moderators
Posted

Hi!

You can get the rotation difference between cursor and center of the menu.
And from this rotation you know which button is active.

Use findRotation to get the rotation difference,

 

GheVe86.png

  • Thanks 1
Posted
3 minutes ago, Patrick said:

Здравствуй!

Вы можете получить разницу вращения между курсором и центром меню.
И из этого вращения вы знаете, какая кнопка активна.

Используйте  findRotation, чтобы получить разницу вращения,

 

GheVe86.png

Thanks for the help, but I'm new to this business, if it's not difficult, could you write a small example?
  • Moderators
Posted
2 minutes ago, DNaumov said:

Thanks for the help, but I'm new to this business, if it's not difficult, could you write a small example?

Maybe, paste here your current code, and upload the image what you use.

  • Thanks 1
Posted
2 minutes ago, Patrick said:

Может быть, вставьте сюда свой текущий код и загрузите изображение, которое вы используете.

function drawRadial()
	dxDrawImage(741*scr.x,320*scr.y,438*scr.x,439*scr.y,'assets/circle.png',0,0,0,tocolor(30,30,30,160))
	
	dxDrawImage(741*scr.x,317*scr.y,438*scr.x,439*scr.y,circle2,1,0,0,tocolor(30,30,30,160))
	dxDrawImage(745*scr.x,319*scr.y,438*scr.x,439*scr.y,circle2,73,0,0,tocolor(30,30,30,160))
	dxDrawImage(745*scr.x,322*scr.y,438*scr.x,439*scr.y,circle2,145,0,0,tocolor(30,30,30,160))
	dxDrawImage(741*scr.x,325*scr.y,438*scr.x,439*scr.y,circle2,217,0,0,tocolor(30,30,30,160))
	dxDrawImage(737*scr.x,322*scr.y,438*scr.x,439*scr.y,circle2,289,0,0,tocolor(30,30,30,160))
	
	dxDrawBorderedText('МЕНЮ ТРАНСПОРТА',845*scr.x,264*scr.y,845*scr.x,264*scr.y,tocolor(255,255,255,255),1,font1s)
	dxDrawBorderedText('BANSHEE',920*scr.x,290*scr.y,845*scr.x,264*scr.y,tocolor(175,175,175,255),0.8,font1s)
	
	dxDrawText('Починить',998*scr.x,425*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)
	dxDrawText('Перевернуть',1030*scr.x,572*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)
	dxDrawText('Заглушить\nдвигатель',930*scr.x,910*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s,'center','center')
	dxDrawText('Включить\nгабариты',660*scr.x,745*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s,'center','center')
	dxDrawText('Запереть двери',795*scr.x,425*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)
	
	if isCursor(978*scr.x,529*scr.y,109*scr.x,66*scr.y) then
		dxDrawRectangle(100,100,100,100)
	end
	
	dxDrawImage(901*scr.x,480*scr.y,117*scr.x,119*scr.y,'assets/circle.png',0,0,0,tocolor(10,10,10,255))
	if getKeyState("mouse1") then isButtonClick = true else isButtonClick = false end
end

Assets

  • Moderators
Posted

@DNaumov Here it is, I hope you understand this. Feel free to ask.

 

local screen = Vector2( guiGetScreenSize() )
local scr = Vector2( screen.x/1920, screen.y/1080 )

circle2 = dxCreateTexture('assets/circle2.png','dxt1')
fileDelete ('assets/circle2.png')

-- Slice rotation ranges
local slices = {
	{0, 70, "1st"},
	{71, 143, "2nd"},
	{144, 216, "3rd"},
	{217, 290, "4th"},
	{291, 360, "5th"},
}

function getActiveSlice(rot)
	rot = math.floor(rot)
	for i = 1, #slices do
		if rot >= slices[i][1] and rot <= slices[i][2] then -- cursor is between this slice range
			return slices[i][3]
		end
	end
	return false
end

function drawRadial()
	dxDrawImage(741*scr.x,320*scr.y,438*scr.x,439*scr.y,'assets/circle.png',0,0,0,tocolor(30,30,30,160))
	
	local cx, cy = getCursorPosition()
	local cx, cy = cx * screen.x, cy * screen.y -- cursor absolute position
	local rot = findRotation(cx, cy, screen.x/2, screen.y/2) -- get rotation difference between center of the menu and cursor

	local active = getActiveSlice(rot) -- get active button
	if active == "1st" then
		dxDrawImage(741*scr.x,317*scr.y,438*scr.x,439*scr.y,circle2,1,0,0,tocolor(30,30,30,160))
	elseif active == "2nd" then
		dxDrawImage(745*scr.x,319*scr.y,438*scr.x,439*scr.y,circle2,73,0,0,tocolor(30,30,30,160))
	elseif active == "3rd" then
		dxDrawImage(745*scr.x,322*scr.y,438*scr.x,439*scr.y,circle2,145,0,0,tocolor(30,30,30,160))
	elseif active == "4th" then
		dxDrawImage(741*scr.x,325*scr.y,438*scr.x,439*scr.y,circle2,217,0,0,tocolor(30,30,30,160))
	elseif active == "5th" then
		dxDrawImage(737*scr.x,322*scr.y,438*scr.x,439*scr.y,circle2,289,0,0,tocolor(30,30,30,160))
	end
	
	dxDrawBorderedText('МЕНЮ ТРАНСПОРТА',845*scr.x,264*scr.y,845*scr.x,264*scr.y,tocolor(255,255,255,255),1,font1s)
	dxDrawBorderedText('BANSHEE',920*scr.x,290*scr.y,845*scr.x,264*scr.y,tocolor(175,175,175,255),0.8,font1s)
	
	dxDrawText('Починить',998*scr.x,425*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)
	dxDrawText('Перевернуть',1030*scr.x,572*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)
	dxDrawText('Заглушить\nдвигатель',930*scr.x,910*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s,'center','center')
	dxDrawText('Включить\nгабариты',660*scr.x,745*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s,'center','center')
	dxDrawText('Запереть двери',795*scr.x,425*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)
	
	dxDrawImage(901*scr.x,480*scr.y,117*scr.x,119*scr.y,'assets/circle.png',0,0,0,tocolor(10,10,10,255))
end
addEventHandler('onClientRender',root,drawRadial)

-- detect button press
addEventHandler("onClientClick", root, function(button, state)
	if button == "left" and state == "up" then
		local cx, cy = getCursorPosition()
		local cx, cy = cx * screen.x, cy * screen.y -- cursor absolute position
		local rot = findRotation(cx, cy, screen.x/2, screen.y/2) -- get rotation difference between center of the menu and cursor
	
		local active = getActiveSlice(rot) -- get active button
		if active then
			if active == "1st" then
				outputChatBox("You pressed the first button! (Починить)")
			end
		end
	end
end)

 

  • Thanks 1
Posted
1 minute ago, Patrick said:

@DNaumov Here it is, I hope you understand this. Feel free to ask.

 


local screen = Vector2( guiGetScreenSize() )local scr = Vector2( screen.x/1920, screen.y/1080 )circle2 = dxCreateTexture('assets/circle2.png','dxt1')fileDelete ('assets/circle2.png')-- Slice rotation rangeslocal slices = {	{0, 70, "1st"},	{71, 143, "2nd"},	{144, 216, "3rd"},	{217, 290, "4th"},	{291, 360, "5th"},}function getActiveSlice(rot)	rot = math.floor(rot)	for i = 1, #slices do		if rot >= slices[i][1] and rot <= slices[i][2] then -- cursor is between this slice range			return slices[i][3]		end	end	return falseendfunction drawRadial()	dxDrawImage(741*scr.x,320*scr.y,438*scr.x,439*scr.y,'assets/circle.png',0,0,0,tocolor(30,30,30,160))		local cx, cy = getCursorPosition()	local cx, cy = cx * screen.x, cy * screen.y -- cursor absolute position	local rot = findRotation(cx, cy, screen.x/2, screen.y/2) -- get rotation difference between center of the menu and cursor	local active = getActiveSlice(rot) -- get active button	if active == "1st" then		dxDrawImage(741*scr.x,317*scr.y,438*scr.x,439*scr.y,circle2,1,0,0,tocolor(30,30,30,160))	elseif active == "2nd" then		dxDrawImage(745*scr.x,319*scr.y,438*scr.x,439*scr.y,circle2,73,0,0,tocolor(30,30,30,160))	elseif active == "3rd" then		dxDrawImage(745*scr.x,322*scr.y,438*scr.x,439*scr.y,circle2,145,0,0,tocolor(30,30,30,160))	elseif active == "4th" then		dxDrawImage(741*scr.x,325*scr.y,438*scr.x,439*scr.y,circle2,217,0,0,tocolor(30,30,30,160))	elseif active == "5th" then		dxDrawImage(737*scr.x,322*scr.y,438*scr.x,439*scr.y,circle2,289,0,0,tocolor(30,30,30,160))	end		dxDrawBorderedText('МЕНЮ ТРАНСПОРТА',845*scr.x,264*scr.y,845*scr.x,264*scr.y,tocolor(255,255,255,255),1,font1s)	dxDrawBorderedText('BANSHEE',920*scr.x,290*scr.y,845*scr.x,264*scr.y,tocolor(175,175,175,255),0.8,font1s)		dxDrawText('Починить',998*scr.x,425*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)	dxDrawText('Перевернуть',1030*scr.x,572*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)	dxDrawText('Заглушить\nдвигатель',930*scr.x,910*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s,'center','center')	dxDrawText('Включить\nгабариты',660*scr.x,745*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s,'center','center')	dxDrawText('Запереть двери',795*scr.x,425*scr.y,998*scr.x,425*scr.y,tocolor(109,109,109,255),1,font2s)		dxDrawImage(901*scr.x,480*scr.y,117*scr.x,119*scr.y,'assets/circle.png',0,0,0,tocolor(10,10,10,255))endaddEventHandler('onClientRender',root,drawRadial)-- detect button pressaddEventHandler("onClientClick", root, function(button, state)	if button == "left" and state == "up" then		local cx, cy = getCursorPosition()		local cx, cy = cx * screen.x, cy * screen.y -- cursor absolute position		local rot = findRotation(cx, cy, screen.x/2, screen.y/2) -- get rotation difference between center of the menu and cursor			local active = getActiveSlice(rot) -- get active button		if active then			if active == "1st" then				outputChatBox("You pressed the first button! (Починить)")			end		end	endend)

 

Thank you!!!

  • IIYAMA locked this topic
  • Moderators
Posted (edited)

Locked, on request of the author.

Request 'delete'. But deleting the topic is unnecessary, since this section is not for private help.

Edited by IIYAMA
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...