Make Code shorter? more efficient?

Ask gaming related questions
Ragnar_White
Posts: 1
Joined: 01 Jul 2020, 19:16

Make Code shorter? more efficient?

01 Jul 2020, 19:36

Hi, my script is working, but i want to make it shorter if possible, also more efficient?

So my first Question is can you write PixelGetColor directly into the if statement? If so, how?
Also, can i get rid of all those "else if", by rewriting the if with some "OR ||" operators?

Something like this?

Code: Select all

if (PixelGetColor, actv1, 1646, 8 == 0xFFFFFF && PixelGetColor, actv2, 1715, 13 == 0xFFFFFF && PixelGetColor, actv3, 1810, 13 == 0xFFFFFF || PixelGetColor, activ1, 1670, 13 == 0xFFFFFF && PixelGetColor, activ2, 1649, 8 == 0xFFFFFF && PixelGetColor, activ3, 1614, 13 == 0xFFFFFF and so on and so on...){
	inTown := true
}else{
	inTown := false
}

This is the working code

Code: Select all

#IfWinActive, Diablo III
#SingleInstance
#NoEnv

inTown := false

SetTimer, Spam, 333 ;start and restart every time D3 wasnt active


	
Spam:
	While (WinActive("Diablo III")){
		
		PixelGetColor, chat, 39, 891 ;0x001050
		
		PixelGetColor, tp, 1051, 324 ;0x242A2E
	
		PixelGetColor, 1cd, 654, 1011 ;0x3B1F3B oder 0x8164AD
		PixelGetColor, 2on, 750, 997 ;0x5B595A
		PixelGetColor, 3cd, 787, 1011 ;0x0D176D oder 0x090101
		PixelGetColor, 4on, 884, 993 ;0x595656
	
		PixelGetColor, actv1, 1646, 8 ;0xFFFFFF
		PixelGetColor, actv2, 1715, 13 ;0xFFFFFF
		PixelGetColor, actv3, 1810, 13 ;0xFFFFFF
		PixelGetColor, activ1, 1670, 13 ;0xFFFFFF
		PixelGetColor, activ2, 1649, 8 ;0xFFFFFF
		PixelGetColor, activ3, 1614, 13 ;0xFFFFFF
		PixelGetColor, actii1, 1773, 13 ;0xFFFFFF
		PixelGetColor, actii2, 1769, 13 ;0xFFFFFF
		PixelGetColor, actii3, 1888, 13 ;0xFFFFFF
		PixelGetColor, acti1, 1749, 9 ;0xFFFFFF
		PixelGetColor, acti2, 1781, 13 ;0xFFFFFF
		PixelGetColor, acti3, 1815, 13 ;0xFFFFFF
		
		PixelGetColor, invopen, 1908, 876 ;0x123951 inventory or friends list
		
		if (actv1 == 0xFFFFFF && actv2 == 0xFFFFFF && actv3 == 0xFFFFFF){  ;check if player in town
			inTown := true
		}else if (activ1 == 0xFFFFFF && activ2 == 0xFFFFFF && activ3 == 0xFFFFFF){
			inTown := true
		}else if (actii1 == 0xFFFFFF && actii2 == 0xFFFFFF && actii3 == 0xFFFFFF){
			inTown := true
		}else if  (acti1 == 0xFFFFFF && acti2 == 0xFFFFFF && acti3 == 0xFFFFFF){
			inTown := true
		}else{
			inTown := false
		}
		
		if (chat != 0x001050 && tp != 0x242A2E && !inTown && invopen != 0x123951 && invopen != 0x030813){  ;if player isnt using townportal/cahtting/in town, inventory or friendlist not open
		
			
			if(1cd == 0x3B1F3B || 1cd == 0x8164AD){ ;press 1 if ready
				Send {1 down}
				Sleep, 50
				Send {1 up}
				Sleep, 50
			}
			if (2on != 0x5B595A){ ;press 2 if skill isnt active
				Send {2 down}
				Sleep, 50
				Send {2 up}
				Sleep, 50
			}
			if(3cd == 0x0D176D || 3cd == 0x090101){ ;press 3 if ready
				Send {3 down}
				Sleep, 50
				Send {3 up}
				Sleep, 50
			}
			if(4on != 0x595656){ ;press 4 if skill isnt active
				Send {4 down}
				Sleep, 50
				Send {4 up}
				Sleep, 50
			}
		}
	}
	
Also I am unsure whether its more efficient to start with Loop {...} or Settimer, Spam, 333 Spam: ... Any suggestions on that?
Rohwedder
Posts: 3232
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Make Code shorter? more efficient?

02 Jul 2020, 00:30

Hallo,
perhaps something like this?

Code: Select all

inTown := (PGC(1646, 8) && PGC(1715, 13) && PGC(1810, 13))
		||(PGC(1670, 13) && PGC(1649, 8) && PGC(1614, 13))
		||(PGC(1773, 13) && PGC(1769, 13) && PGC(1888, 13))
		||(PGC(1749, 9) && PGC(1781, 13) && PGC(1815, 13))
		

PGC(X, Y, Color:= 0xFFFFFF)
{ ;checks if (X, Y) is White or has the Color
    PixelGetColor, Is, X, Y
    if !ErrorLevel
        return, Color = Is
}

Return to “Gaming”

Who is online

Users browsing this forum: Dorsi, Starker and 11 guests