OSRS Ahk - Clicking on a monster in random spot
-
- Posts: 4
- Joined: 06 Mar 2024, 15:54
OSRS Ahk - Clicking on a monster in random spot
Hi all, I am creating a script for a game I play, old school runescape. I am looking to make a script that clicks on monsters in the game. Please see below I have screenshot a of a couple monsters which I have hilighted in red so I can easily detect them using a pixel search looking for the red color. The issue is there is more than 1 monster that has to be hilighted and they move around, not just sit still.
If mousemove to the pixel it goes to the first pixel at the top of the monster very oddly and I feel like the script will be easily detectable. Is there any simple code I can do to make it click on a random spot in the red pixels? not just the first one it finds?
Thank you for your help.
https://imgur.com/a/rpPVFAW
[Mod edit: Removed duplicate links with img-tags which only work with direct image links, not embedded pictures.]
[Mod edit: Moved topic from 'Scripts and Functions (v2)' to help subforum, since this is neither script nor function but a help request.]
If mousemove to the pixel it goes to the first pixel at the top of the monster very oddly and I feel like the script will be easily detectable. Is there any simple code I can do to make it click on a random spot in the red pixels? not just the first one it finds?
Thank you for your help.
https://imgur.com/a/rpPVFAW
[Mod edit: Removed duplicate links with img-tags which only work with direct image links, not embedded pictures.]
[Mod edit: Moved topic from 'Scripts and Functions (v2)' to help subforum, since this is neither script nor function but a help request.]
-
- Posts: 4
- Joined: 06 Mar 2024, 15:54
Re: OSRS Ahk - Clicking on a monster in random spot
bump - anyone?
- WarlordAkamu67
- Posts: 232
- Joined: 21 Mar 2023, 06:52
Re: OSRS Ahk - Clicking on a monster in random spot
Hello. PixelSearch returns the value of the first found pixel. It would be possible to use PixelGetColor across the entire window and capture each red pixel, then pick a random one using the Random function. This would be an extremely slow process, though.
You can also try a library such as ImagePut by isahound using the PixelSearchAll method. This is where you would, again, use the Random function select a random array element.
You can also try a library such as ImagePut by isahound using the PixelSearchAll method. This is where you would, again, use the Random function select a random array element.
-
- Posts: 4
- Joined: 06 Mar 2024, 15:54
Re: OSRS Ahk - Clicking on a monster in random spot
Thank you for your response, I am very new to AHK and writing these scripts as I have no background in it, but do enjoy. Is there anyway you could altar this to try as you mentioned? I am not familiar with those functions how they work/how to use them... this is what I currently have but it only works if there is 1 red shape on screen and the shape has to be a square or rectangle.WarlordAkamu67 wrote: ↑07 Mar 2024, 11:32Hello. PixelSearch returns the value of the first found pixel. It would be possible to use PixelGetColor across the entire window and capture each red pixel, then pick a random one using the Random function. This would be an extremely slow process, though.
You can also try a library such as ImagePut by isahound using the PixelSearchAll method. This is where you would, again, use the Random function select a random array element.
Current script:
Code: Select all
Loop {
MouseSpeed:=RandomWeight(0.5, 0.6, 0.8)
PixelSearch, Px, Py, 60, 35, 1080, 659, 0x0000FF, 1, Fast
; PixelSearch, Px2, Py2, 1080, 659, 60, 35, 0x0000FF, 1, Fast
CenterTileX:=((Px+Px2)/2)
CenterTileY:=((Py+Py2)/2)
CenterTileRandomX:=(Px2-Px)/2
CenterTileRandomY:=(Py2-Py)/2
if (ErrorLevel = 0) {
MouseMove Px, Py
; MoveMouse(CenterTileX + RandomWeight(-CenterTileRandomX, 0, CenterTileRandomX), CenterTileY + RandomWeight(-CenterTileRandomY, 0, CenterTileRandomY), MouseSpeed)
Sleep 100
click
break
}
}
[Mod edit: Moved topic from AHK v2 to v1 help based on the posted code. This is v1 code.]
Re: OSRS Ahk - Clicking on a monster in random spot
@zemplarius, I moved your topic from AHK v2 help to v1 help since you posted v1 code. If you want help regarding v2 nonetheless (it's the main release now after all and v1 won't get developed any further), please state that.
Also, please use code tags when you post code (fifth button from the left in the 'Full Editor'). Thank you!
Also, please use code tags when you post code (fifth button from the left in the 'Full Editor'). Thank you!
- WarlordAkamu67
- Posts: 232
- Joined: 21 Mar 2023, 06:52
Re: OSRS Ahk - Clicking on a monster in random spot
The links I provided contain information on the functions and how to use them, for version 2 of AHK. The code you posted uses the same function (command in v1), PixelSearch. What version do you want to write in?
-
- Posts: 4
- Joined: 06 Mar 2024, 15:54
Re: OSRS Ahk - Clicking on a monster in random spot
v1 please.WarlordAkamu67 wrote: ↑12 Mar 2024, 06:32The links I provided contain information on the functions and how to use them, for version 2 of AHK. The code you posted uses the same function (command in v1), PixelSearch. What version do you want to write in?
- WarlordAkamu67
- Posts: 232
- Joined: 21 Mar 2023, 06:52
Re: OSRS Ahk - Clicking on a monster in random spot
It has been awhile since I have used v1. Like I said before, without utilizing a library or some other script, writing your own script is doable; however, it is a slow process. The code below is what I have come up with. You may want to change the CoordMode to window or something. Another option, if you know the min size of the blocks or other properties, is to just find a side/corner and add a random amount to it.
Code: Select all
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
red_Pixels := getAllPixels(100,45,100,46,0xFF0000)
pixel_Length := red_Pixels.Length()
if (pixel_Length > 0) {
MsgBox % "Done with a length of " pixel_Length
Random, random_Place, 0, pixel_Length
MouseMove, red_Pixels[random_Place][1], red_Pixels[random_Place][2]
} else {
MsgBox, No match found!
}
return
; Function that returns an array.
getAllPixels(minX, minY, maxX, MaxY, useColor) {
CoordMode, Pixel, Screen
temp_Array := []
evaluate_Color := 0
x_Now := minX
y_Now := minY
while (y_Now < maxY) {
while (x_Now < maxX) {
PixelGetColor, evaluate_Color, x_Now, y_Now, RGB
if (evaluate_Color == useColor) {
temp_Array.Push([x_Now, y_Now])
}
x_Now++
}
x_Now := minX
y_Now++
}
return temp_Array
}
/*
Loop {
MouseSpeed:=RandomWeight(0.5, 0.6, 0.8)
PixelSearch, Px, Py, 60, 35, 1080, 659, 0x0000FF, 1, Fast
; PixelSearch, Px2, Py2, 1080, 659, 60, 35, 0x0000FF, 1, Fast
CenterTileX:=((Px+Px2)/2)
CenterTileY:=((Py+Py2)/2)
CenterTileRandomX:=(Px2-Px)/2
CenterTileRandomY:=(Py2-Py)/2
if (ErrorLevel = 0) {
MouseMove Px, Py
; MoveMouse(CenterTileX + RandomWeight(-CenterTileRandomX, 0, CenterTileRandomX), CenterTileY + RandomWeight(-CenterTileRandomY, 0, CenterTileRandomY), MouseSpeed)
Sleep 100
click
break
}
}
*/