Shaiya Fighter Bot

For any other game that doesn't have its own section.
Message
Author
vvayinsane
Posts: 148
Joined: Fri Mar 21, 2008 9:10 pm

Re: Shaiya Fighter Bot

#161 Post by vvayinsane » Mon Dec 22, 2008 10:15 pm

Adminstrator says:

Code: Select all

It looks like the HDC is nil (the first parameter), and therefor it cannot read pixels from that HDC. Find where the HDC is opened ( getDC() ) and do some logging. First, ensure that the window you're getting the HDC from is not 0. Second, check the value that's returned by getDC().
I have no clue what he is saying he lost me at find whre th hdc is located.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Shaiya Fighter Bot

#162 Post by Administrator » Tue Dec 23, 2008 4:54 am

I took a look at the script, and it's quite a mess. It is going to be difficult to diagnose. The easy solution here is just to use a script that works and is still being updated regularly (such as Zero's, which is apparently working well again).

1z2x3c
Posts: 14
Joined: Tue Dec 30, 2008 8:26 pm

Re: Shaiya Fighter Bot

#163 Post by 1z2x3c » Tue Dec 30, 2008 8:29 pm

here is a working one(although you have to change ddd to the name of the .exe or it wont work.... ok....):

Code: Select all

on  = true;
off = false;
------------------------------------------------
-- HOTKEYS
------------------------------------------------
macro_running       = on; -- leave this ON!

startKey = key.VK_INSERT;
stopKey = key.VK_DELETE;

key_switchtarget = key.VK_TILDE;

key_attack  = key.VK_1;
key_pickup  = key.VK_2;

key_skill1  = key.VK_3;
key_skill2  = key.VK_4;
key_skill3  = key.VK_5;
key_skill4 = key.VK_NUMPAD5;
key_skill5 = key.VK_NUMPAD6;
key_skill6 = key.VK_NUMPAD7;

key_buff1   = key.VK_6;
key_buff2   = key.VK_7;
key_buff3   = key.VK_NUMPAD8;
key_buff4   = key.VK_NUMPAD9;
key_buff5   = key.VK_NUMPAD0;

key_hp_potion = key.VK_8;
key_hp_potion1 = key.VK_NUMPAD1;
key_hp_potion2 = key.VK_NUMPAD2;
key_hp_potion3 = key.VK_NUMPAD3;
key_hp_potion4 = key.VK_NUMPAD4;
key_mp_potion = key.VK_9;
key_sp_potion = key.VK_0;

key_sit       = key.VK_C;
key_move_down = key.VK_S;
key_move_right= key.VK_E;
key_myself    = key.VK_F1;
key_jump      = key.VK_SPACE;
key_home      = key.VK_HOME;
key_right     = key.VK_RIGHT;
do_jump       = 0;
--- Don't touch the code above or the program will act differently/not work unless you kknow how to-----------------------


--------------------------------------------------------
-- If the target's hp is not full how many time you want it to scan for targets with full hp.
-- Note: Lag issue will happen. if the target's Hp is still loading it will switch targets.
-- This code prevents it from ksing other people's damaged mobs
-- Default is 4 but adjust it to your mobs zone
--------------------------------------------------------

how_many_scanTarget = 5;

--------------------------------------------------------
-- How many seconds you want to keep locking on the target. If the target's Hp is full for more than 15 
-- seconds then that means you are stuck behind a wall, So the macro will change target.
-- Default is 15, if the mob is more spread apart adjust it with a higher number.
--------------------------------------------------------
 
how_many_seconds    = 15;


--------------------------------------------------------
--How many time you want to pick up items after mob is dead.
--Default is 3. In some cases 4 should pick up every drop.
--------------------------------------------------------


how_many_pickup     = 7; 


--------------------------------------------------------
-- Choose what range of Colored Mob you would want your Fighter
-- To kill. This way your fighter does not run all over the map.
-- Default is min 3 max 3. Which means the micro will only target blue mobs.
--------------------------------------------------------
target_difficulty_color_min= 5;
target_difficulty_color_max= 6;
--white  = 1
--cyan   = 2
--blue   = 3
--green  = 4
--yellow = 5
--orange = 6
--red    = 7
--purple = 8
--grey   = 9


------------------------------------------------
-- SKILLS secondsToTimer(x);
------------------------------------------------
-- Set to 0 if you don't want to use a skill
skill1_time = secondsToTimer(60);
skill2_time = secondsToTimer(20);
skill3_time = secondsToTimer(300);
skill4_time = secondsToTimer(300);
skill5_time = secondsToTimer(300);
skill6_time = secondsToTimer(600);


------------------------------------------------
-- BUFFS
------------------------------------------------
-- Set a buff to 0 if you don't want to use it
buff1_time = minutesToTimer(9);
buff2_time = minutesToTimer(4);
buff3_time = minutesToTimer(4);
buff4_time = minutesToTimer(4);
buff5_time = minutesToTimer(4);

------------------------------------------------
-- POTIONS
------------------------------------------------
-- All potion use values are specified in %
-- Set the values to 0 to not use that potion
HP_potion_use = 70;
MP_potion_use = 30;
SP_potion_use = 30;


------------------------------------------------
-- SITTING
------------------------------------------------
-- All sitting values are specified in %
-- We will only sit while out of battle
-- Set the values to 0 to not use sitting
HP_sit = 60;
MP_sit = 20;
SP_sit = 20;


--[[*********************************************************************
**************************************************************************
    DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
**************************************************************************
************************************************************************]]

------------------------------------------------
-- Memory addresses
------------------------------------------------
playerptr_addr = 0x00825CB4;

HP_offset = 0x12C; 
MaxHP_offset = 0x130;
MP_offset = 0x134;
MaxMP_offset = 0x138;
SP_offset = 0x13C;
MaxSP_offset = 0x140;

targetid_addr = 0x006d0bc4; -- short, 65535 if none selected
-- REMOVED -- targettype_addr = 0x00619B1F; -- byte, 0 = player/NPC, 7 = monster

sitcheck_addr = 0x006E5D40; -- byte, 0 = standing, 7 = sitting

--------------------------------------------------------------------------
function init_window()
  win = findWindow("Shaiya");
  if(win == nil) then
    printf(error_init);
    macro_running = false;
  end
end
function init_process()
  proc = openProcess( findProcessByExe("[color=#00BF00]ddd[/color].exe") );
  if(proc == 0) then
    printf("error opening process.\n");
    macro_running = false;
  end
end
function init_hdc()
  hdc = openDC(get_win());
  local wx, wy, ww, wh = windowRect(get_win());

end
function get_hdc()
  return hdc;
end
function get_win()
  return win;
end
function debug_message(msg)
  if (g_debug) then
    print(msg);
    logMessage(msg);
  end
end
window_mode = false;

g_debug = true;
function target()
  keyboardPress(key_switchtarget);
  yrest(200);
end

function moveBreak()
  keyboardHold(key_move_down);
  yrest(500);
  keyboardRelease(key_move_down);
end

function pickup()
  printf("Pickup!\n");
  if( key_pickup == 0 ) then return; end
    local i;
    for i = 0, how_many_pickup do
      keyboardPress(key_pickup);
      yrest(500);
  end
end

--------------------------------------------------------------------------------
-- Memory Addresses.
TARGET_POS_X_ADDRESS = 0x1FCFE80;
TARGET_POS_Y_ADDRESS = 0x1FCFE84;
TARGET_POS_Z_ADDRESS = 0x1FCFE88;
TARGET_TYPE_ADDR     = 0x0619B1F;

-- Field Values.
TARGET_UNKNOWN  = 0;
TARGET_DAMAGED  = 1;
TARGET_FULL     = 2;
TARGET_DEAD     = 3;

TARGET_BAR_COLOR = {
  r_min=150, r_max=180,
  g_min=10, g_max=40,
  b_min=50, b_max=80
};

TARGET_HEALTH_BAR_PIXEL_OFFSET_1 = {x=36, y=36};
TARGET_HEALTH_BAR_PIXEL_OFFSET_2 = {x=165, y=36};
TARGET_HEALTH_BAR_PIXEL_OFFSET_3 = {x=100, y=36};

-- Target Name Color
TARGET_NAME_COLOR_SCAN_OFFSET_1 = {x=98, y=15};
TARGET_NAME_COLOR_SCAN_OFFSET_2 = {x=110, y=15};


target_name_color = {
  unknown=0,
  white=1,
  cyan=2,
  blue=3,
  green=4,
  yellow=5,
  orange=6,
  red=7,
  purple=8,
  grey=9,
};

--[[TARGET_NAME_COLOR_WHITE    = 1;
TARGET_NAME_COLOR_CYAN     = 2;
TARGET_NAME_COLOR_BLUE     = 3;
TARGET_NAME_COLOR_GREEN    = 4;
TARGET_NAME_COLOR_YELLOW   = 5;
TARGET_NAME_COLOR_ORANGE   = 6;
TARGET_NAME_COLOR_RED      = 7;
TARGET_NAME_COLOR_PURPLE   = 8;
TARGET_NAME_COLOR_GREY     = 9;]]


-- In order of difficulty, from easiest to hardest.
target_name_color_rgb = {
  [target_name_color["white"]]   = {r_min=255, r_max=255,
                                    g_min=255, g_max=255,
                                    b_min=255, b_max=255},
  [target_name_color["cyan"]]    = {r_min=120, r_max=140,
                                    g_min=255, g_max=255,
                                    b_min=255, b_max=255},
  [target_name_color["blue"]]    = {r_min=0, r_max=0,
                                    g_min=0, g_max=0,
                                    b_min=253, b_max=255},
  [target_name_color["green"]]   = {r_min=0, r_max=0,
                                    g_min=1, g_max=255,
                                    b_min=0, b_max=0},
  [target_name_color["yellow"]]  = {r_min=253, r_max=255,
                                    g_min=253, g_max=255,
                                    b_min=0, b_max=0},
  [target_name_color["orange"]]  = {r_min=255, r_max=255,
                                    g_min=128, g_max=128,
                                    b_min=0, b_max=0},
  [target_name_color["red"]]     = {r_min=255, r_max=255,
                                    g_min=0, g_max=0,
                                    b_min=0, b_max=0},
  [target_name_color["purple"]]  = {r_min=255, r_max=255,
                                    g_min=0, g_max=0,
                                    b_min=255, b_max=255},
  --[target_name_color["grey"]]  = {r_min=255, r_max=255,
   --                               g_min=255, g_max=255,
   --                               b_min=255, b_max=255},
}


TARGET_TYPE_FRIENDLY  = 0;
TARGET_TYPE_NOTHING   = -1;

-- Status Info Bar, offset.
STATUSINFOBAR_POS = {x=0, y=0};


