Jump to content

Welcome to Gaming On Steroids Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

GoS EXT QoL Mouse Class source


  • Please log in to reply
5 replies to this topic

#1
InsidiousQuack

InsidiousQuack

    Advanced Member

  • Contributor
  • 138 posts
  • LocationLondon

I wrote this small mouse class to deal with the problem of user mouse movement being lost by scripts which just move the mouse back to where it was before they interacted with it. Hopefully it should mean that any mouse movement made while the script has moved the mouse will persist to the mouse location after the script moves it back using this mouse class if you integrate it into your scripts.

Posting so you guys can test and share improvements to it, I couldn't get conclusive results on how effective it was but my personal scripts felt a lot better once it was added.
Source code:

class "Mouse"

	function Mouse:__init()
		self.ActualPos = cursorPos
		self.ScriptPos = cursorPos
		self.MousePosLastTick = cursorPos
		self.mouseReleaseDifference = Vector(0,0)

		Callback.Add("Draw", function() self:Update() end)
	end

	function Mouse:Update()
		if self.MousePosLastTick ~= cursorPos then
			self:Moved()
		end

		self.MousePosLastTick = cursorPos

		--Draw.Text("cursorPos", cursorPos+Vector(100, 100))
		Draw.Text("ActualPos", self.ActualPos)
		Draw.Text("ScriptPos", (self.ScriptPos+Vector(20, 200)))
	end

	function Mouse:SetMousePos(pos) -- accepts vector2 or vector3
		self.IgnoreNextMovement = true
		pos2 = pos:To2D()
		self.ScriptPos = Vector(pos2.x, pos2.y, cursorPos.z)
		Control.SetCursorPos(pos)
	end

	function Mouse:Moved()
		if ScriptControllingMouse == false then
			self.ActualPos = cursorPos
		elseif ScriptControllingMouse == true then
			local mouseDifference = cursorPos - self.ScriptPos
			self.mouseReleaseDifference = mouseDifference*2
		end
	end

	function Mouse:ScriptStartedControlling()
		self.mouseReleaseDifference = Vector(0,0)
		self.ActualPos = cursorPos

		ScriptControllingMouse = true
	end

	function Mouse:ScriptFinishedControlling(addReleaseDifference)
		ScriptControllingMouse = false
		if addReleaseDifference==nil then addReleaseDifference = true end

                if addReleaseDifference then
		    self.ActualPos = self.ActualPos + self.mouseReleaseDifference
                end
		self.mouseReleaseDifference = Vector(0,0)

		local posX, posY = self.ActualPos.x, self.ActualPos.y

		Control.SetCursorPos(posX, posY)
	end

GameMouse = Mouse()

 

How to use: Just copy pasting the sourecode means it will update itself as it adds callbacks when it initiates.

 

 

When you want to control the players mouse, you use the Started, Stopped and SetMousePos functions, example implementation:

function Orbwalker:Attack(unit)
	if not self:CanOrb(unit) then return end

	self.Attacking = true
	GameMouse:ScriptStartedControlling(true)


	if unit.type == Obj_AI_Hero then
		Control.KeyDown(HK_TCO)
	end

	local diff = Vector(0,0,0)

	if unit.type == Obj_AI_Minion then
		diff =Vector(0, 20, 0) --Clicks up a little bit to avoid some of the awkward misclicks.
	end

	GameMouse:SetMousePos(unit.pos + diff)

	DelayAction(function()

		self:RightClick()
		self.LastAttack = Game.Timer()
		self.Attacking = true

		DelayAction(function()

			Control.KeyUp(HK_TCO)
			self.Attacking = false
			GameMouse:ScriptFinishedControlling()
			self:AfterAttack()
		end, .001)

	end, .001)

end

Like stated earlier please give feedback and share improvements that you make.

Some ideas for something that could be added is a time based curve movement function for smooth mouse movement towards pos with duration of curve movement being given to the function. This would make EXT much more available to being used while streaming(if someone actually wants to do that).

For some reason GOS wont set the cursor pos back to actual pos at the end, but there's no error, does someone know why this is?

edit: this was caused by Control.SetCursorPos being broken for 2D vectors.



ATM this is better for large movements scripts would make like moving the mouse to cast spells or attack units, for small movements like orbwalkers moving the character it makes controlling the mouse feel a bit "sticky" on the user's end, if someone fixes it please post. Temporarily when calling ScriptFinishedControlling for very frequent mouse movements (i.e orbwalkers moving the mouse when not autoattacking) just pass false to it.


  • 5

#2
WeeepixeL

WeeepixeL

    Advanced Member

  • Members
  • 239 posts

:o 


  • 0

#3
Munk

Munk

    Member

  • Members
  • 28 posts

I get confused as balls when reading smart-code-person threads like these.

 

1.) How do I get it into my loader

2.) Do I have to add anything to the code to make it work


  • 0

#4
InsidiousQuack

InsidiousQuack

    Advanced Member

  • Contributor
  • 138 posts
  • LocationLondon

I get confused as balls when reading smart-code-person threads like these.

 

1.) How do I get it into my loader

2.) Do I have to add anything to the code to make it work

This post is more aimed at people writing scripts who know what they're doing.
If there is a specific script you would like to see it in, please ask the script creator to add this feature and link them to this post.

1) The class code should be added to a script and then the functions and variables can be used by the script

2) you would have to edit the script to incorporate the code into it correctly else it wouldn't work.


  • 0

#5
Raine

Raine

    ‌‌

  • Contributor
  • 468 posts

I've been waiting a lot for someone to make cursor-related solutions. 

 

The three things I always felt External needs: 

- Something that rescues pre-mouse alteration position properly, as sometimes it just "doesn't come back" to the original spot.

- Something that makes sure the proper mouse position isn't altered by another mouse position alteration from another script (most typical example: evade forcing skillshots/flash in wrong places).

- Some kind of smooth mouse movement simulator, with adjustable speed. Imagine being able to play in LAN or even streaming with a legit cursor. I couldn't stream Xerath since, even with hidden cursor, it still displays the charging Q and R drawings. 

 

Thank you very much for your hard work. If you need support or feedback, just tell me. 


  • 0

#6
InsidiousQuack

InsidiousQuack

    Advanced Member

  • Contributor
  • 138 posts
  • LocationLondon

GOS doesn't run scripts simultaneously, when you bind to the ontick callback it adds that action to a table of actions and then loops through that table every 1/tickrate seconds and runs the action at that index. This means the second problem is more of a symptom of the first problem than an actual problem in and of itself.

It's also a symptom of people using DelayAction for mouse control.

 

I'll try to go about adding an optional feature to sort of block mouse movement while still storing any movement the player makes, but if you use it it would require you calling mouseMoved in OnDraw rather than OnTick just to get farrr smoother results as well as make the class more self contained so that you dont need to add code to your scripts onTick, just copy and paste the class and then use it's start setmousepos and stop functions.

 


  • 1




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users