Shaiya Fighter Bot

For any other game that doesn't have its own section.
Message
Author
1z2x3c
Posts: 14
Joined: Tue Dec 30, 2008 8:26 pm

Re: Shaiya Fighter Bot

#181 Post by 1z2x3c » Sun Jun 14, 2009 4:59 am

ok.... here is my script:

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 = 0x83DDF4;

HP_offset = 0x12C; 
MaxHP_offset = 0x130; -- 304
MP_offset = 0x134; --308;
MaxMP_offset = 0x138; --312;
SP_offset = 0x13C; --316;
MaxSP_offset = 0x140; --320;

targetid_addr = 0x6E8BE0; -- short, 65535 if none selected

sitcheck_addr = 0x83DDF4; -- 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("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()
  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);

and here is a pic which shows the problem and log:'


Image
Image

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

Re: Shaiya Fighter Bot

#182 Post by Administrator » Sun Jun 14, 2009 5:18 am

You may need to run micromacro.exe with admin privileges. Right click it, and select "Run as". When the window pops up, select the "The following user:" radio button, and type in "Administrator" as the username, and the administrator's password for your password. Click OK.

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

Re: Shaiya Fighter Bot

#183 Post by centik » Sun Jun 14, 2009 8:47 am

1z2x3c wrote:ok.... here is my script:

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 = 0x83DDF4;

HP_offset = 0x12C; 
MaxHP_offset = 0x130; -- 304
MP_offset = 0x134; --308;
MaxMP_offset = 0x138; --312;
SP_offset = 0x13C; --316;
MaxSP_offset = 0x140; --320;

targetid_addr = 0x6E8BE0; -- short, 65535 if none selected

sitcheck_addr = 0x83DDF4; -- 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("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()
  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);

and here is a pic which shows the problem and log:'


Image
Image

dude..i dont think its wise that u post ur character pic here or in any forum :D

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

Re: Shaiya Fighter Bot

#184 Post by vvayinsane » Sun Jun 14, 2009 12:38 pm

While looking at the pic. I can say centik is right. Also something i notice about your folders. You have one that says jerking jerk d.

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

Re: Shaiya Fighter Bot

#185 Post by 1z2x3c » Mon Jun 15, 2009 12:08 am

private server

i did run as admin and it still got the same errors

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

Re: Shaiya Fighter Bot

#186 Post by 1z2x3c » Fri Jun 19, 2009 4:47 am

Can someone plz help me get this going, i run both shaiya and micro marko as admin and i get same error, plz help
'

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

Re: Shaiya Fighter Bot

#187 Post by Administrator » Fri Jun 19, 2009 5:13 am

You're going to have to just experiment. It could be caused by your anti-virus, as well as a virus/rootkit, it could be because you haven't disabled GameGuard, because you don't have proper permissions set in user policies (yes, this can affect the Administrator user as well), or any other number of things. You have to tell us what you have and have not tried and what the results were, otherwise nobody will be able to help you.

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

Re: Shaiya Fighter Bot

#188 Post by Green200 » Fri Jun 19, 2009 11:00 am

I think Admin is correct. I looked at your code and the playerptr and memory read commands are correct so it's not a problem specifically with your script so far as the error you're showing. I see you've mod'd the script to add more buffs/skills but that hasn't kicked in yet since it's not even getting to that part of the script due to the inability to read your player's HP.

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

Re: Shaiya Fighter Bot

#189 Post by 1z2x3c » Fri Jun 19, 2009 5:19 pm

OK, so i finaly figrued out how to use olly,.... so the errors i get now ar:

log file:

Code: Select all