-- Looks at pixels in the status info bar in the h/w device context,
-- to determine the status of the monster.
-- note - this has known errors, changing the colour bit value, or restarting PC
--        seems to fix it.
-- @return TARGET_UNKNOWN does not have any detectable red bar.
--         TARGET_DAMAGED if some red bar exists.
--         TARGET_FULL full red bar.
function status()
  local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"])};
  local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_2["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_2["y"])};
  local pos_3 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_3["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_3["y"])};
  --printf("x1:%d y1:%d x2:%d y2:%d\n", pos_1["x"], pos_1["y"], pos_2["x"], pos_2["y"]);

  local l_hdc = get_hdc();
-- s(RGB) begining E(RGB) end M(RGB) middle;
  local sr,sg,sb;
  local er,eg,eb;
local mr,mg,mb;
  if (window_mode) then
    local wx, wy = windowRect(get_win());
    --debug_message(sprintf("win_x: %d, wim_y: %d\n", wx, wy));

    sr,sg,sb = getPixel(l_hdc, (wx + pos_1["x"]), (wy + pos_1["y"]));
    er,eg,eb = getPixel(l_hdc, (wx + pos_2["x"]), (wy + pos_2["y"]));
mr,mg,mb = getPixel(l_hdc, (wx + pos_3["x"]), (wy + pos_3["y"]));
  else
    sr,sg,sb = getPixel(l_hdc, pos_1["x"], pos_1["y"]);
    er,eg,eb = getPixel(l_hdc, pos_2["x"], pos_2["y"]);
mr,mg,mb = getPixel(l_hdc, pos_3["x"], pos_3["y"]);
  end
  --closeDC(hdc);
  --debug_message(sprintf("sr: %d, sg: %d, sb: %d", sr, sg, sb));
  --debug_message(sprintf("er: %d, eg: %d, eb: %d", er, eg, eb));
--debug_message(sprintf("mr: %d, mg: %d, mb: %d", mr, mg, mb));
  if ((sr >= TARGET_BAR_COLOR["r_min"] and
        sr <= TARGET_BAR_COLOR["r_max"]) and
      (sg >= TARGET_BAR_COLOR["g_min"] and
        sg <= TARGET_BAR_COLOR["g_max"]) and
      (sb >= TARGET_BAR_COLOR["b_min"] and
        sb <= TARGET_BAR_COLOR["b_max"]))
  then
      if((er <= TARGET_BAR_COLOR["r_min"] and
          er <= TARGET_BAR_COLOR["r_max"]) and
        (eg <= TARGET_BAR_COLOR["g_min"] and
          eg <= TARGET_BAR_COLOR["g_max"]) and
        (eb <= TARGET_BAR_COLOR["b_min"] and
          eb <= TARGET_BAR_COLOR["b_max"])) 
      then
	if((mr <= TARGET_BAR_COLOR["r_min"] and
          mr <= TARGET_BAR_COLOR["r_max"]) and
          (mg <= TARGET_BAR_COLOR["g_min"] and
          mg <= TARGET_BAR_COLOR["g_max"]) and
          (mb <= TARGET_BAR_COLOR["b_min"] and
          mb <= TARGET_BAR_COLOR["b_max"])) 
      	then
	  emergencyHeal=1;
	end
        return TARGET_DAMAGED;     
      end
	return TARGET_FULL;
  end
  return TARGET_UNKNOWN;
end
-- Gets the monster difficulty color, by reading each pixel in a small fixed 
-- line in the middle through the top of the lower case letters,
-- in the monster name label.
-- @return The color index of the name text on success, 0 on failure.
function get_difficulty_color()
  local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["x"]),
                     y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["y"])};
  local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["x"]),
                     y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["y"])};

  local pr, pg, pb;
  --local l_color = TARGET_NAME_COLOR_UNKNOWN;
  --local hdc = openDC(shaiya_win);
  local l_hdc = get_hdc();
  for i=pos_1["x"], pos_2["x"] do
    for j=pos_1["y"], pos_2["y"] do
      if (window_mode) then
          local wx, wy = windowRect(get_win());
          printf("win_x: %d, wim_y: %d\n", wx, wy);
          pr, pg, pb = getPixel(l_hdc, wx + i, wy + j);
        else
          pr, pg, pb = getPixel(l_hdc, i, j);
        end
        debug_message(sprintf("pr: %d, pg: %d, pb: %d", pr, pg, pb));
        for k,v in pairs(target_name_color_rgb) do
          --printf("v[r]: %d, v[g]: %d, v[b]: %d\n", v["r"], v["g"], v["b"]);
          if(pr >= v["r_min"] and pr <= v["r_max"] and
              pg >= v["g_min"] and pg <= v["g_max"] and
              pb >= v["b_min"] and pb <= v["b_max"]) then
            printf("target_difficulty_color: %s\n", k);
            return k;
          end
        end
    end
  end
  --closeDC(hdc);
  return target_name_color["unknown"];
end

-------------------------------------------------------------------
-- Modification to see if Target is Dead or FULL HP

function targetstatus()
  local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"])};

  --printf("x1:%d y1:%d x2:%d y2:%d\n", pos_1["x"], pos_1["y"], pos_2["x"], pos_2["y"]);

  local l_hdc = get_hdc();
-- s(RGB) begining E(RGB) end M(RGB) middle;
  local sr,sg,sb;
  if (window_mode) then
    local wx, wy = windowRect(get_win());
    --debug_message(sprintf("win_x: %d, wim_y: %d\n", wx, wy));
    sr,sg,sb = getPixel(l_hdc, (wx + pos_1["x"]), (wy + pos_1["y"]));

  else
    sr,sg,sb = getPixel(l_hdc, pos_1["x"], pos_1["y"]);
  end
  --closeDC(hdc);
  --debug_message(sprintf("sr: %d, sg: %d, sb: %d", sr, sg, sb));
  --debug_message(sprintf("er: %d, eg: %d, eb: %d", er, eg, eb));
--debug_message(sprintf("mr: %d, mg: %d, mb: %d", mr, mg, mb));
  if ((sr <= TARGET_BAR_COLOR["r_min"] and
        sr <= TARGET_BAR_COLOR["r_max"]) and
      (sg <= TARGET_BAR_COLOR["g_min"] and
        sg <= TARGET_BAR_COLOR["g_max"]) and
      (sb <= TARGET_BAR_COLOR["b_min"] and
        sb <= TARGET_BAR_COLOR["b_max"]))
  then

	return TARGET_DEAD;
  end
  return TARGET_FULL;
end
------------------------------------------------------------------------


-----------------------------------------------------------------------------------
--*******Cycle Target to see if It matches your minimum and maximum color monster ********
function cycle_target()
  --printf("self.switched_targets: %d\n", self.switched_targets);
  --printf("self.max_switch_targets: %d\n", self.max_switch_targets);

    --debug_message("new_target");
    target();
    local target_status = status();
    --printf("target_color: %d\n", target_color);
    --printf("target_status=%d\n", target_status);
    logMessage(sprintf("target_status=%d", target_status));
    
    if (target_status == TARGET_FULL) then
      local l_color = get_difficulty_color();
      local l_color_min = target_difficulty_color_min;
      local l_color_max = target_difficulty_color_max;
--printf("target_color_min: %s\n", l_color_min);
--    printf("target_color_max: %s\n", l_color_max);
printf("getting difficulty Color \n");
      --printf("l_color: %s\n", l_color);
      
if (l_color >= l_color_min and l_color <= l_color_max) then
       return true;
      end
    end
return false;
end
-----------------------------------------------------------------------------------
function cycle_target2()
    if (target_status == TARGET_FULL) then
      local l_color = get_difficulty_color();
      local l_color_min = target_difficulty_color_min;
      local l_color_max = target_difficulty_color_max;     
      if (l_color >= l_color_min and l_color <= l_color_max) then
       return true;
      end
    end
return false;
end
------------------------------------------------
-- Variable setup
------------------------------------------------
HP = 10000;
MaxHP = HP;
MP = 10000;
MaxMP = MP;
SP = 10000;
MaxSP = SP;

skill1_ready = true;
skill2_ready = true;
skill3_ready = true;
skill4_ready = true;
skill5_ready = true;
skill6_ready = true;

buff1_ready = true;
buff2_ready = true;
buff3_ready = true;
buff4_ready = true;
buff5_ready = true;

------------------------------------------------
-- Functions
------------------------------------------------

skill1_toggle = function () skill1_ready = true; end;
skill2_toggle = function () skill2_ready = true; end;
skill3_toggle = function () skill3_ready = true; end;
skill4_toggle = function () skill4_ready = true; end;
skill5_toggle = function () skill5_ready = true; end;
skill6_toggle = function () skill6_ready = true; end;

buff1_toggle = function () buff1_ready = true; end;
buff2_toggle = function () buff2_ready = true; end;
buff3_toggle = function () buff3_ready = true; end;
buff4_toggle = function () buff4_ready = true; end;
buff5_toggle = function () buff5_ready = true; end;


function use_hp_potion()
  keyboardPress(key_hp_potion);
  keyboardPress(key_hp_potion1);
  keyboardPress(key_hp_potion2);
  keyboardPress(key_hp_potion3);
  keyboardPress(key_hp_potion4);
  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 sit()
  if( HP_sit == 0 ) then
    return; end

  printf("Sitting.\n");

  local sitting = false;
  while( sitting == false ) do
    keyboardPress(key_sit);
    yrest(1000);

    sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
  end

  local lasthp = HP;

  while( true ) do
    if( HP == MaxHP and MP == MaxMP and SP == MaxSP ) then
      switch_target();
      break;
    end

    if( HP < (lasthp - 10) ) then
      printf("Exiting rest...under attack\n");
      break;
    else
      lasthp = HP;
    end

    yrest(100);
  end

  sitting = true;
  while( sitting ) do
    keyboardPress(key_sit);
    yrest(1000);

    sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
  end

  printf("Standing... Resuming bot\n");
  yrest(1000);
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);
end


function have_target()
  local readid = memoryReadShort(proc, targetid_addr);

  return ( readid ~= 0xFFFF );
end

function find_target()
  keyboardPress(key_attack);
end

function switch_target()
  keyboardPress(key_switchtarget);
end

------------------------------------------------
-- FIGHT2
------------------------------------------------
function fight2()
   local beginTime  = os.time();
   local attackLoop = true;
   local skillsonetime = 0;
  keyboardPress(key_attack);
yrest(200);
  
printf("Attacking Target \n");

  while (attackLoop) do
    local targetStatus = targetstatus();
    local Tstatus = status();
    if(targetStatus == TARGET_DEAD) then
       printf("Target Dead \n\n");
       pickup();
       attackLoop = false;
       moveBreak();
    else      
      local currentTime = os.time();
      if( os.difftime(currentTime, beginTime) > how_many_seconds ) then 
         moveBreak();
         beginTime  = os.time();
         if(Tstatus == TARGET_FULL) then
           do_jump = do_jump+1;
           printf("Changing Targets: Obsticle \n\n");
           attackLoop = false;
         end
      else
         if(skillsonetime == 0 and Tstatus == TARGET_DAMAGED) then
           skillsonetime = 1+skillsonetime;
           keyboardPress(key_skill1);
         end;
         keyboardPress(key_attack);
         yrest(2000);
      end
    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




------------------------------------------------
-- MAIN
------------------------------------------------
function main()
  proc = openProcess(findProcessByExe("game.exe"));
  win = findWindow("Shaiya");
  attach(win);
  setPriority(PRIORITY_HIGH);
init_window();
  init_process();
  init_hdc();


  registerTimer("update_vars", 100, update_vars);

  if( skill1_time ) then registerTimer("skill1_toggle", skill1_time, skill1_toggle); end
  if( skill2_time ) then registerTimer("skill2_toggle", skill2_time, skill2_toggle); end
  if( skill3_time ) then registerTimer("skill3_toggle", skill3_time, skill3_toggle); end
  if( skill4_time ) then registerTimer("skill4_toggle", skill4_time, skill4_toggle); end
  if( skill5_time ) then registerTimer("skill5_toggle", skill5_time, skill5_toggle); end
  if( skill6_time ) then registerTimer("skill6_toggle", skill6_time, skill6_toggle); end

  if( buff1_time ) then registerTimer("buff1_toggle", buff1_time, buff1_toggle); end;
  if( buff2_time ) then registerTimer("buff2_toggle", buff2_time, buff2_toggle); end;
  if( buff3_time ) then registerTimer("buff3_toggle", buff3_time, buff3_toggle); end;
  if( buff4_time ) then registerTimer("buff4_toggle", buff4_time, buff4_toggle); end;
  if( buff5_time ) then registerTimer("buff5_toggle", buff5_time, buff5_toggle); end;

local reAttack = 0;

  while( macro_running ) do
    if( buff1_ready  and buff1_time > 0 ) then
      keyboardPress(key_buff1); buff1_ready = false; yrest(2000); end;
    if( buff2_ready  and buff2_time > 0 ) then
      keyboardPress(key_buff2); buff2_ready = false; yrest(2000); end;
    if( buff3_ready  and buff3_time > 0 ) then
      keyboardPress(key_buff3); buff3_ready = false; yrest(2000); end;
    if( buff4_ready  and buff4_time > 0 ) then
      keyboardPress(key_buff4); buff4_ready = false; yrest(2000); end;
    if( buff5_ready  and buff5_time > 0 ) then
      keyboardPress(key_buff5); buff5_ready = false; yrest(2000); end;

    if(cycle_target()) then
       fight2();
       if(do_jump == 1) then
          keyboardHold(key_move_down);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardRelease(key_move_down);
          keyboardHold(key_move_right);
          yrest(2000);
          keyboardRelease(key_move_right);
          keyboardHold(key_move_right);
          yrest(2000);
          keyboardRelease(key_move_right);
          keyboardHold(key_move_down);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardRelease(key_move_down);
          do_jump = 0;
       end
       reAttack = 0;
    else
       reAttack = 1 + reAttack;
    end
--printf(reAttack);
    if ( reAttack == how_many_scanTarget ) then
       reAttack = 0;
       keyboardPress(key_myself);
       yrest(500);
       keyboardHold(key_right);
       yrest(500);
       keyboardRelease(key_right);
    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

    if( (HP/MaxHP*100) < HP_sit and (HP_sit > 0) ) then sit(); end
    if( (MP/MaxMP*100) < MP_sit and (MP_sit > 0) ) then sit(); end
    if( (SP/MaxSP*100) < SP_sit and (SP_sit > 0) ) then sit(); end

  if ((HP/MaxHP*100) <= 0) then
    --user_alive = false;
    printf("\n\nPlayer is DEAD");
    keyboardPress(key.VK_DELETE);
    --force_close();
  end    
  end
end

startMacro(main);

centik
Posts: 51
Joined: Sat Apr 19, 2008 2:03 am

Re: Shaiya Fighter Bot

#164 Post by centik » Sun Jan 04, 2009 5:23 am

1z2x3c wrote:here is a working one(although you have to change ddd to the name of the .exe or it wont work.... ok....):

Code: Select all

on  = true;
off = false;
------------------------------------------------
-- HOTKEYS
------------------------------------------------
macro_running       = on; -- leave this ON!

startKey = key.VK_INSERT;
stopKey = key.VK_DELETE;

key_switchtarget = key.VK_TILDE;

key_attack  = key.VK_1;
key_pickup  = key.VK_2;

key_skill1  = key.VK_3;
key_skill2  = key.VK_4;
key_skill3  = key.VK_5;
key_skill4 = key.VK_NUMPAD5;
key_skill5 = key.VK_NUMPAD6;
key_skill6 = key.VK_NUMPAD7;

key_buff1   = key.VK_6;
key_buff2   = key.VK_7;
key_buff3   = key.VK_NUMPAD8;
key_buff4   = key.VK_NUMPAD9;
key_buff5   = key.VK_NUMPAD0;

key_hp_potion = key.VK_8;
key_hp_potion1 = key.VK_NUMPAD1;
key_hp_potion2 = key.VK_NUMPAD2;
key_hp_potion3 = key.VK_NUMPAD3;
key_hp_potion4 = key.VK_NUMPAD4;
key_mp_potion = key.VK_9;
key_sp_potion = key.VK_0;

key_sit       = key.VK_C;
key_move_down = key.VK_S;
key_move_right= key.VK_E;
key_myself    = key.VK_F1;
key_jump      = key.VK_SPACE;
key_home      = key.VK_HOME;
key_right     = key.VK_RIGHT;
do_jump       = 0;
--- Don't touch the code above or the program will act differently/not work unless you kknow how to-----------------------


--------------------------------------------------------
-- If the target's hp is not full how many time you want it to scan for targets with full hp.
-- Note: Lag issue will happen. if the target's Hp is still loading it will switch targets.
-- This code prevents it from ksing other people's damaged mobs
-- Default is 4 but adjust it to your mobs zone
--------------------------------------------------------

how_many_scanTarget = 5;

--------------------------------------------------------
-- How many seconds you want to keep locking on the target. If the target's Hp is full for more than 15 
-- seconds then that means you are stuck behind a wall, So the macro will change target.
-- Default is 15, if the mob is more spread apart adjust it with a higher number.
--------------------------------------------------------
 
how_many_seconds    = 15;


--------------------------------------------------------
--How many time you want to pick up items after mob is dead.
--Default is 3. In some cases 4 should pick up every drop.
--------------------------------------------------------


how_many_pickup     = 7; 


--------------------------------------------------------
-- Choose what range of Colored Mob you would want your Fighter
-- To kill. This way your fighter does not run all over the map.
-- Default is min 3 max 3. Which means the micro will only target blue mobs.
--------------------------------------------------------
target_difficulty_color_min= 5;
target_difficulty_color_max= 6;
--white  = 1
--cyan   = 2
--blue   = 3
--green  = 4
--yellow = 5
--orange = 6
--red    = 7
--purple = 8
--grey   = 9


------------------------------------------------
-- SKILLS secondsToTimer(x);
------------------------------------------------
-- Set to 0 if you don't want to use a skill
skill1_time = secondsToTimer(60);
skill2_time = secondsToTimer(20);
skill3_time = secondsToTimer(300);
skill4_time = secondsToTimer(300);
skill5_time = secondsToTimer(300);
skill6_time = secondsToTimer(600);


------------------------------------------------
-- BUFFS
------------------------------------------------
-- Set a buff to 0 if you don't want to use it
buff1_time = minutesToTimer(9);
buff2_time = minutesToTimer(4);
buff3_time = minutesToTimer(4);
buff4_time = minutesToTimer(4);
buff5_time = minutesToTimer(4);

------------------------------------------------
-- POTIONS
------------------------------------------------
-- All potion use values are specified in %
-- Set the values to 0 to not use that potion
HP_potion_use = 70;
MP_potion_use = 30;
SP_potion_use = 30;


------------------------------------------------
-- SITTING
------------------------------------------------
-- All sitting values are specified in %
-- We will only sit while out of battle
-- Set the values to 0 to not use sitting
HP_sit = 60;
MP_sit = 20;
SP_sit = 20;


--[[*********************************************************************
**************************************************************************
    DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
**************************************************************************
************************************************************************]]

------------------------------------------------
-- Memory addresses
------------------------------------------------
playerptr_addr = 0x00825CB4;

HP_offset = 0x12C; 
MaxHP_offset = 0x130;
MP_offset = 0x134;
MaxMP_offset = 0x138;
SP_offset = 0x13C;
MaxSP_offset = 0x140;

targetid_addr = 0x006d0bc4; -- short, 65535 if none selected
-- REMOVED -- targettype_addr = 0x00619B1F; -- byte, 0 = player/NPC, 7 = monster

sitcheck_addr = 0x006E5D40; -- byte, 0 = standing, 7 = sitting

--------------------------------------------------------------------------
function init_window()
  win = findWindow("Shaiya");
  if(win == nil) then
    printf(error_init);
    macro_running = false;
  end
end
function init_process()
  proc = openProcess( findProcessByExe("[color=#00BF00]ddd[/color].exe") );
  if(proc == 0) then
    printf("error opening process.\n");
    macro_running = false;
  end
end
function init_hdc()
  hdc = openDC(get_win());
  local wx, wy, ww, wh = windowRect(get_win());

end
function get_hdc()
  return hdc;
end
function get_win()
  return win;
end
function debug_message(msg)
  if (g_debug) then
    print(msg);
    logMessage(msg);
  end
end
window_mode = false;

g_debug = true;
function target()
  keyboardPress(key_switchtarget);
  yrest(200);
end

function moveBreak()
  keyboardHold(key_move_down);
  yrest(500);
  keyboardRelease(key_move_down);
end

function pickup()
  printf("Pickup!\n");
  if( key_pickup == 0 ) then return; end
    local i;
    for i = 0, how_many_pickup do
      keyboardPress(key_pickup);
      yrest(500);
  end
end

--------------------------------------------------------------------------------
-- Memory Addresses.
TARGET_POS_X_ADDRESS = 0x1FCFE80;
TARGET_POS_Y_ADDRESS = 0x1FCFE84;
TARGET_POS_Z_ADDRESS = 0x1FCFE88;
TARGET_TYPE_ADDR     = 0x0619B1F;

-- Field Values.
TARGET_UNKNOWN  = 0;
TARGET_DAMAGED  = 1;
TARGET_FULL     = 2;
TARGET_DEAD     = 3;

TARGET_BAR_COLOR = {
  r_min=150, r_max=180,
  g_min=10, g_max=40,
  b_min=50, b_max=80
};

TARGET_HEALTH_BAR_PIXEL_OFFSET_1 = {x=36, y=36};
TARGET_HEALTH_BAR_PIXEL_OFFSET_2 = {x=165, y=36};
TARGET_HEALTH_BAR_PIXEL_OFFSET_3 = {x=100, y=36};

-- Target Name Color
TARGET_NAME_COLOR_SCAN_OFFSET_1 = {x=98, y=15};
TARGET_NAME_COLOR_SCAN_OFFSET_2 = {x=110, y=15};


target_name_color = {
  unknown=0,
  white=1,
  cyan=2,
  blue=3,
  green=4,
  yellow=5,
  orange=6,
  red=7,
  purple=8,
  grey=9,
};

--[[TARGET_NAME_COLOR_WHITE    = 1;
TARGET_NAME_COLOR_CYAN     = 2;
TARGET_NAME_COLOR_BLUE     = 3;
TARGET_NAME_COLOR_GREEN    = 4;
TARGET_NAME_COLOR_YELLOW   = 5;
TARGET_NAME_COLOR_ORANGE   = 6;
TARGET_NAME_COLOR_RED      = 7;
TARGET_NAME_COLOR_PURPLE   = 8;
TARGET_NAME_COLOR_GREY     = 9;]]


-- In order of difficulty, from easiest to hardest.
target_name_color_rgb = {
  [target_name_color["white"]]   = {r_min=255, r_max=255,
                                    g_min=255, g_max=255,
                                    b_min=255, b_max=255},
  [target_name_color["cyan"]]    = {r_min=120, r_max=140,
                                    g_min=255, g_max=255,
                                    b_min=255, b_max=255},
  [target_name_color["blue"]]    = {r_min=0, r_max=0,
                                    g_min=0, g_max=0,
                                    b_min=253, b_max=255},
  [target_name_color["green"]]   = {r_min=0, r_max=0,
                                    g_min=1, g_max=255,
                                    b_min=0, b_max=0},
  [target_name_color["yellow"]]  = {r_min=253, r_max=255,
                                    g_min=253, g_max=255,
                                    b_min=0, b_max=0},
  [target_name_color["orange"]]  = {r_min=255, r_max=255,
                                    g_min=128, g_max=128,
                                    b_min=0, b_max=0},
  [target_name_color["red"]]     = {r_min=255, r_max=255,
                                    g_min=0, g_max=0,
                                    b_min=0, b_max=0},
  [target_name_color["purple"]]  = {r_min=255, r_max=255,
                                    g_min=0, g_max=0,
                                    b_min=255, b_max=255},
  --[target_name_color["grey"]]  = {r_min=255, r_max=255,
   --                               g_min=255, g_max=255,
   --                               b_min=255, b_max=255},
}


