But i dont know what to edit
Code: Select all
-------------------------------------------------
-- Variable declaration -- do not edit
-------------------------------------------------
CLASS_WARRIOR = 0;
CLASS_MAGE = 1;
HP = 10000;
HPmax = HP;
MP = 10000;
MPmax = MP;
SP = 10000;
SPmax = SP;
HP_ptr = "020F2910";
HP_offset = 296;
HPmax_ptr = "020F2910";
HPmax_offset = 300;
MP_ptr = "020F2910";
MP_offset = 304;
MPmax_ptr = "020F2910";
MPmax_offset = 308;
SP_ptr = "020F2910";
SP_offset = 312;
SPmax_ptr = "020F2910";
SPmax_offset = 316;
-------------------------------------------------
-------------------------------------------------
-- character configuration
-------------------------------------------------
class = CLASS_DEFENDER;
key_attack = key.VK_1;
key_pickup = key.VK_2;
key_sit = key.VK_C;
key_skill1 = key.VK_3;
key_skill2 = key.VK_4;
key_skill3 = key.VK_5;
key_hppotion = key.VK_8;
key_mppotion = key.VK_9;
key_sppotion = key.VK_9;
-- rest or use potions when low on HP/MP/SP
HP_usepotion = 350;
MP_usepotion = 0;
SP_usepotion = 0;
HP_sit = 180;
MP_sit = 0;
SP_sit = 20;
-- chance to cast
skill1_chance = 100;
skill2_chance = 0;
skill3_chance = 0;
-- MP cost
skill1_cost = 38;
skill2_cost = 20;
skill3_cost = 80;
casttime = 2000;
-------------------------------------------------
function use_hppotion(2)
keyboardPress(key_hppotion);
end
function use_mppotion(3)
keyboardPress(key_mppotion);
end
function use_sppotion(2)
keyboardPress(key_sppotion);
end
-- so we aren't spamming the attack key...
-- we will use a timer to press it once
-- every 3 seconds.
function attack_timer(3000)
keyboardPress(key_attack);
end
function fight_warrior(2)
registerTimer("attack_timer", 3000, attack_timer);
while( have_target() ) do
if( HP < HP_usepotion ) then
use_hppotion(); end
if( MP < MP_usepotion ) then
use_mppotion(); end
if( SP < SP_usepotion ) then
use_sppotion(); end
yrest(100);
coroutine.yield();
end
unregisterTimer("attack_timer");
yrest(1000);
pickup(5);
end
function fight_mage()
while( have_target() ) do
if( HP < HP_usepotion ) then
use_hppotion(); end
if( MP < MP_usepotion ) then
use_mppotion(); end
if( SP < SP_usepotion ) then
use_sppotion(); end
local roll = math.random(100);
if( roll <= skill1_chance and MP >= skill1_cost ) then
-- cast skill 1
keyboardPress(key_skill1);
yrest(casttime);
else
keyboardPress(key_attack);
end
yrest(100);
coroutine.yield();
end
yrest(1000);
pickup(5);
end
-- heal until full HP & MP
function rest_heal(6)
local last_HP = HP;
keyboardPress(key_sit);
yrest(100);
while( HP < HPmax ) do
if( HP < last_HP ) then
print("Under attack! Exiting rest");
return;
else
last_HP = HP;
end
yrest(100);
coroutine.yield();
end
keyboardPress(key_sit);
yrest(1000);
end
-- pickup nearby items
function pickup(5)
for i = 1,5 do
keyboardPress(key_pickup);
yrest(500);
end
end
-- update client variables by reading from it's memory
function update_vars()
HP = memoryReadIntPtr(proc, HP_ptr, HP_offset);
HPmax = memoryReadIntPtr(proc, HPmax_ptr, HPmax_offset);
MP = memoryReadIntPtr(proc, MP_ptr, MP_offset);
MPmax = memoryReadIntPtr(proc, MPmax_ptr, MPmax_offset);
SP = memoryReadIntPtr(proc, SP_ptr, SP_offset);
SPmax = memoryReadIntPtr(proc, SPmax_ptr, SPmax_offset);
end
function have_target()
--1280*1024
-- X: 345, Y: 36
-- 16bit: 165, 24, 66
-- 32bit: 163, 25, 65
--1024*768
-- X: 258, Y: 36
-- 16bit: 165, 28, 66
-- 32bit: 165, 30, 68
local r,g,b;
-- use the window's rect to find the resolution
local wx,wy,ww,wh = windowRect(win);
if( ww == 1024 and wh == 768 ) then
r,g,b = getPixel(win, 258, 36);
elseif( ww == 1280 and wh == 1024 ) then
r,g,b = getPixel(win, 345, 36);
else
r,g,b = 0;
print("Unsupported resolution! Please use 1024*768 or 1280*1024.");
end
--printf("R: %d, G: %d, B: %d\n", r, g, b);
-- if there is still HP left in monster's HP bar...return true
if( r >= 160 and r <= 170 and g >= 20 and g <= 34 and b >= 63 and b <= 73) then
return true;
else
return false;
end
end
-------------------------------------------------
-- FUNCTION MAIN
-------------------------------------------------
function main()
proc = openProcess( findProcess("Shaiya") );
win = findWindow("Shaiya");
attach(win);
registerTimer("update_vars", 100, update_vars);
running = true;
while( running ) do
if( keyPressed(key.VK_F7) == 1 ) then
running = false; end
keyboardPress(key_attack);
if( have_target() ) then
if( class == CLASS_WARRIOR ) then
fight_warrior();
elseif( class == CLASS_MAGE ) then
fight_mage();
end
end
yrest(500);
if( HP < HP_sit or MP < MP_sit or SP < SP_sit ) then
rest_heal(); end
yrest(200);
end
closeProcess(proc);
detach();
end
startMacro(main);
-------------------------------------------------
I dont get this whole thing