Fri Jun 19 15:15:03 2009 : MicroMacro v0.99
Fri Jun 19 15:15:03 2009 : Processor Type: 2X 586, OS: Windows Vista | Windows Server 2008 
Fri Jun 19 15:15:03 2009 : Lua initialized successfully.
Fri Jun 19 15:15:03 2009 : Lua libs opened successfully.
Fri Jun 19 15:15:03 2009 : LuaCoco is available.
Fri Jun 19 15:15:03 2009 : Lua glues exported.
Fri Jun 19 15:15:03 2009 : Keyboard layout: US English
Fri Jun 19 15:15:03 2009 : Configurations run.
Fri Jun 19 15:15:09 2009 : Executing script "fighter.lua".
==================================================


stack traceback:
	C:\Users\Robert\Desktop\micromarco\lib\lib.lua:476: in function 'startMacro'
	...\Users\Robert\Desktop\micromarco\scripts\fighter.lua:769: in main chunk

----------TRACEBACK END----------

Fri Jun 19 15:15:52 2009 : ...\Users\Robert\Desktop\micromarco\scripts\fighter.lua:599: bad argument #2 to 'memoryReadIntPtr' ((null))
Fri Jun 19 15:15:52 2009 : Execution of fighter.lua complete.
Fri Jun 19 15:15:52 2009 : Execution error: Runtime error
Fri Jun 19 15:15:52 2009 : Collecting garbage...
Fri Jun 19 15:15:52 2009 : GC closed process handle 0x60.
Fri Jun 19 15:15:52 2009 : 11KB freed.



Fri Jun 19 15:16:30 2009 : Executing script "fighter.lua".
==================================================


stack traceback:
	C:\Users\Robert\Desktop\micromarco\lib\lib.lua:476: in function 'startMacro'
	...\Users\Robert\Desktop\micromarco\scripts\fighter.lua:769: in main chunk

----------TRACEBACK END----------

Fri Jun 19 15:16:33 2009 : ...\Users\Robert\Desktop\micromarco\scripts\fighter.lua:599: bad argument #2 to 'memoryReadIntPtr' ((null))
Fri Jun 19 15:16:33 2009 : Execution of fighter.lua complete.
Fri Jun 19 15:16:33 2009 : Execution error: Runtime error
Fri Jun 19 15:16:33 2009 : Collecting garbage...
Fri Jun 19 15:16:33 2009 : GC closed process handle 0x60.
Fri Jun 19 15:16:33 2009 : GC closed device context handle 0x2614258.
Fri Jun 19 15:16:33 2009 : GC closed process handle 0xA8.
Fri Jun 19 15:16:33 2009 : 68KB freed.



Fri Jun 19 15:16:41 2009 : Executing script "fighter.lua".
==================================================


stack traceback:
	C:\Users\Robert\Desktop\micromarco\lib\lib.lua:476: in function 'startMacro'
	...\Users\Robert\Desktop\micromarco\scripts\fighter.lua:769: in main chunk

----------TRACEBACK END----------

Fri Jun 19 15:16:44 2009 : ...\Users\Robert\Desktop\micromarco\scripts\fighter.lua:599: bad argument #2 to 'memoryReadIntPtr' ((null))
Fri Jun 19 15:16:44 2009 : Execution of fighter.lua complete.
Fri Jun 19 15:16:44 2009 : Execution error: Runtime error
Fri Jun 19 15:16:44 2009 : Collecting garbage...
Fri Jun 19 15:16:44 2009 : GC closed process handle 0xA8.
Fri Jun 19 15:16:44 2009 : GC closed device context handle 0x25EE1E8.
Fri Jun 19 15:16:44 2009 : GC closed process handle 0xAC.
Fri Jun 19 15:16:44 2009 : 68KB freed.



... and the micromacro window still says same error, but shaiya no gg is working

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

Re: Shaiya Fighter Bot

#190 Post by Administrator » Fri Jun 19, 2009 7:34 pm

Try using MicroMacro 1.0. Verify that all addresses are correct.

I looked at line 599 of the script, and it does not use memoryReadIntPtr, so I'm not sure why that is throwing an error. Have you made any modifications to the script?

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

