Jump to content


Please Help. RPG Health/Mana Potion Trigger


  • Please log in to reply
4 replies to this topic

#1 bswolgast

bswolgast
  • Guests

Posted 30 July 2012 - 02:50 PM

I am a newbie at writing programs with AHK.
I have gotten other peoples to work but never written one myself.
I have been reading quite a bit but I can’t seem to figure it out.
Maybe some of you Pros can help me write this.

What I want is an RPG Heal/Mana Potion Helper.
When my Health or Mana gets low I would like it to trigger the use of a potion to replenish.
I thought this would be easy, but it turns out not to be that easy for me.

I thought it could prompt to click the pixel (or the level of Health/Mana) and also prompt witch button to trigger.
If that pixel changes color (say from red to black) then it would trigger the use of the potion.

It would essentially have to prompt twice. Once for the Health bar / Potion button and one or the Mana side.

This could be used many different RPG's.
Please help me with this, I think it would be awesome to use with any RPG.

#2 bswolgast

bswolgast
  • Guests

Posted 31 July 2012 - 04:23 PM

Here is the script that I made for this.
It does not work.
Keeps spamming command 1 and 2 even if the pixel hasn't changed.
Please help.


; Script Name: RPG Pixel Trigger
; Description: Sends a command when the chosen pixel changes color.
; Purpose: Automaticaly uses potion to replenish health and mana in any RPG game.
; Version: 1.0
; Author: bswolgast
; Note: Help displayed on startup or by pressing Ctrl+Alt+H

; fresh variables
triggerset1 := 0
triggerset2 := 0

; default variables
command1 := 1
command2 := 2
shortwait := 10
longwait := 2000

; functions
showhelp(timeout) {
Msgbox, 0, Help, Press Ctrl+Alt+:`n`t[Z] - sets trigger1 pixel`n`t[A] - sets trigger2 pixel`n`t[S] - sets command1`n`t[T] - sets command2`n`t[P] - exits script`n`t[H] - displays this menu, %timeout%
Sleep, shortwait
return
}

showhelp(20)

Loop 
{
	
If (triggerset1 = 1 and (triggerset2 = 1)) 
{
	PixelGetColor, getcolor1, Xpos1, Ypos1
	Sleep, shortwait
		
	If %setcolor1% = %getcolor1%
	{
		Sleep, shortwait
	}

	Else
		send %command1%
		sleep, longwait

	PixelGetColor, getcolor2, Xpos2, Ypos2
	Sleep, shortwait
		
	If %setcolor2% = %getcolor2% 
	{
		Sleep, shortwait
	}

	Else
		send %command2%
		sleep, longwait
	
}

Else
	If Triggerset1 = 0
	{
		Msgbox, Please Set Trigger1!
		Sleep, longwait
		
	}
	Else
		Msgbox, Please Set Trigger2!
		Sleep, longwait
		
}

return

^!z::
; sets trigger1 pixel

MouseGetPos, Xpos1, Ypos1
PixelGetColor, setcolor1, Xpos1, Ypos1
triggerset1 := 1
Msgbox, 0, Trigger1 set!, Trigger color %setcolor1% set at %Xpos1%`,%Ypos1%., .75
Sleep, 1500
return


^!a::
; sets trigger2 pixel

MouseGetPos, Xpos2, Ypos2
PixelGetColor, setcolor2, Xpos2, Ypos2
triggerset2 := 1
Msgbox, 0, Trigger2 set!, Trigger color %setcolor2% set at %Xpos2%`,%Ypos2%., .75
Sleep, 1500
return


^!s::
; sets command1

InputBox, command1, Input Command1, %erstr%Enter the command if trigger1 is set off.Sleep, shortwait
return


^!t::
; sets command2

InputBox, command2, Input Command2, %erstr%Enter the command if trigger2 is set off.Sleep, shortwait
return


^!p::
; exit script
ExitApp
return


^!h::
; help message
showhelp(20)
Sleep, shortwait
return



#3 bswolgast

bswolgast
  • Guests

Posted 01 August 2012 - 05:16 PM

I changed the script and made it a little simpler.
This seems to work now.
Any feedback is greatly appreciated.


;;Script Name: RPG Pixel Trigger
;;Description: Sends a key stroke when the chosen pixel changes color.
;;Purpose: Automaticaly uses potion to replenish health and mana in any RPG game.
;;Version: 1.1
;;Author: bswolgast
;;Note: Help displayed on startup or by pressing Ctrl+Alt+H

showhelp(20)

#Persistent
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
return

;;Show Functions
showhelp(timeout) 
{
Msgbox, 0, Help, Press Ctrl+Alt+:`n`t[Left Click] - Sets Trigger Pixel 1`n`t[Right Click] - Sets Trigger Pixel 2`n`t[Z] - Starts Pixel Change Check`n`t[Esc] - Exits Script`n`t[H] - Displays This Menu, %timeout%
return
}