TARGET_TYPE_FRIENDLY  = 0;
TARGET_TYPE_NOTHING   = -1;

-- Status Info Bar, offset.
STATUSINFOBAR_POS = {x=0, y=0};


-- Looks at pixels in the status info bar in the h/w device context,
-- to determine the status of the monster.
-- note - this has known errors, changing the colour bit value, or restarting PC
--        seems to fix it.
-- @return TARGET_UNKNOWN does not have any detectable red bar.
--         TARGET_DAMAGED if some red bar exists.
--         TARGET_FULL full red bar.
function status()
  local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"])};
  local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_2["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_2["y"])};
  local pos_3 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_3["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_3["y"])};
  --printf("x1:%d y1:%d x2:%d y2:%d\n", pos_1["x"], pos_1["y"], pos_2["x"], pos_2["y"]);

  local l_hdc = get_hdc();
-- s(RGB) begining E(RGB) end M(RGB) middle;
  local sr,sg,sb;
  local er,eg,eb;
local mr,mg,mb;
  if (window_mode) then
    local wx, wy = windowRect(get_win());
    --debug_message(sprintf("win_x: %d, wim_y: %d\n", wx, wy));

    sr,sg,sb = getPixel(l_hdc, (wx + pos_1["x"]), (wy + pos_1["y"]));
    er,eg,eb = getPixel(l_hdc, (wx + pos_2["x"]), (wy + pos_2["y"]));
mr,mg,mb = getPixel(l_hdc, (wx + pos_3["x"]), (wy + pos_3["y"]));
  else
    sr,sg,sb = getPixel(l_hdc, pos_1["x"], pos_1["y"]);
    er,eg,eb = getPixel(l_hdc, pos_2["x"], pos_2["y"]);
mr,mg,mb = getPixel(l_hdc, pos_3["x"], pos_3["y"]);
  end
  --closeDC(hdc);
  --debug_message(sprintf("sr: %d, sg: %d, sb: %d", sr, sg, sb));
  --debug_message(sprintf("er: %d, eg: %d, eb: %d", er, eg, eb));
--debug_message(sprintf("mr: %d, mg: %d, mb: %d", mr, mg, mb));
  if ((sr >= TARGET_BAR_COLOR["r_min"] and
        sr <= TARGET_BAR_COLOR["r_max"]) and
      (sg >= TARGET_BAR_COLOR["g_min"] and
        sg <= TARGET_BAR_COLOR["g_max"]) and
      (sb >= TARGET_BAR_COLOR["b_min"] and
        sb <= TARGET_BAR_COLOR["b_max"]))
  then
      if((er <= TARGET_BAR_COLOR["r_min"] and
          er <= TARGET_BAR_COLOR["r_max"]) and
        (eg <= TARGET_BAR_COLOR["g_min"] and
          eg <= TARGET_BAR_COLOR["g_max"]) and
        (eb <= TARGET_BAR_COLOR["b_min"] and
          eb <= TARGET_BAR_COLOR["b_max"])) 
      then
	if((mr <= TARGET_BAR_COLOR["r_min"] and
          mr <= TARGET_BAR_COLOR["r_max"]) and
          (mg <= TARGET_BAR_COLOR["g_min"] and
          mg <= TARGET_BAR_COLOR["g_max"]) and
          (mb <= TARGET_BAR_COLOR["b_min"] and
          mb <= TARGET_BAR_COLOR["b_max"])) 
      	then
	  emergencyHeal=1;
	end
        return TARGET_DAMAGED;     
      end
	return TARGET_FULL;
  end
  return TARGET_UNKNOWN;
end
-- Gets the monster difficulty color, by reading each pixel in a small fixed 
-- line in the middle through the top of the lower case letters,
-- in the monster name label.
-- @return The color index of the name text on success, 0 on failure.
function get_difficulty_color()
  local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["x"]),
                     y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["y"])};
  local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["x"]),
                     y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["y"])};

  local pr, pg, pb;
  --local l_color = TARGET_NAME_COLOR_UNKNOWN;
  --local hdc = openDC(shaiya_win);
  local l_hdc = get_hdc();
  for i=pos_1["x"], pos_2["x"] do
    for j=pos_1["y"], pos_2["y"] do
      if (window_mode) then
          local wx, wy = windowRect(get_win());
          printf("win_x: %d, wim_y: %d\n", wx, wy);
          pr, pg, pb = getPixel(l_hdc, wx + i, wy + j);
        else
          pr, pg, pb = getPixel(l_hdc, i, j);
        end
        debug_message(sprintf("pr: %d, pg: %d, pb: %d", pr, pg, pb));
        for k,v in pairs(target_name_color_rgb) do
          --printf("v[r]: %d, v[g]: %d, v[b]: %d\n", v["r"], v["g"], v["b"]);
          if(pr >= v["r_min"] and pr <= v["r_max"] and
              pg >= v["g_min"] and pg <= v["g_max"] and
              pb >= v["b_min"] and pb <= v["b_max"]) then
            printf("target_difficulty_color: %s\n", k);
            return k;
          end
        end
    end
  end
  --closeDC(hdc);
  return target_name_color["unknown"];
end

-------------------------------------------------------------------
-- Modification to see if Target is Dead or FULL HP

function targetstatus()
  local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"]),
			    y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"])};

  --printf("x1:%d y1:%d x2:%d y2:%d\n", pos_1["x"], pos_1["y"], pos_2["x"], pos_2["y"]);

  local l_hdc = get_hdc();
-- s(RGB) begining E(RGB) end M(RGB) middle;
  local sr,sg,sb;
  if (window_mode) then
    local wx, wy = windowRect(get_win());
    --debug_message(sprintf("win_x: %d, wim_y: %d\n", wx, wy));
    sr,sg,sb = getPixel(l_hdc, (wx + pos_1["x"]), (wy + pos_1["y"]));

  else
    sr,sg,sb = getPixel(l_hdc, pos_1["x"], pos_1["y"]);
  end
  --closeDC(hdc);
  --debug_message(sprintf("sr: %d, sg: %d, sb: %d", sr, sg, sb));
  --debug_message(sprintf("er: %d, eg: %d, eb: %d", er, eg, eb));
--debug_message(sprintf("mr: %d, mg: %d, mb: %d", mr, mg, mb));
  if ((sr <= TARGET_BAR_COLOR["r_min"] and
        sr <= TARGET_BAR_COLOR["r_max"]) and
      (sg <= TARGET_BAR_COLOR["g_min"] and
        sg <= TARGET_BAR_COLOR["g_max"]) and
      (sb <= TARGET_BAR_COLOR["b_min"] and
        sb <= TARGET_BAR_COLOR["b_max"]))
  then

	return TARGET_DEAD;
  end
  return TARGET_FULL;
end
------------------------------------------------------------------------


-----------------------------------------------------------------------------------
--*******Cycle Target to see if It matches your minimum and maximum color monster ********
function cycle_target()
  --printf("self.switched_targets: %d\n", self.switched_targets);
  --printf("self.max_switch_targets: %d\n", self.max_switch_targets);

    --debug_message("new_target");
    target();
    local target_status = status();
    --printf("target_color: %d\n", target_color);
    --printf("target_status=%d\n", target_status);
    logMessage(sprintf("target_status=%d", target_status));
    
    if (target_status == TARGET_FULL) then
      local l_color = get_difficulty_color();
      local l_color_min = target_difficulty_color_min;
      local l_color_max = target_difficulty_color_max;
--printf("target_color_min: %s\n", l_color_min);
--    printf("target_color_max: %s\n", l_color_max);
printf("getting difficulty Color \n");
      --printf("l_color: %s\n", l_color);
      
if (l_color >= l_color_min and l_color <= l_color_max) then
       return true;
      end
    end
return false;
end
-----------------------------------------------------------------------------------
function cycle_target2()
    if (target_status == TARGET_FULL) then
      local l_color = get_difficulty_color();
      local l_color_min = target_difficulty_color_min;
      local l_color_max = target_difficulty_color_max;     
      if (l_color >= l_color_min and l_color <= l_color_max) then
       return true;
      end
    end
return false;
end
------------------------------------------------
-- Variable setup
------------------------------------------------
HP = 10000;
MaxHP = HP;
MP = 10000;
MaxMP = MP;
SP = 10000;
MaxSP = SP;

skill1_ready = true;
skill2_ready = true;
skill3_ready = true;
skill4_ready = true;
skill5_ready = true;
skill6_ready = true;

buff1_ready = true;
buff2_ready = true;
buff3_ready = true;
buff4_ready = true;
buff5_ready = true;

------------------------------------------------
-- Functions
------------------------------------------------

skill1_toggle = function () skill1_ready = true; end;
skill2_toggle = function () skill2_ready = true; end;
skill3_toggle = function () skill3_ready = true; end;
skill4_toggle = function () skill4_ready = true; end;
skill5_toggle = function () skill5_ready = true; end;
skill6_toggle = function () skill6_ready = true; end;

buff1_toggle = function () buff1_ready = true; end;
buff2_toggle = function () buff2_ready = true; end;
buff3_toggle = function () buff3_ready = true; end;
buff4_toggle = function () buff4_ready = true; end;
buff5_toggle = function () buff5_ready = true; end;


function use_hp_potion()
  keyboardPress(key_hp_potion);
  keyboardPress(key_hp_potion1);
  keyboardPress(key_hp_potion2);
  keyboardPress(key_hp_potion3);
  keyboardPress(key_hp_potion4);
  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 sit()
  if( HP_sit == 0 ) then
    return; end

  printf("Sitting.\n");

  local sitting = false;
  while( sitting == false ) do
    keyboardPress(key_sit);
    yrest(1000);

    sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
  end

  local lasthp = HP;

  while( true ) do
    if( HP == MaxHP and MP == MaxMP and SP == MaxSP ) then
      switch_target();
      break;
    end

    if( HP < (lasthp - 10) ) then
      printf("Exiting rest...under attack\n");
      break;
    else
      lasthp = HP;
    end

    yrest(100);
  end

  sitting = true;
  while( sitting ) do
    keyboardPress(key_sit);
    yrest(1000);

    sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
  end

  printf("Standing... Resuming bot\n");
  yrest(1000);
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);
end


function have_target()
  local readid = memoryReadShort(proc, targetid_addr);

  return ( readid ~= 0xFFFF );
end

function find_target()
  keyboardPress(key_attack);
end

function switch_target()
  keyboardPress(key_switchtarget);
end

------------------------------------------------
-- FIGHT2
------------------------------------------------
function fight2()
   local beginTime  = os.time();
   local attackLoop = true;
   local skillsonetime = 0;
  keyboardPress(key_attack);
yrest(200);
  
printf("Attacking Target \n");

  while (attackLoop) do
    local targetStatus = targetstatus();
    local Tstatus = status();
    if(targetStatus == TARGET_DEAD) then
       printf("Target Dead \n\n");
       pickup();
       attackLoop = false;
       moveBreak();
    else      
      local currentTime = os.time();
      if( os.difftime(currentTime, beginTime) > how_many_seconds ) then 
         moveBreak();
         beginTime  = os.time();
         if(Tstatus == TARGET_FULL) then
           do_jump = do_jump+1;
           printf("Changing Targets: Obsticle \n\n");
           attackLoop = false;
         end
      else
         if(skillsonetime == 0 and Tstatus == TARGET_DAMAGED) then
           skillsonetime = 1+skillsonetime;
           keyboardPress(key_skill1);
         end;
         keyboardPress(key_attack);
         yrest(2000);
      end
    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




------------------------------------------------
-- MAIN
------------------------------------------------
function main()
  proc = openProcess(findProcessByExe("game.exe"));
  win = findWindow("Shaiya");
  attach(win);
  setPriority(PRIORITY_HIGH);
init_window();
  init_process();
  init_hdc();


  registerTimer("update_vars", 100, update_vars);

  if( skill1_time ) then registerTimer("skill1_toggle", skill1_time, skill1_toggle); end
  if( skill2_time ) then registerTimer("skill2_toggle", skill2_time, skill2_toggle); end
  if( skill3_time ) then registerTimer("skill3_toggle", skill3_time, skill3_toggle); end
  if( skill4_time ) then registerTimer("skill4_toggle", skill4_time, skill4_toggle); end
  if( skill5_time ) then registerTimer("skill5_toggle", skill5_time, skill5_toggle); end
  if( skill6_time ) then registerTimer("skill6_toggle", skill6_time, skill6_toggle); end

  if( buff1_time ) then registerTimer("buff1_toggle", buff1_time, buff1_toggle); end;
  if( buff2_time ) then registerTimer("buff2_toggle", buff2_time, buff2_toggle); end;
  if( buff3_time ) then registerTimer("buff3_toggle", buff3_time, buff3_toggle); end;
  if( buff4_time ) then registerTimer("buff4_toggle", buff4_time, buff4_toggle); end;
  if( buff5_time ) then registerTimer("buff5_toggle", buff5_time, buff5_toggle); end;

local reAttack = 0;

  while( macro_running ) do
    if( buff1_ready  and buff1_time > 0 ) then
      keyboardPress(key_buff1); buff1_ready = false; yrest(2000); end;
    if( buff2_ready  and buff2_time > 0 ) then
      keyboardPress(key_buff2); buff2_ready = false; yrest(2000); end;
    if( buff3_ready  and buff3_time > 0 ) then
      keyboardPress(key_buff3); buff3_ready = false; yrest(2000); end;
    if( buff4_ready  and buff4_time > 0 ) then
      keyboardPress(key_buff4); buff4_ready = false; yrest(2000); end;
    if( buff5_ready  and buff5_time > 0 ) then
      keyboardPress(key_buff5); buff5_ready = false; yrest(2000); end;

    if(cycle_target()) then
       fight2();
       if(do_jump == 1) then
          keyboardHold(key_move_down);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardRelease(key_move_down);
          keyboardHold(key_move_right);
          yrest(2000);
          keyboardRelease(key_move_right);
          keyboardHold(key_move_right);
          yrest(2000);
          keyboardRelease(key_move_right);
          keyboardHold(key_move_down);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardPress(key_jump);
          yrest(1000);
          keyboardRelease(key_move_down);
          do_jump = 0;
       end
       reAttack = 0;
    else
       reAttack = 1 + reAttack;
    end
--printf(reAttack);
    if ( reAttack == how_many_scanTarget ) then
       reAttack = 0;
       keyboardPress(key_myself);
       yrest(500);
       keyboardHold(key_right);
       yrest(500);
       keyboardRelease(key_right);
    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

    if( (HP/MaxHP*100) < HP_sit and (HP_sit > 0) ) then sit(); end
    if( (MP/MaxMP*100) < MP_sit and (MP_sit > 0) ) then sit(); end
    if( (SP/MaxSP*100) < SP_sit and (SP_sit > 0) ) then sit(); end

  if ((HP/MaxHP*100) <= 0) then
    --user_alive = false;
    printf("\n\nPlayer is DEAD");
    keyboardPress(key.VK_DELETE);
    --force_close();
  end    
  end
end

startMacro(main);
doesnt work

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#165 Post by Green200 » Fri Feb 06, 2009 5:14 pm

here's a working version of fighter.lua for version 40 ... I fixed the memory addess issues by looking at working scripts and stopped the constant spinning of the view... made me stomach sick watching it...

I don't think this is supeior to other scripts just wanted to see if I could get it to work and see if the anti-ks stuff worked... works ok but if you're around a defender or ranger using their debuffs to pull distant mobs the script can't determine that and still attacks.
Attachments
fighter.lua
good for Shaiya ver.40
(23.29 KiB) Downloaded 253 times

vvayinsane
Posts: 148
Joined: Fri Mar 21, 2008 9:10 pm

Re: Shaiya Fighter Bot

#166 Post by vvayinsane » Fri Feb 06, 2009 9:49 pm

Yes almost all bots cant tell if someone used a debuff to pull because the game doesnt tell you what buff if any was put on a mob.

If you use this bot and it tells you in micro that the bot is running but nothing happens bellow is how i fixed the problem and the bot still worked for me

-- MAIN
------------------------------------------------
function main()
proc = openProcess(findProcessByExe("game.exe"));
win = findWindow("Shaiya");
-- attach(win);
setPriority(PRIORITY_HIGH);
init_window();
init_process();
init_hdc();

Change to bellow
-- MAIN
------------------------------------------------
function main()
proc = openProcess(findProcessByExe("game.exe"));
win = findWindow("Shaiya");
setPriority(PRIORITY_HIGH);

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#167 Post by Green200 » Fri May 29, 2009 12:47 am

here's an updated version for EP4. One thing that might still be not fully working is the kill verification... it's tied to the targetidaddr of 0x002ABFF0 which may not be correct... not sure.

works only with EP4. Let me know if you find any bugs. I added some anti-ks stuff that checks the targets health if running at the target so that if someone else attacks it while you're running at it then it breaks off. Also, there's a jumping while running part in there that I added since I was testing it on map 2 light, by the boars, foxes and monkeys and needed to jump over the fences.
Attachments
fighter.lua
Ep4 only
(25.88 KiB) Downloaded 190 times

vvayinsane
Posts: 148
Joined: Fri Mar 21, 2008 9:10 pm

Re: Shaiya Fighter Bot

#168 Post by vvayinsane » Fri May 29, 2009 1:28 am

When running the bot i get this in my error log.

Quote:
Thu May 28 23:13:08 2009 : Executing script "fighter.lua".
==================================================

Thu May 28 23:19:43 2009 : Execution of fighter.lua complete.
Thu May 28 23:19:43 2009 : Execution success.
Thu May 28 23:19:43 2009 : Collecting garbage...
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E920.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E748.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E720.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E6F8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E6D0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E6A8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E680.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E5B8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E590.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E568.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E540.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E518.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E4F0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E4C8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E4A0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E478.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E450.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E428.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E400.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E3D8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E3B0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E388.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E360.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E338.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E310.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E2C0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E298.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E248.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E220.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E1F8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E1D0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E1A8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E180.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E158.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E130.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E108.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E0E0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7E068.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DF58.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DF08.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DE90.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DE68.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DE40.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DE18.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DDF0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DDC8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DD78.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DD50.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DD28.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DD00.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DCD8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DCB0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DC88.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DC10.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DB08.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DA90.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DA68.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DA40.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7DA18.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D9F0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D9C8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D9A0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D978.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D928.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D900.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D8B0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D888.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D860.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D838.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D810.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D7E8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D7C0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D798.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D770.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D748.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D6D0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D5C8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D550.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D528.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D500.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D4D8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D4B0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D488.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D460.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D438.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D3E8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D3C0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D370.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D348.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D320.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D2F8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D2D0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D2A8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D280.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D258.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D230.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D208.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D190.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D088.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7D010.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64CA0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64C78.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64C50.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64C00.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64BD8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64BB0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64B60.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64B38.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64B10.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64AE8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64AC0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64A98.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64A70.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64A48.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64A20.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA649F8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64980.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64878.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64800.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA647D8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA647B0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64788.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64760.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64738.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64710.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA646E8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA646C0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64698.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64670.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64648.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64620.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA645F8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA64558.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA600A0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60050.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FFD8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FFB0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FF88.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FF60.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FF38.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FF10.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FEE8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FEC0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FE48.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FE20.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FDF8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FDD0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FDA8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FD80.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FD58.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FD30.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FD08.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FCE0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FC68.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FB60.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FAC0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FA98.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FA70.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FA48.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5FA20.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5F9F8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5F9D0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5F9A8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60E88.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60D80.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60D08.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60CE0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60CB8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60C90.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60C68.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60C40.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60C18.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60BF0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60B50.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60A48.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA609D0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA609A8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60980.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60958.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60930.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA60908.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA608E0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50E38.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50E10.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50DE8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50D98.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50D70.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50D48.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50D20.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50CF8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7CFE8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7CFC0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7CF98.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7CF70.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA7CEF8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA30360.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA30DA8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA30D80.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA52C28.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA52C00.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA52BD8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA41708.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4A700.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA49420.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA3E4C0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6DE38.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA45D40.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA63B30.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4A5E8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA43E38.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4CD58.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4CAF8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4D0B0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4DF38.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5DEB0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5DF00.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5DF50.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5DFC8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0x9FF6A0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0x9FF6E8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA52968.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA52A70.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA358A0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA528A0.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA4FC20.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA41E40.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA44A28.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA35928.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E4B8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA52990.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E440.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E418.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E3C8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E378.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E328.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E2D8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E288.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E238.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E198.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E148.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E0A8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E058.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E008.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50FF8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50FA8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50F58.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50F08.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50EB8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA50E68.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6DFB8.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6DE90.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA5E070.
Thu May 28 23:19:43 2009 : GC closed device context handle 0xA6E490.
Thu May 28 23:19:43 2009 : GC closed process handle 0x7C.
Thu May 28 23:19:43 2009 : 71KB freed.
The bot is working. only problem i see is maybe due to the above is that the bot will think its stuck and he wont move and the screen will keep circling and wont stop. If im being attack the bot does nothing.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Shaiya Fighter Bot

#169 Post by Administrator » Fri May 29, 2009 3:55 am

Wow, that's a lot of opening and closing of process handles. That's just letting you know there is a bug in the code that's causing it to call openProcess(), and then forgetting the variable. If it weren't for the garbage collection routine, that would be a massive memory leak, and use a ton of handles (and yes, there are a limit to how many handles you can have open).

My guess is that the handle is being loaded into a local variable. It should be global.

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#170 Post by Green200 » Fri May 29, 2009 11:15 am

Ah, I never have looked in the logfile! D'oh!

As I'm not a real coder it's possible I created that... I'm a script modifier only :/

vvayinsane
Posts: 148
Joined: Fri Mar 21, 2008 9:10 pm

Re: Shaiya Fighter Bot

#171 Post by vvayinsane » Fri May 29, 2009 4:28 pm

Hey i got the bot to work. I used the version 1.0 beta 5 and i have not have the leak since.

basiclight
Posts: 9
Joined: Sat May 23, 2009 8:35 pm

Re: Shaiya Fighter Bot

#172 Post by basiclight » Fri May 29, 2009 6:15 pm

do you have alink to download the file
vvayinsane wrote:Hey i got the bot to work. I used the version 1.0 beta 5 and i have not have the leak since.

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#173 Post by Green200 » Fri May 29, 2009 6:59 pm

I went to the lua wiki and read up on the Garbage Collector... then thought that maybe having

Code: Select all

local <variable> = "x";


inside of "while" loops that repeated may be the issue... so I pulled all of the local definitions out of the loops and it seems to have fixed the memory leak with 0.99. I also tested it with 1.00 beta and it worked too... with no leaks. Note, this was a quick test and I didn't test all the functionality... would someone please do that since I won't be on this weekend? Here's the updated .lua...
Attachments
fighter.lua
EP4, no memory leak with 0.99/1.00 but needs further testing
(26.13 KiB) Downloaded 222 times

vvayinsane
Posts: 148
Joined: Fri Mar 21, 2008 9:10 pm

Re: Shaiya Fighter Bot

#174 Post by vvayinsane » Sun May 31, 2009 12:18 am

How can we make the bot do the skills in order? I am sin in game

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#175 Post by Green200 » Mon Jun 01, 2009 12:04 pm

vvayinsane wrote:How can we make the bot do the skills in order? I am sin in game
check your inbox

centik
Posts: 51
Joined: Sat Apr 19, 2008 2:03 am

Re: Shaiya Fighter Bot

#176 Post by centik » Mon Jun 01, 2009 4:29 pm

ok i tried both script with 1.0 beta and .99 but it seems kinda glitching on me..it kept on scanning his sorounding but when he does locks on his attack he jumps 2x run on to that target and attack but even the mob not dead he started scanning again and run up to the other mob and does nothing..i also notice he doesnt pick up the loot..and my screen keeps on spinning non stop and he keeps jumping around :/ ..does this work only on specific resolution..i only tried it on 1900 x 1080 and 1024 x 768 but still get the same result


edit:

this is what my bot did using 1.0 beta
MicroMacro v1.0
SolarStrike Software
http://www.solarstrike.net
Please enter the script name to run.
Type in 'exit' (without quotes) to exit.
Script> fighter.lua
Opening fighter.lua...
Starting script execution - Press CTRL+C to exit.
Press CTRL+L to cancel execution and low a new script.
-------------------------------------------------------------------------------
The macro is currently not running. Press the start key (F5) to begin.
You may use (F6) key to stop/pause the script.
Started.
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Attacking Target
Target Dead

Pickup!
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Attacking Target
Changing Targets: Obsticle

target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Changing Targets: Obstacle

TARGET_DAMAGED breaking-off attack
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Attacking Target
Target Dead

Pickup!
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Attacking Target
Paused.
it says on log he picked up but he never did

using 0.99
MicroMacro v0.99
SolarImpact
http://solarimpact.servegame.com


Please enter the script name to run.
Type in 'exit' (without quotes) to exit.
Script> fighter.lua
Opening fighter.lua...

Starting script execution - Press CTRL+C to exit.
Press CTRL+L to cancel execution and load a new script.
-------------------------------------------------
The macro is currently not running. Press the start key (Insert) to begin.
You may use (Delete) key to stop/pause the script.
Started.
target_difficulty_color: 4
getting difficulty Color
Attacking Target
Changing Targets: Obsticle

target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Attacking Target
Target Dead

Pickup!
TARGET_DAMAGED breaking-off attack
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Changing Targets: Obstacle

target_difficulty_color: 3
getting difficulty Color
TARGET_UNKNOWN
target_difficulty_color: 3
getting difficulty Color
TARGET_UNKNOWN
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Changing Targets: Obstacle

target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Attacking Target
Changing Targets: Obsticle

TARGET_DAMAGED breaking-off attack
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Paused.
he prolly killed 2 out of 10 he locked on..some coz the character thinks theres an obsticle then in some he attacks but half way through he backs of like hes ksing someone so end result he got like bunch of mob chasing him while jumping around :D nad still didnt pick up loot

both bot was in map 1 boars fury side

the script i used:
on = true;
off = false;
------------------------------------------------
-- HOTKEYS
------------------------------------------------
macro_running = on; -- leave this ON!

startKey = key.VK_INSERT;
stopKey = key.VK_DELETE;

key_switchtarget = key.VK_TILDE;

key_attack = key.VK_1;
key_pickup = key.VK_Y;

key_skill1 = key.VK_3;
key_skill2 = key.VK_4;
key_skill3 = key.VK_5;

key_buff1 = key.VK_6;
key_buff2 = key.VK_7;
key_buff3 = key.VK_8;

-- key_hp_potion = key.VK_8;
key_hp_potion1 = key.VK_NUMPAD1;
key_hp_potion2 = key.VK_NUMPAD2;
key_hp_potion3 = key.VK_NUMPAD3;
key_hp_potion4 = key.VK_NUMPAD4;
key_hp_potion5 = key.VK_NUMPAD5;
key_hp_potion6 = key.VK_NUMPAD6;
key_hp_potion7 = key.VK_NUMPAD7;
key_hp_potion8 = key.VK_NUMPAD8;
key_hp_potion9 = key.VK_NUMPAD9;
key_hp_potion0 = key.VK_NUMPAD0;
key_mp_potion = key.VK_9;
key_sp_potion = key.VK_0;

key_sit = key.VK_C;
key_move_down = key.VK_S;
key_move_right= key.VK_E;
key_move_forward= key.VK_W;
key_myself = key.VK_F1;
key_jump = key.VK_SPACE;
key_home = key.VK_HOME;
key_right = key.VK_RIGHT;
key_zoom_out = key.VK_PAGEDOWN;
do_jump = 0;
--- Don't touch the code above or the program will act differently/not work unless you kknow how to-----------------------


--------------------------------------------------------
-- If the target's hp is not full how many time you want it to scan for targets with full hp.
-- Note: Lag issue will happen. if the target's Hp is still loading it will switch targets.
-- This code prevents it from ksing other people's damaged mobs
-- Default is 4 but adjust it to your mobs zone
--------------------------------------------------------

how_many_scanTarget = 6;

--------------------------------------------------------
-- How many seconds you want to keep locking on the target. If the target's Hp is full for more than 15
-- seconds then that means you are stuck behind a wall, So the macro will change target.
-- Default is 15, if the mob is more spread apart adjust it with a higher number.
--------------------------------------------------------

how_many_seconds = 10;


--------------------------------------------------------
--How many time you want to pick up items after mob is dead.
--Default is 3. In some cases 4 should pick up every drop.
--------------------------------------------------------


how_many_pickup = 4;


--------------------------------------------------------
--How much time in msecs you want to check the target for damage while running at it
--Default is 250. In some cases that can lag a little and higher may be better for you
--------------------------------------------------------


how_long_ks_check = 750;


--------------------------------------------------------
--Sets whether you jump while you run at target. Will jump once per number of
--"how_long_ks_check" time intervals, e.g. 1 is every ks_check, 2 is every other, etc.
--------------------------------------------------------

ks_check_per_jump = 2;

--------------------------------------------------------
-- Choose what range of Colored Mob you would want your Fighter
-- To kill. This way your fighter does not run all over the map.
-- Default is min 3 max 3. Which means the micro will only target blue mobs.
--------------------------------------------------------
target_difficulty_color_min= 4;
target_difficulty_color_max= 4;
--white = 1
--cyan = 2
--blue = 3
--green = 4
--yellow = 5
--orange = 6
--red = 7
--purple = 8
--grey = 9


------------------------------------------------
-- SKILLS secondsToTimer(x);
------------------------------------------------
-- Set to 0 if you don't want to use a skill
skill1_time = secondsToTimer(3);
skill2_time = secondsToTimer(5);
skill3_time = secondsToTimer(7);


------------------------------------------------
-- BUFFS
------------------------------------------------
-- Set a buff to 0 if you don't want to use it
buff1_time = minutesToTimer(4);
buff2_time = minutesToTimer(4);
buff3_time = minutesToTimer(9);
------------------------------------------------
-- POTIONS
------------------------------------------------
-- All potion use values are specified in %
-- Set the values to 0 to not use that potion
HP_potion_use = 33;
MP_potion_use = 10;
SP_potion_use = 20;


------------------------------------------------
-- SITTING
------------------------------------------------
-- All sitting values are specified in %
-- We will only sit while out of battle
-- Set the values to 0 to not use sitting
HP_sit = 30;
MP_sit = 0;
SP_sit = 0;


--[[*********************************************************************
**************************************************************************
DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
**************************************************************************
************************************************************************]]
------------------------------------------------
-- Memory addresses
------------------------------------------------
playerptr_addr = 0x0083DDF4; -- EP4
targetid_addr = 0x002ABFF0; -- EP4 try 0x006d0bc4
sitcheck_addr = 0x006FDE80; --EP4
-- byte, 0 = standing, 7 = sitting, 1 = moving, 2 = animation, 3 = jumping, 5 = process of sitting, 6 = process of standing
swimcheck_addr = 0x006FDE64; -- EP4 or 0x006FDE68

HP_offset = 300;
MaxHP_offset = 304;
MP_offset = 308;
MaxMP_offset = 312;
SP_offset = 316;
MaxSP_offset = 320;


--------------------------------------------------------------------------
function init_window()
win = findWindow("Shaiya");
if(win == nil) then
printf(error_init);
macro_running = false;
end
end

function init_process()
proc = openProcess( findProcessByExe("game.exe") );
if(proc == 0) then
printf("error opening process.\n");
macro_running = false;
end
end

function init_hdc()
hdc = openDC(get_win());
local wx, wy, ww, wh = windowRect(get_win());
end

function get_hdc()
hdc = openDC(get_win());
return hdc;
end

function get_win()
return win;
end

function debug_message(msg)
if (g_debug) then
print(msg);
logMessage(msg);
end
end

window_mode = false;

g_debug = true;

function target()
keyboardPress(key_switchtarget);
yrest(200);
end

function moveBreak()
keyboardHold(key_move_down);
yrest(500);
keyboardRelease(key_move_down);
end

function pickup()
printf("Pickup!\n");
if( key_pickup == 0 ) then return; end
local i;
for i = 0, how_many_pickup do
keyboardPress(key_pickup);
if( i == 0) then
yrest(400);
else
yrest(300);
end
end
end


function pot_check()
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

--------------------------------------------------------------------------------
-- Memory Addresses.
TARGET_POS_X_ADDRESS = 0x2202E0C;
TARGET_POS_Y_ADDRESS = 0x2202E10;
TARGET_POS_Z_ADDRESS = 0x2202E14;
TARGET_TYPE_ADDR = 0x0619B1F;

-- Field Values.
TARGET_UNKNOWN = 0;
TARGET_DAMAGED = 1;
TARGET_FULL = 2;
TARGET_DEAD = 3;

TARGET_BAR_COLOR = {
-- r_min=150, r_max=180, EP3
r_min=173, r_max=176, -- EP4
g_min=10, g_max=40,
b_min=50, b_max=80
};

-- Status Info Bar, offset.
STATUSINFOBAR_POS = {x=0, y=0};

-- Target Health Bar location relative to 0,0 of Status Info Bar
TARGET_HEALTH_BAR_PIXEL_OFFSET_1 = {x=42, y=43};
TARGET_HEALTH_BAR_PIXEL_OFFSET_2 = {x=179, y=43};
TARGET_HEALTH_BAR_PIXEL_OFFSET_3 = {x=110, y=43};

-- Target Name Color
TARGET_NAME_COLOR_SCAN_OFFSET_1 = {x=51, y=24};
TARGET_NAME_COLOR_SCAN_OFFSET_2 = {x=152, y=24};


target_name_color = {
unknown=0,
white=1,
cyan=2,
blue=3,
green=4,
yellow=5,
orange=6,
red=7,
purple=8,
grey=9,
};

--[[TARGET_NAME_COLOR_WHITE = 1;
TARGET_NAME_COLOR_CYAN = 2;
TARGET_NAME_COLOR_BLUE = 3;
TARGET_NAME_COLOR_GREEN = 4;
TARGET_NAME_COLOR_YELLOW = 5;
TARGET_NAME_COLOR_ORANGE = 6;
TARGET_NAME_COLOR_RED = 7;
TARGET_NAME_COLOR_PURPLE = 8;
TARGET_NAME_COLOR_GREY = 9;]]