Re: Shaiya Fighter Bot

#191 Post by 1z2x3c » Fri Jun 19, 2009 8:04 pm

yes, but not that i remember...

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

Re: Shaiya Fighter Bot

#192 Post by Administrator » Fri Jun 19, 2009 8:57 pm

I'm guessing that since your client is different from the "officially" supported version, you will need to look up your own addresses, pointers and offsets. If you don't, it will lead to all sorts of memory reading/writing problems and result in a lot of strange bugs. If you already know how to find addresses but not pointers and offsets, then check the memory editing section of this forum for a tutorial on how to do it with Cheat Engine.

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

Re: Shaiya Fighter Bot

#193 Post by 1z2x3c » Fri Jun 19, 2009 11:25 pm

uhh, i dont know how to find any of them

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

Re: Shaiya Fighter Bot

#194 Post by Administrator » Fri Jun 19, 2009 11:34 pm

Then download Cheat Engine and follow the tutorial. You basically just narrow down which address it is based on value.

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

Re: Shaiya Fighter Bot

#195 Post by 1z2x3c » Sat Jun 20, 2009 12:51 am

the script i posted at the very top seems to have the same exact memory adresses i have been finding, so ill try it ...

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

Re: Shaiya Fighter Bot

#196 Post by Administrator » Sat Jun 20, 2009 12:59 am

Try this script instead. Does it give any errors?

mitzpuff
Posts: 1
Joined: Mon Jun 29, 2009 10:54 am

Re: Shaiya Fighter Bot - Problem

#197 Post by mitzpuff » Mon Jun 29, 2009 11:48 am

hi all,

first, i can get only the shaiya.lua running (fighter.lua doesn't work). then the targeting and attacks work fine, but healing and buffs don't work. i tried changing the keys but still nothing.

errors i get (script is still running) : "error code 299 only a part of the readprocess-memory or writeprocess-memory completed"

thanks for any help

User avatar
Rishijin
Posts: 49
Joined: Sat Jul 04, 2009 4:25 pm
Location: Kauai

Re: Shaiya Fighter Bot

#198 Post by Rishijin » Sat Jul 04, 2009 6:12 pm

When I start the bot it spams this at me.

Code: Select all

. 
WARNING: Failure reading memory from 0x103FDB0 at 0x7835b4 in memoryReadIntPtr()
. Error code 299 (Only part of a ReadProcessMemory or WriteProcessMemory request
 was completed.)
scripts\fighter.lua:721: attempt to perform arithmetic on global 'HP' (a nil val
ue)

Script>

Does that mean that I need to find and change the pointer for something? If so, what, and how do I know which thing to search for and change?
I know how to find pointers, but it doesn't really help me because I don't know how to use them with the script.

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

Re: Shaiya Fighter Bot

#199 Post by Administrator » Sat Jul 04, 2009 6:46 pm

Rishijin wrote: Does that mean that I need to find and change the pointer for something? If so, what, and how do I know which thing to search for and change?
I know how to find pointers, but it doesn't really help me because I don't know how to use them with the script.
Almost certainly, you will only need new pointers. Offsets probably didn't change, but the addresses will. Look up the addresses and pointers, then just plug them into this section:

Code: Select all

playerptr_addr = 0x007835B4;

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

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

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

User avatar
Rishijin
Posts: 49
Joined: Sat Jul 04, 2009 4:25 pm
Location: Kauai

Re: Shaiya Fighter Bot

#200 Post by Rishijin » Sun Jul 05, 2009 8:54 pm

This has nothing to do with my other post, but I was looking at the script and I'm confused as to how the heck you found what the target's x, y, and z coords are in memory. Like what would the initial scan be? Do you just search all values and do equal to searches a few times, then get the target to move and do not equal to searches, then more equal to searches, etc? And in the end of that, how would you tell apart the x from the y? Go physically stand where the target was to see which is which?
Am I on track here at all?

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests