------------------------------------------------ -- SETTINGS ------------------------------------------------ -- The minimum amount of health before the target needs healing. -- For example, at 80, any time the target is below 80% health, this bot will attempt to heal them. -- But only if it is not in movement, so if you need a heal, stop moving! minimum_health = 80; ------------------------------------------------ -- HOTKEYS ------------------------------------------------ startKey = key.VK_INSERT; stopKey = key.VK_DELETE; key_targetpartyleader = key.VK_F1; key_targetself = key.VK_F2; key_heal = key.VK_1; key_buff1 = key.VK_6; key_buff2 = key.VK_7; key_hp_potion = key.VK_8; key_mp_potion = key.VK_9; key_sp_potion = key.VK_0; ------------------------------------------------ -- BUFFS ------------------------------------------------ -- Set a buff to 0 if you don't want to use it buff1_time = minutesToTimer(10); -- Prayer buff2_time = minutesToTimer(15); -- Aura of Peace ------------------------------------------------ -- POTIONS ------------------------------------------------ -- All potion use values are specified in % -- Set the values to 0 to not use that potion HP_potion_use = 45; MP_potion_use = 45; SP_potion_use = 20; --[[********************************************************************* ************************************************************************** DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ************************************************************************** ************************************************************************]] ------------------------------------------------ -- Memory addresses ------------------------------------------------ playerptr_addr = 0x007835B4; HP_offset = 296; MaxHP_offset = 300; MP_offset = 304; MaxMP_offset = 308; SP_offset = 312; MaxSP_offset = 316; xOffset = 0x7835DC; yOffset = 0x783724; zOffset = 0x7835E4; targetid_addr = 0x0062FAD4; -- short, 65535 if none selected -- REMOVED -- targettype_addr = 0x00619B1F; -- byte, 0 = player/NPC, 7 = monster ------------------------------------------------ -- Variable setup ------------------------------------------------ HP = 10000; MaxHP = HP; MP = 10000; MaxMP = MP; SP = 10000; MaxSP = SP; lastX = 0; lastZ = 0; curX = 0; curZ = 0; buff1_ready = true; buff2_ready = true; ------------------------------------------------ -- Functions ------------------------------------------------ buff1_toggle = function () buff1_ready = true; end; buff2_toggle = function () buff2_ready = true; end; function use_hp_potion() keyboardPress(key_hp_potion); printf("Using HP potion\n"); end function use_mp_potion() keyboardPress(key_mp_potion); printf("Using MP potion\n"); end function use_sp_potion() keyboardPress(key_sp_potion); printf("Using SP potion\n"); end function update_vars() HP = memoryReadIntPtr(proc, playerptr_addr, HP_offset); MaxHP = memoryReadIntPtr(proc, playerptr_addr, MaxHP_offset); MP = memoryReadIntPtr(proc, playerptr_addr, MP_offset); MaxMP = memoryReadIntPtr(proc, playerptr_addr, MaxMP_offset); SP = memoryReadIntPtr(proc, playerptr_addr, SP_offset); MaxSP = memoryReadIntPtr(proc, playerptr_addr, MaxSP_offset); lastX = curX; lastZ = curZ; curX = memoryReadFloat(proc, xOffset); curZ = memoryReadFloat(proc, zOffset); end function have_target() local readid = memoryReadShort(proc, targetid_addr); return ( readid ~= 0xFFFF ); end -- Returns a float value of the health percentage. Ex 100% health is returned as 100, 70.3% health is returned as 70.3 -- This function assumes the target's health bar is moved to upper left corner of the screen and game is running in 1024x768 resolution. -- Depends on the Round() function. function getTargetHealth() local mob_health_start = {x=36, y=37}; local mob_health_end = {x=174, y=37}; local mob_total_health_pixels = 136; local l_hdc = get_hdc(); local rr,gg,bb; local a,b,c; -- a = start, b = middle, c = end a = mob_health_start["x"]; c = mob_health_end["x"]; local b = (c - a) / 2 + a; -- Find middle of health bar and start there rr,gg,bb = getPixel(l_hdc, mob_health_end['x'], mob_health_end["y"]); -- Check if full health if( rr > 0 ) then printf("Health = 100\n"); return 100; end rr,gg,bb = getPixel(l_hdc, mob_health_start['x'], mob_health_start["y"]); -- Check if zero health, target may not be dead! if( rr == 0 ) then printf("Health = 0\n"); return 0; end -- Health is between full and none, find it! while ( b ~= a and b ~= c ) do rr,gg,bb = getPixel(l_hdc, b, mob_health_end["y"]); if ( rr == 0 ) then c = b; -- Set the end to the middle b = ((b - a) / 2) + a; -- Half split the health bar in the negative x direction else a = b; -- Set the beginning to the middle b = ((c - b) / 2) + b; -- Half split the health bar in the positive x direction end b = math.floor(b); end local health_percent = (b - mob_health_start["x"]) / (mob_health_end["x"] - mob_health_start["x"]); health_percent = round(health_percent * 100, 1); --printf("Health = " .. health_percent .. "\n"); return health_percent; end function get_hdc() hdc = openDC(get_win()); return hdc; end function get_win() return win; end function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end function inMovement() if( lastX == curX and lastZ == curZ ) then return 0; end return 1; end ------------------------------------------------ -- MAIN ------------------------------------------------ function main() proc = openProcess(findProcessByExe("game.exe")); win = findWindow("Shaiya"); attach(win); setPriority(PRIORITY_HIGH); registerTimer("update_vars", 100, update_vars); if( buff1_time ) then registerTimer("buff1_toggle", buff1_time, buff1_toggle); end; if( buff2_time ) then registerTimer("buff2_toggle", buff2_time, buff2_toggle); end; while( true ) do yrest(500); if( inMovement() == 0 and have_target() and getTargetHealth() < 80 ) then keyboardPress(key_heal); yrest(2000); end if( buff1_ready and buff1_time > 0 ) then printf("buffing1\n"); keyboardPress(key_buff1); buff1_ready = false; yrest(2000); end; if( buff2_ready and buff2_time > 0 ) then printf("buffing2\n"); keyboardPress(key_buff2); buff2_ready = false; yrest(2000); end; if( (HP/MaxHP*100) < HP_potion_use and HP_potion_use > 0 ) then use_hp_potion(); end if( (MP/MaxMP*100) < MP_potion_use and MP_potion_use > 0 ) then use_mp_potion(); end if( (SP/MaxSP*100) < SP_potion_use and SP_potion_use > 0 ) then use_sp_potion(); end end end startMacro(main);