-- In order of difficulty, from easiest to hardest.
target_name_color_rgb = {
[target_name_color["white"]] = {r_min=255, r_max=255,
g_min=255, g_max=255,
b_min=255, b_max=255},
[target_name_color["cyan"]] = {r_min=120, r_max=140,
g_min=255, g_max=255,
b_min=255, b_max=255},
[target_name_color["blue"]] = {r_min=0, r_max=0,
g_min=0, g_max=0,
b_min=253, b_max=255},
[target_name_color["green"]] = {r_min=0, r_max=0,
g_min=1, g_max=255,
b_min=0, b_max=0},
[target_name_color["yellow"]] = {r_min=253, r_max=255,
g_min=253, g_max=255,
b_min=0, b_max=0},
[target_name_color["orange"]] = {r_min=255, r_max=255,
g_min=128, g_max=128,
b_min=0, b_max=0},
[target_name_color["red"]] = {r_min=255, r_max=255,
g_min=0, g_max=0,
b_min=0, b_max=0},
[target_name_color["purple"]] = {r_min=255, r_max=255,
g_min=0, g_max=0,
b_min=255, b_max=255},
--[target_name_color["grey"]] = {r_min=255, r_max=255,
-- g_min=255, g_max=255,
-- b_min=255, b_max=255},
}


TARGET_TYPE_FRIENDLY = 0;
TARGET_TYPE_NOTHING = -1;




-- Looks at pixels in the status info bar in the h/w device context,
-- to determine the status of the monster.
-- note - this has known errors, changing the colour bit value, or restarting PC
-- seems to fix it.
-- @return TARGET_UNKNOWN does not have any detectable red bar.
-- TARGET_DAMAGED if some red bar exists.
-- TARGET_FULL full red bar.

function status() -- new EP4 status
local l_hdc = get_hdc();
local rrb,ggb,bbb;
local rre,gge,bbe;

rre,gge,bbe = getPixel(l_hdc, TARGET_HEALTH_BAR_PIXEL_OFFSET_2["x"], TARGET_HEALTH_BAR_PIXEL_OFFSET_2["y"]); -- Check if full health
if( rre >= TARGET_BAR_COLOR["r_min"] and rre <= TARGET_BAR_COLOR["r_max"] ) then
return TARGET_FULL;
else
rrb,ggb,bbb = getPixel(l_hdc, TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"], TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"]); -- Check if zero health, target may not be dead!
if( rrb >= TARGET_BAR_COLOR["r_min"] and rrb <= TARGET_BAR_COLOR["r_max"] ) then
return TARGET_DAMAGED;
else
return TARGET_UNKNOWN;
end
end
end


-- Gets the monster difficulty color, by reading each pixel in a small fixed
-- line in the middle through the top of the lower case letters,
-- in the monster name label.
-- @return The color index of the name text on success, 0 on failure.
function get_difficulty_color()
local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["x"]),
y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["y"])};
local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["x"]),
y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["y"])};

local pr, pg, pb;
--local l_color = TARGET_NAME_COLOR_UNKNOWN;
--local hdc = openDC(shaiya_win);
local l_hdc = get_hdc();
for i=pos_1["x"], pos_2["x"] do
for j=pos_1["y"], pos_2["y"] do
if (window_mode) then
local wx, wy = windowRect(get_win());
printf("win_x: %d, wim_y: %d\n", wx, wy);
pr, pg, pb = getPixel(l_hdc, wx + i, wy + j);
else
pr, pg, pb = getPixel(l_hdc, i, j);
end
--debug_message(sprintf("pr: %d, pg: %d, pb: %d", pr, pg, pb));
for k,v in pairs(target_name_color_rgb) do
--printf("v[r]: %d, v[g]: %d, v: %d\n", v["r"], v["g"], v["b"]);
if(pr >= v["r_min"] and pr <= v["r_max"] and
pg >= v["g_min"] and pg <= v["g_max"] and
pb >= v["b_min"] and pb <= v["b_max"]) then
printf("target_difficulty_color: %s\n", k);
return k;
end
end
end
end
--closeDC(hdc);
return target_name_color["unknown"];
end

-------------------------------------------------------------------
-- Modification to see if Target is Dead or FULL HP

function targetstatus() -- new EP4 targetstatus
local l_hdc = get_hdc();
local rrb,ggb,bbb;

rrb,ggb,bbb = getPixel(l_hdc, TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"], TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"]); -- Check if any health
if( rrb >= TARGET_BAR_COLOR["r_min"] and rrb <= TARGET_BAR_COLOR["r_max"] ) then
return TARGET_FULL;
end
return TARGET_DEAD;
end


------------------------------------------------------------------------

-----------------------------------------------------------------------------------
--*******Cycle Target to see if It matches your minimum and maximum color monster ********
function cycle_target()
if( (HP/MaxHP*100) < HP_sit and (HP_sit > 0) ) then
return false;
end
--printf("self.switched_targets: %d\n", self.switched_targets);
--printf("self.max_switch_targets: %d\n", self.max_switch_targets);
keyboardHold(key.VK_DOWN);
yrest(100);
--debug_message("new_target");
target();
local target_status = status();
--printf("target_color: %d\n", target_color);
--printf("target_status=%d\n", target_status);
--logMessage(sprintf("target_status=%d", target_status));

if (target_status == TARGET_FULL) then
local l_color = get_difficulty_color();
local l_color_min = target_difficulty_color_min;
local l_color_max = target_difficulty_color_max;
printf("getting difficulty Color \n");
if (l_color >= l_color_min and l_color <= l_color_max) then
keyboardRelease(key.VK_DOWN);
-- Addition to check for damaged target while running at it
local running;
local jumping;
local beginTime;
local jump_count;
local currentTime;
keyboardPress(key_attack);
yrest(100);
running = memoryReadByte(proc, sitcheck_addr) == 1;
jumping = memoryReadByte(proc, sitcheck_addr) == 3;
beginTime = os.time();
jump_count = 1;
while( (running or jumping) and target_status == TARGET_FULL) do
running = memoryReadByte(proc, sitcheck_addr) == 1;
jumping = memoryReadByte(proc, sitcheck_addr) == 3;
target_status = status();
if( (running or jumping) and target_status ~= TARGET_FULL) then
return false;
end
currentTime = os.time();
if( os.difftime(currentTime, beginTime) > how_many_seconds ) then
moveBreak();
beginTime = os.time();
if(target_status == TARGET_FULL) then
do_jump = do_jump+1;
printf("Changing Targets: Obstacle \n\n");
return false;
else
keyboardPress(key_jump);
yrest(750);
moveBreak();
keyboardPress(key_attack);
end
else
if (jump_count < ks_check_per_jump) then
jump_count = jump_count + 1;
else
keyboardPress(key_jump);
printf("Jump! \n");
jump_count = 1;
end
end
-- printf("running and target full \n");
yrest(how_long_ks_check);
pot_check();
end
-- End of Addition
return true;
end
else
if (target_status ~= TARGET_FULL) then
moveBreak();
printf("TARGET_DAMAGED breaking-off attack \n");
-- keyboardRelease(key.VK_DOWN);
return false;
end
end
moveBreak();
printf("TARGET_UNKNOWN \n");
keyboardRelease(key.VK_DOWN);
return false;
end
-----------------------------------------------------------------------------------
function cycle_target2()
if (target_status == TARGET_FULL) then
local l_color = get_difficulty_color();
local l_color_min = target_difficulty_color_min;
local l_color_max = target_difficulty_color_max;
if (l_color >= l_color_min and l_color <= l_color_max) then
return true;
end
end
return false;
end
------------------------------------------------
-- Variable setup
------------------------------------------------
HP = 10000;
MaxHP = HP;
MP = 10000;
MaxMP = MP;
SP = 10000;
MaxSP = SP;

skill1_ready = true;
skill2_ready = true;
skill3_ready = true;

buff1_ready = true;
buff2_ready = true;
buff3_ready = true;

------------------------------------------------
-- Functions
------------------------------------------------

skill1_toggle = function () skill1_ready = true; end;
skill2_toggle = function () skill2_ready = true; end;
skill3_toggle = function () skill3_ready = true; end;

buff1_toggle = function () buff1_ready = true; end;
buff2_toggle = function () buff2_ready = true; end;
buff3_toggle = function () buff3_ready = true; end;

function use_hp_potion()
-- keyboardPress(key_hp_potion);
keyboardPress(key_hp_potion1);
keyboardPress(key_hp_potion2);
keyboardPress(key_hp_potion3);
keyboardPress(key_hp_potion4);
keyboardPress(key_hp_potion5);
keyboardPress(key_hp_potion6);
keyboardPress(key_hp_potion7);
keyboardPress(key_hp_potion8);
keyboardPress(key_hp_potion9);
keyboardPress(key_hp_potion0);
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 sit()
if( HP_sit == 0 ) then
return; end
keyboardPress(key_myself);
printf("Sitting.\n");

local sitting = false;
local swimming;
keyboardHold(key.VK_RIGHT);
while( sitting == false ) do
yrest(200);
keyboardPress(key_sit);
yrest(1000);
sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
swimming = memoryReadByte(proc, swimcheck_addr) == 1;
if (swimming) then
break;
end
end

local lasthp = HP;

while( true ) do
if( HP == MaxHP and MP == MaxMP and SP == MaxSP ) then
-- keyboardRelease(key.VK_RIGHT);
-- keyboardPress(key_myself);
yrest(100);
-- switch_target();
break;
end

if( HP < (lasthp - 10) ) then
sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
if (sitting == false) then
printf("Exiting rest...under attack\n");
keyboardRelease(key.VK_RIGHT);
switch_target();
fight2();
break;
end
else
lasthp = HP;
end

yrest(100);
end

sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;
while( sitting ) do
if (sitting == false) then
printf("break \n");
break;
end
keyboardPress(key_sit);
yrest(1000);
sitting = memoryReadByte(proc, sitcheck_addr) ~= 0;

end

printf("\nStanding... Resuming bot\n\n");
keyboardHold(key_zoom_out);
yrest(500);
keyboardRelease(key_zoom_out);
-- keyboardPress(key_myself);
-- keyboardHold(key.VK_RIGHT);
-- yrest(1000);
switch_target(); -- new after commenting above 3 lines
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);
end


function have_target()
local readid = memoryReadShort(proc, targetid_addr);
return ( readid ~= 0xFFFF );
end

function find_target()
keyboardPress(key_attack);
end

function switch_target()
keyboardPress(key_switchtarget);
end

------------------------------------------------
-- FIGHT2
------------------------------------------------
function fight2()
local currtarget = memoryReadShort(proc, targetid_addr);
keyboardRelease(key.VK_RIGHT);
local beginTime = os.time();
local attackLoop = true;
local skillsonetime = 0;


keyboardPress(key_attack);
yrest(100);

printf("Attacking Target \n");
local targetStatus;
local Tstatus;
local currentTime;
local checktarget;
while (attackLoop) do
targetStatus = targetstatus();
Tstatus = status();
if(targetStatus == TARGET_DEAD) then
printf("Target Dead \n\n");
pickup();
attackLoop = false;
moveBreak();
else
currentTime = os.time();
if( os.difftime(currentTime, beginTime) > how_many_seconds ) then
moveBreak();
beginTime = os.time();
if(Tstatus == TARGET_FULL) then
do_jump = do_jump+1;
printf("Changing Targets: Obsticle \n\n");
attackLoop = false;
end
else

-- from gen_solo
if( skill1_ready and skill1_time > 0 ) then
keyboardPress(key_skill1); skill1_ready = false; yrest(1000);
-- registerTimer("skill1_toggle", skill1_time, skill1_toggle);
-- keyboardPress(key_attack);
end;