^!LButton::
;;(Ctl Alt Left Click) Gets color and asks for Key imput for the first trigger
MouseGetPos, xpos1, ypos1
PixelGetColor, Color1, %xpos1%, %ypos1%
InputBox, Key1, Input Command, %erstr%Enter the key to press if pixel changes.
return

^!RButton::
;;(Ctl Alt Right Click) Gets color and asks for Key imput for the second trigger
MouseGetPos, xpos2, ypos2
PixelGetColor, Color2, %xpos2%, %ypos2%
InputBox, Key2, Input Command, %erstr%Enter the key to press if pixel changes.
return

^!z::
;;(Ctl Alt Z) Starts the checking process
Loop
{
	PixelGetColor, Check1, %xpos1%, %ypos1%
	PixelGetColor, Check2, %xpos2%, %ypos2%
	
	if Color1 != %Check1%
	{
		;; MsgBox, "Color1 has changed" ;; DEBUG line
		Send, %Key1%
		Sleep, 2000
	}
	
	if Color2 != %Check2%
	{
		;; MsgBox, "Color2 has changed" ;; DEBUG line
		Send, %Key2%
		Sleep, 2000
	}
}
return

^!h::
;;(Ctl Alt H) Shows the help message
showhelp(20)
return

^!esc::
;;(Ctl Alt Esc) Exits the App
exitapp
return



#4 bswolgast

bswolgast
  • Guests

Posted 02 August 2012 - 05:22 PM

I made some revisions to this script.
This revision may not be best for all games you can always go back to v1.1.

Pixel 1 must be Red in color.
Pixel 2 must be Blue in color.

This seems to help with some games where the health or mana bar changes color a little, automatically triggering the script.

If you have any feedback, please post it.
I am new to this and would like to learn.


;;Script Name: RPG Pixel Trigger
;;Description: Sends a key stroke when the chosen pixel changes color.
;;Purpose: Automaticaly uses potion to replenish health and mana in any RPG game.
;;Version: 1.2
;;Author: bswolgast
;;Note: Help displayed on startup or by pressing Ctrl+Alt+H

showhelp(20)

#Persistent
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
return

;;Show Functions
showhelp(timeout) 
{
Msgbox, 0, Help, Press Ctrl+Alt+:`n`t[Left Click] - Sets Pixel 1 RED ONLY`n`t[Right Click] - Sets Pixel 2 BLUE ONLY`n`t[Z] - 

Starts Pixel Change Check`n`t[Esc] - Exits Script`n`t[H] - Displays This Menu, %timeout%
return
}

^!LButton::
;;(Ctl Alt Left Click) Gets color and asks for Key imput for the first trigger
MouseGetPos, xpos1, ypos1
InputBox, Key1, Input Command, %erstr%Enter the key to press if RED pixel changes.
return

^!RButton::
;;(Ctl Alt Right Click) Gets color and asks for Key imput for the second trigger
MouseGetPos, xpos2, ypos2
InputBox, Key2, Input Command, %erstr%Enter the key to press if BLUE pixel changes.
return

^!z::
;;(Ctl Alt Z) Starts the checking process
Loop
{
	PixelGetColor, Color1, %xpos1%, %ypos1%, BGR
	Color1 := (Color1 & 0xFF)
        if (Color1 < 0x80)
	{
		;;Tooltip, "Color1 has changed" ;; DEBUG line
		Send, %Key1%
		Sleep, 4000
	}
	PixelGetColor, Color2, %xpos2%, %ypos2%, RGB
	Color2 := (Color2 & 0xFF)
        if (Color2 < 0x80)
	{
		;;Tooltip, "Color2 has changed" ;; DEBUG line
		Send, %Key2%
		Sleep, 4000
	}
}
return

^!h::
;;(Ctl Alt H) Shows the help message
showhelp(20)
return

^!esc::
;;(Ctl Alt Esc) Exits the App
exitapp
return



#5 Scytale

Scytale
  • Members
  • 3 posts

Posted 24 August 2012 - 06:11 PM

It looks fine to me. One thing I might offer as an option is a different way of handling your color checks. I like to use PixelSearch because it a variation value built into the function. That's really handy for games since these areas will often be a little transparent or affected by lighting. I typically make a function like this:

; Returns TRUE if the pixel has the requested color (x, y, color, variation)
PixelPresent(pixelinfo) {
  local x, y, pixel, flag
  
  flag := false
  pixelsearch, x, y, pixelinfo[1], pixelinfo[2], pixelinfo[1], pixelinfo[2], pixelinfo[3], pixelinfo[4]
  if (not errorlevel)
    flag := true

  return flag
}

I pass into it an array that is defined like this:

global targetlocation := [1337,999,0x2B33C2,20]

Another trick I like to define in your script the "top" and "bottom" locations of the health or mana bar. Now if you have a color value (red or blue or whatever), you can pretty easily check for a percentage value without having to store coordinates for each one. So you might do one thing if it's below 80% or another if it's below 20%.