if( skill2_ready and skill2_time > 0) then
keyboardPress(key_skill2); skill2_ready = false; yrest(1000);
-- registerTimer("skill2_toggle", skill2_time, skill2_toggle);
-- keyboardPress(key_attack);
end;

if( skill3_ready and skill3_time > 0) then
keyboardPress(key_skill3); skill3_ready = false; yrest(1000);
-- registerTimer("skill3_toggle", skill3_time, skill3_toggle);
-- keyboardPress(key_attack);
end;
-- from gen solo end


-- if(skillsonetime == 0 and Tstatus == TARGET_DAMAGED) then
-- skillsonetime = 1+skillsonetime;
-- keyboardPress(key_skill1);
-- end;

checktarget = memoryReadShort(proc, targetid_addr);
-- printf("currtarget = %d \n",currtarget);
-- printf("checktarget = %d \n",checktarget);
if(checktarget == currtarget) then
keyboardPress(key_attack);
else
moveBreak();
printf("Target Dead 2nd \n\n");
pickup();
attackLoop = false;
end
yrest(1000);
end
end
pot_check();
end
end




------------------------------------------------
-- MAIN
------------------------------------------------
function main()
proc = openProcess(findProcessByExe("game.exe"));
win = findWindow("Shaiya");
-- attach(win);
setPriority(PRIORITY_HIGH);
-- init_window();
-- init_process();
-- init_hdc();


registerTimer("update_vars", 100, update_vars);

if( skill1_time ) then registerTimer("skill1_toggle", skill1_time, skill1_toggle); end
if( skill2_time ) then registerTimer("skill2_toggle", skill2_time, skill2_toggle); end
if( skill3_time ) then registerTimer("skill3_toggle", skill3_time, skill3_toggle); end

if( buff1_time ) then registerTimer("buff1_toggle", buff1_time, buff1_toggle); end;
if( buff2_time ) then registerTimer("buff2_toggle", buff2_time, buff2_toggle); end;
if( buff3_time ) then registerTimer("buff3_toggle", buff3_time, buff3_toggle); end;

local reAttack = 0;
keyboardHold(key_zoom_out);
yrest(500);
keyboardRelease(key_zoom_out);
keyboardHold(key.VK_RIGHT); -- Makes sure ALL nearby targets are loaded so you always select the nearest target, not just just the nearest target that is visible.
while( macro_running ) do
if( buff1_ready and buff1_time > 0 ) then
keyboardPress(key_buff1); buff1_ready = false; yrest(2000); end;
if( buff2_ready and buff2_time > 0 ) then
keyboardPress(key_buff2); buff2_ready = false; yrest(2000); end;
if( buff3_ready and buff3_time > 0 ) then
keyboardPress(key_buff3); buff3_ready = false; yrest(2000); end;

if(cycle_target()) then
fight2();
if(do_jump == 1) then
keyboardHold(key_move_down);
keyboardPress(key_jump);
yrest(1000);
keyboardPress(key_jump);
yrest(1000);
keyboardRelease(key_move_down);
keyboardHold(key_move_right);
yrest(2000);
keyboardRelease(key_move_right);
do_jump = 0;
end

keyboardHold(key.VK_RIGHT); -- Makes sure ALL nearby targets are loaded so you always select the nearest target, not just just the nearest target that is visible.

reAttack = 0;
else
reAttack = 1 + reAttack;
end
--printf(reAttack);
if ( reAttack == how_many_scanTarget ) then
reAttack = 0;
keyboardPress(key_myself);
yrest(500);
--keyboardHold(key_right);
--yrest(500);
--keyboardRelease(key_right);
end


pot_check();

if( (HP/MaxHP*100) < HP_sit and (HP_sit > 0) ) then sit(); end
if( (MP/MaxMP*100) < MP_sit and (MP_sit > 0) ) then sit(); end
if( (SP/MaxSP*100) < SP_sit and (SP_sit > 0) ) then sit(); end

if ((HP/MaxHP*100) <= 0) then
--user_alive = false;
printf("\n\nPlayer is DEAD");
keyboardPress(key.VK_DELETE);
--force_close();
end
end
end

startMacro(main);


ok..i really love this bot coz i like the anti ks feature and u can stack up on pots and i really wanna know how to fix this :D

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#177 Post by Green200 » Mon Jun 01, 2009 6:29 pm

Pickup: my pickup key is "Y". You'll need to set yours to that or change this line to yours:

key_pickup = key.VK_Y;

Also, so far as how far a mob is away is allowed by:

how_many_seconds = 10;

try changing that to 15

how many times it jumps per ks_check is:

ks_check_per_jump = 2;

if you increase that number you actually get less jumps per ks check cycle

It won't lock onto a target it doesn't see as full health so that's why it spins so much. The mob has to be visible in the GUI for the target bar to show the mob health.

I've only used it at 1024 x 768 window mode. The target status bar has to be in the upper left corner.

Not sure i've fully helped you but try those changes and report back. Thanks.

centik
Posts: 51
Joined: Sat Apr 19, 2008 2:03 am

Re: Shaiya Fighter Bot

#178 Post by centik » Mon Jun 01, 2009 6:59 pm

Green200 wrote:Pickup: my pickup key is "Y". You'll need to set yours to that or change this line to yours:

key_pickup = key.VK_Y;

Also, so far as how far a mob is away is allowed by:

how_many_seconds = 10;

try changing that to 15

how many times it jumps per ks_check is:

ks_check_per_jump = 2;

if you increase that number you actually get less jumps per ks check cycle

It won't lock onto a target it doesn't see as full health so that's why it spins so much. The mob has to be visible in the GUI for the target bar to show the mob health.

I've only used it at 1024 x 768 window mode. The target status bar has to be in the upper left corner.

Not sure i've fully helped you but try those changes and report back. Thanks.

tnx for the quick reply..

ok my bot seems better this time but still have constant spinning and jumping but not like b4 and i notice he still dont wanna pick up,he sees the item and about to pick up but instantly he shy away on picking the loot up..couple of time after running it for 3 minutes he let go 2 mobs..hitting them then break off and look for another one

sorry for asking too many question. :/

btw hes my battle log
MicroMacro v1.0
SolarStrike Software
http://www.solarstrike.net
Please enter the script name to run.
Type in 'exit' (without quotes) to exit.
Script> fighter.lua
Opening fighter.lua...
Starting script execution - Press CTRL+C to exit.
Press CTRL+L to cancel execution and low a new script.
-------------------------------------------------------------------------------
The macro is currently not running. Press the start key (F5) to begin.
You may use (F6) key to stop/pause the script.
Started.
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Attacking Target
Target Dead

Pickup!
TARGET_DAMAGED breaking-off attack
TARGET_DAMAGED breaking-off attack
TARGET_DAMAGED breaking-off attack
TARGET_DAMAGED breaking-off attack
TARGET_DAMAGED breaking-off attack
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Attacking Target
Target Dead

Pickup!
target_difficulty_color: 4
getting difficulty Color
Attacking Target
Target Dead

Pickup!
target_difficulty_color: 4
getting difficulty Color
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Jump!
Attacking Target
Changing Targets: Obsticle

TARGET_DAMAGED breaking-off attack
TARGET_DAMAGED breaking-off attack
target_difficulty_color: 4
getting difficulty Color
Attacking Target
Paused.

this is what i did with my config
key_attack = key.VK_1;
key_pickup = key.VK_2;

key_skill1 = key.VK_3;
key_skill2 = key.VK_4;
key_skill3 = key.VK_5;

key_buff1 = key.VK_6;
key_buff2 = key.VK_7;
key_buff3 = key.VK_8;

-- key_hp_potion = key.VK_8;
key_hp_potion1 = key.VK_NUMPAD1;
key_hp_potion2 = key.VK_NUMPAD2;
key_hp_potion3 = key.VK_NUMPAD3;
key_hp_potion4 = key.VK_NUMPAD4;
key_hp_potion5 = key.VK_NUMPAD5;
key_hp_potion6 = key.VK_NUMPAD6;
key_hp_potion7 = key.VK_NUMPAD7;
key_hp_potion8 = key.VK_NUMPAD8;
key_hp_potion9 = key.VK_NUMPAD9;
key_hp_potion0 = key.VK_NUMPAD0;
key_mp_potion = key.VK_9;
key_sp_potion = key.VK_0;

key_sit = key.VK_C;
key_move_down = key.VK_S;
key_move_right= key.VK_E;
key_move_forward= key.VK_W;
key_myself = key.VK_F1;
key_jump = key.VK_SPACE;
key_home = key.VK_HOME;
key_right = key.VK_RIGHT;
key_zoom_out = key.VK_PAGEDOWN;
do_jump = 0;
--- Don't touch the code above or the program will act differently/not work unless you kknow how to-----------------------


--------------------------------------------------------
-- If the target's hp is not full how many time you want it to scan for targets with full hp.
-- Note: Lag issue will happen. if the target's Hp is still loading it will switch targets.
-- This code prevents it from ksing other people's damaged mobs
-- Default is 4 but adjust it to your mobs zone
--------------------------------------------------------

how_many_scanTarget = 6;

--------------------------------------------------------
-- How many seconds you want to keep locking on the target. If the target's Hp is full for more than 15
-- seconds then that means you are stuck behind a wall, So the macro will change target.
-- Default is 15, if the mob is more spread apart adjust it with a higher number.
--------------------------------------------------------

how_many_seconds = 15;


--------------------------------------------------------5s2
--How many time you want to pick up items after mob is dead.
--Default is 3. In some cases 4 should pick up every drop.
--------------------------------------------------------


how_many_pickup = 3;


--------------------------------------------------------
--How much time in msecs you want to check the target for damage while running at it
--Default is 250. In some cases that can lag a little and higher may be better for you
--------------------------------------------------------


how_long_ks_check = 250;


--------------------------------------------------------
--Sets whether you jump while you run at target. Will jump once per number of
--"how_long_ks_check" time intervals, e.g. 1 is every ks_check, 2 is every other, etc.
--------------------------------------------------------

ks_check_per_jump = 2;

Green200
Posts: 23
Joined: Fri Feb 06, 2009 5:10 pm

Re: Shaiya Fighter Bot

#179 Post by Green200 » Tue Jun 02, 2009 12:02 pm

It looks like your framerate may be impacting the speed. Type "H" and look and report what your framerate is.

I had set my pickup timer to be 400 msec (1st pickup) and 300 msec (subsequent). But noticed that when I had lag the pickup didn't work and I had to set it longer. On line 224 you'll find the pickup function. Change both the 400 and 300 to longer... say 500 or 750 and keep playing with it until it starts working.

Also, I found the default of how_long_ks_check of 250 msec is kind of low and can cause some poor performance due to the programming cycles of the anti ks routine. I had to changed mine to 750 msec. When I look at your number of jumps between id'ing the target and attacking... I see 15 jumps... with 2 ks-checks per jump that's 7.5 secs... which means your mobs at about 7.5 secs apart. That's most of the "how_many_seconds" timer so you should increase that to even be higher. The risk is that if you end up on an obstacle and a mob is attacking you and you can't attack it due to the obstacle he'll have a lot more time to hit you and possibly kill you. The way the how_many_seconds works is that once the "attack" has started (from Id'ing the target to actualling hitting it) it looks to see if the target has received any damage within that time limit. If it hasn't it assumes there's an obstacle keeping you from damaging the target and breaks off.

HTH

1z2x3c
Posts: 14
Joined: Tue Dec 30, 2008 8:26 pm

Re: Shaiya Fighter Bot

#180 Post by 1z2x3c » Sat Jun 13, 2009 1:59 am

does anyone have a working bot for euroshaiya or know how to find the memory addresses?

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests