Page 7 of 22

Re: Shaiya bot

Posted: Wed Feb 27, 2008 6:06 pm
by urbandenim
Hey can anyone help me.. i have this as my Function and for some reason is still doesnt buff every 10 mins...

it just carries on running the normal script as if i had never even entered the buffing section..

Code: Select all

function main()
 need_buff = false;
 
 function buff_timer()
   need_buff = true;
   end

  function cast_buff()
   need_buff = false;
   keyboardPress( key.VK_6 ); -- key 6 - only an example
   end

  registerTimer("buff_timer", 10 * (1000*60), buff_timer);

  while( 1 ) do
  
  proc = openProcess( findProcessByExe("Game.exe") );
  win = findWindow("Shaiya");
  hdc = openDC(win);
  attach(win);

  setPriority(1);

  registerTimer("update_vars", 100, update_vars);

  running = true;
  while( running ) do
    if( keyPressed(key.VK_F7) == 1 ) then
      running = false; end

    keyboardPress(key_attack);

    if( have_target() ) then
      if( class == CLASS_WARRIOR ) then
        fight_warrior();
      elseif( class == CLASS_MAGE ) then
        fight_mage();
      end
    end

    yrest(500);

    if( HP < HP_sit or MP < MP_sit or SP < SP_sit ) then
      rest_heal(); end

    yrest(200);
    end

  closeProcess(proc);
  detach();
  end

if( need_buff ) then cast_buff(); end; -- we call our timer
end

Re: Shaiya bot

Posted: Wed Feb 27, 2008 7:34 pm
by Administrator
You mangled that script up pretty good.

Code: Select all

need_buff = false;
function buff_timer()
  need_buff = true;
end

function cast_buff()
 need_buff = false;
 keyboardPress( key.VK_6 ); -- key 6 - only an example
end

function main()
  registerTimer("buff_timer", 10 * (1000*60), buff_timer);
  registerTimer("update_vars", 100, update_vars);

  proc = openProcess( findProcessByExe("Game.exe") );
  win = findWindow("Shaiya");
  hdc = openDC(win);
  attach(win);
  setPriority(1);

  while( 1 ) do
    keyboardPress(key_attack);

    if( have_target() ) then
      if( class == CLASS_WARRIOR ) then
        fight_warrior();
      elseif( class == CLASS_MAGE ) then
        fight_mage();
      end
    end

    yrest(500);

    if( HP < HP_sit or MP < MP_sit or SP < SP_sit ) then
      rest_heal();
    end

    if( need_buff == true ) then
      cast_buff();
      need_buff = false;
    end

    yrest(200);
  end

  closeProcess(proc);
  detach();
end
Don't declare functions inside other functions; it could potentially lead to problems.
Don't call openProcess(), findWindow(), openDC(), attach(), or setPriority() every logic loop; it's redundant.
Don't call registerTimer() every logic loop; this will typically result in the timer never being called, as it keeps being reset.
You created an infinite loop with the nested while inside your main logic loop ( running = true, while(running == true)...).
You did not place checks for need_buff inside the main logic loop, therefor the code could not have possibly been called.
Do not call closeDC() every logic loop; the handle is still needed! Typically, you can just leave closeDC() out -- it will be closed automatically.

Re: Shaiya bot

Posted: Thu Feb 28, 2008 3:44 am
by zer0
elverion wrote:zerosignal: Have you made any other changes to the script? Maybe, something that could cause the handles proc and hdc to not be global? If you use the "official" script (the one posted by me) do you get the same error? I suppose you could write a function that would check if the handle was closed, and re-open it.
Yes, I am not using this script, a little bit of the code is used from it, that is all. The code I have reads the user pointer variables exactll like the updatevars() function, if the variables go out of scope in updatevars(), it forces the script to close shaiya down, and terminates the script.
So the fact that the proc and hdc are being freed is fine, the thing that is bugging me is why the memory pointer cannot be read in the first place, which is causing the script to close rather ungracefully.
I'll use your script, and see if the error still occurs, it may give me an idea, of what may be wrong with my script. ;)

Re: Shaiya bot

Posted: Thu Feb 28, 2008 8:42 am
by urbandenim
elverion i have changed the script to what you said.

but it still continues to run as normal withoug buffing me.

i checked (using chat) what happens and it just uses "11111111111111122222" over and over..

and im sure it should use "6111111111111111122222".... should it not?

Re: Shaiya bot

Posted: Thu Feb 28, 2008 10:51 am
by Administrator
No, because the way it is setup, it will trigger the timer in 10 minutes after starting. If you want it to buff at start as well, you need to change need_buff = false; to need_buff = true;.

Re: Shaiya bot

Posted: Sat Mar 01, 2008 7:41 pm
by urbandenim
is it possible to get the script to use a attack skill?

like... Use "Doubble Hit" but only once per mob.. or is this not possible??

Re: Shaiya bot

Posted: Sat Mar 01, 2008 8:13 pm
by keven999
is it possible just become semi-bot program ?
actually manual by hand is more practical thing i think !
its better just point to mob by hand but also can have potion and attack (buff) automatically ..

Re: Shaiya bot

Posted: Sat Mar 01, 2008 8:49 pm
by Administrator
Yes, it is. Open up the script and see if you can figure out which parts to enable and disable. One thing that's strange about Shaiya is that attack is the same as target next.

Having it just use potions is pretty easy. Just fix up the main loop like so to get it to just use potions for you:

Code: Select all

function main()
  proc = openProcess( findProcessByExe("Game.exe") );
  win = findWindow("Shaiya");
  hdc = openDC(win);
  attach(win);

  setPriority(1);

  registerTimer("update_vars", 100, update_vars);

  running = true;
  while( running ) do
    if( keyPressed(key.VK_F7) == 1 ) then
      running = false; end

      if( HP < HP_usepotion ) then
        use_hppotion(); end
      if( MP < MP_usepotion ) then
        use_mppotion(); end
      if( SP < SP_usepotion ) then
        use_sppotion(); end

    yrest(200);
  end
end

Re: Shaiya bot

Posted: Sat Mar 01, 2008 10:58 pm
by nooberz
hi i just downloaded the shaiya.lua a few days back it work fine by then. Right now i'm having problem with the script it just keep on spamming the key 1 and it dont loot anymore also use pots to heal. i have tried to reset my graphic setting, also there no error msg in the log file. i dont know what to do right now, :?: hoping somebody here can help me.

here the whole script btw

Code: Select all

-------------------------------------------------
-- Variable declaration -- do not edit
-------------------------------------------------
CLASS_WARRIOR   = 0;
CLASS_MAGE      = 1;
HP              = 10000;
HPmax           = HP;
MP              = 10000;
MPmax           = MP;
SP              = 10000;
SPmax           = SP;

HP_ptr         = "210A880";
HP_offset      = 296;
HPmax_ptr      = "210A880";
HPmax_offset   = 300;

MP_ptr         = "210A880";
MP_offset      = 304;
MPmax_ptr      = "210A880";
MPmax_offset   = 308;

SP_ptr         = "210A880";
SP_offset      = 312;
SPmax_ptr      = "210A880";
SPmax_offset   = 316;

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


-------------------------------------------------
-- character configuration
-------------------------------------------------
class           = CLASS_WARRIOR;
key_attack      = key.VK_1;
key_pickup      = key.VK_2;
key_sit         = key.VK_C;

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

key_hppotion    = key.VK_8;
key_mppotion    = key.VK_9;
key_sppotion    = key.VK_9;

-- rest or use potions when low on HP/MP/SP
HP_usepotion    = 200;
MP_usepotion    = 0;
SP_usepotion    = 0;

HP_sit          = 100;
MP_sit          = 0;
SP_sit          = 20;

-- chance to cast
skill1_chance   = 100;
skill2_chance   = 0;
skill3_chance   = 0;

-- MP cost
skill1_cost     = 38;
skill2_cost     = 20;
skill3_cost     = 80;

casttime        = 2000;
-------------------------------------------------

function use_hppotion()
  keyboardPress(key_hppotion);
end

function use_mppotion()
  keyboardPress(key_mppotion);
end

function use_sppotion()
  keyboardPress(key_sppotion);
end

-- so we aren't spamming the attack key...
-- we will use a timer to press it once
-- every 3 seconds.
function attack_timer()
  keyboardPress(key_attack);
end

function fight_warrior()
  registerTimer("attack_timer", 3000, attack_timer);

  while( have_target() ) do
    if( HP < HP_usepotion ) then
      use_hppotion(); end
    if( MP < MP_usepotion ) then
      use_mppotion(); end
    if( SP < SP_usepotion ) then
      use_sppotion(); end

    yrest(100);
    coroutine.yield();
  end

  unregisterTimer("attack_timer");

  yrest(1000);
  kpickup();
end

-- heal until full HP & MP
function rest_heal()

  local last_HP = HP;

  keyboardPress(key_sit);
  yrest(100);
    while( HP < HPmax ) do
      if( HP < last_HP ) then
        print("Under attack! Exiting rest");
        return;
      else
        last_HP = HP;
      end

      yrest(100);
      coroutine.yield();
    end
  keyboardPress(key_sit);
  yrest(1000);
end

-- pickup nearby items
function kpickup()
  for i = 1,5 do
    keyboardPress(key_pickup);
    yrest(100);
  end
end

-- update client variables by reading from it's memory
function update_vars()
  HP = memoryReadIntPtr(proc, HP_ptr, HP_offset);
  HPmax = memoryReadIntPtr(proc, HPmax_ptr, HPmax_offset);

  MP = memoryReadIntPtr(proc, MP_ptr, MP_offset);
  MPmax = memoryReadIntPtr(proc, MPmax_ptr, MPmax_offset);

  SP = memoryReadIntPtr(proc, SP_ptr, SP_offset);
  SPmax = memoryReadIntPtr(proc, SPmax_ptr, SPmax_offset);
end

function have_target()
  --1280*1024
  --  X: 345, Y: 36
  --  16bit: 165, 24, 66
  --  32bit: 163, 25, 65
  --1024*768
  --  X: 258, Y: 36
  --  16bit: 165, 28, 66
  --  32bit: 165, 30, 68

  local r,g,b;

  -- use the window's rect to find the resolution
  local wx,wy,ww,wh = windowRect(win);

  if( ww == 1024 and wh == 768 ) then
    r,g,b = getPixel(hdc, 258, 36);
  elseif( ww == 1280 and wh == 1024 ) then
    r,g,b = getPixel(win, 345, 36);
  else
    r,g,b = 0;
    print("Unsupported resolution! Please use 1024*768 or 1280*1024.");
  end

  --printf("R: %d, G: %d, B: %d\n", r, g, b);

  -- if there is still HP left in monster's HP bar...return true
  if( r >= 160 and r <= 170 and g >= 20 and g <= 34 and b >= 63 and b <= 73) then
    return true;
  else
    return false;
  end
end


-------------------------------------------------
-- FUNCTION MAIN
-------------------------------------------------
function main()
  proc = openProcess( findProcessByExe("Game.exe") );
  win = findWindow("Shaiya");
  hdc = openDC(win);
  attach(win);

  registerTimer("update_vars", 100, update_vars);

  running = true;
  while( running ) do
    if( keyPressed(key.VK_F7) == 1 ) then
      running = false; end

    keyboardPress(key_attack);

    if( have_target() ) then
      if( class == CLASS_WARRIOR ) then
        fight_warrior();
      elseif( class == CLASS_MAGE ) then
        fight_mage();
      end
    end

    yrest(500);

    if( HP < HP_sit or MP < MP_sit or SP < SP_sit ) then
      rest_heal(); end

    yrest(200);
  end

  closeProcess(proc);
  detach();
end

startMacro(main);
-------------------------------------------------

Re: Shaiya bot

Posted: Sun Mar 02, 2008 1:12 am
by Administrator
You're not the only one. It appears that they removed the graphical display of the monsters HP because we were using it to bot. Do you also seem to have this missing? Because of this, the bot continuously thinks that it does not have a target, and works sub-optimally. I really wish I could recruit a few good bot programmers to help me with all these little projects, but between work, writing MicroMacro, and about 10 different games...I'm stretched a little thin.

I'll probably write the Shaiya bot from scratch soon. It could use a good cleaning.

Re: Shaiya bot

Posted: Sun Mar 02, 2008 4:15 am
by 3cmSailorfuku
elverion wrote:You're not the only one. It appears that they removed the graphical display of the monsters HP because we were using it to bot. Do you also seem to have this missing? Because of this, the bot continuously thinks that it does not have a target, and works sub-optimally. I really wish I could recruit a few good bot programmers to help me with all these little projects, but between work, writing MicroMacro, and about 10 different games...I'm stretched a little thin.

I'll probably write the Shaiya bot from scratch soon. It could use a good cleaning.
You could replace it with an offset _TargetSelected_. ;)
Select a Monster, look for a 1 byte adress with the value 1, deselect and search for 0, and so on.

Code: Select all

TargetSelected_ptr = "xx";
TargetSelected_offset = "xx";

[...]

if(TargetSelected == 1) then
 return true;
else
 return false;
end
Don't know if this would work for Shaiya, I dont have it.

Re: Shaiya bot

Posted: Sun Mar 02, 2008 4:51 am
by Administrator
Yeah, it does. I've been working on this. So far the new script is much faster and more accurate. It also actually works. Potions and buffs will be fully implemented... I'll keep you guys updated.

3cmSailorfuku: You're always around and helpful. How would you like to become a mod?

Re: Shaiya bot

Posted: Sun Mar 02, 2008 5:22 am
by 3cmSailorfuku
elverion wrote: 3cmSailorfuku: You're always around and helpful. How would you like to become a mod?
No thanks, I'm just here observing how it developes :P

Re: Shaiya bot

Posted: Sun Mar 02, 2008 6:42 am
by Administrator
Ok, it's ready for testing I think. It appears everything works OK. I've attached the new script to my first post. It works pretty much the same way as before, only I have remapped start/stop to INSERT and DELETE instead of F5 and F6. Other fixes include making sure you have a monster targeted and not a player/NPC, and ensuring that your character stands up when exiting rest, just in case something happened and you get stuck.

Re: Shaiya bot

Posted: Sun Mar 02, 2008 6:51 am
by mindennek
Thank you for the new bot, i will test it!

Re: Shaiya bot

Posted: Wed Mar 05, 2008 12:55 am
by hpr12951
A question occurs,, when I open shaiya.lua it says

"...ings\chen\desktop\micromacro\scripts\shaiya.lua:29: attempt to call glob al 'secondsToTimer' (a nil value)"
How to fix it to work?

If I change the "skill1_time = secondsToTimer(30)" to "skill1_time = 0" and "buff1_time = minutesToTimer(5)" to "buff1_time = 0", the micromacro gives me "Started.
...nd Settings\chen\desktop\micromacro\lib\lib.lua:105: Invalid data was su
pplied to setPriority()."

Since my graphic is kind of different (dont know why), do I have to change any number to different number or I have to change other parts, for example the number of 254, 44 was something different before for me >> r,g,b = getPixel(hdc, 254, 44);

Using old script, it still works attack, but not pick up, they change the address?


Thx for elverion and other ppl helping Ya!! :)

Re: Shaiya bot

Posted: Wed Mar 05, 2008 5:43 am
by Administrator
Sorry, the script uses some of the newer things added to lib.lua. You can just do the secondsToTimer manually for now (just take the number and multiply by 1000 -- ie. 30 * 1000 = 30000). Also, change PRIORITY_HIGH in setPriority() to 1.

And no. This updated script will run at any graphics settings. It does not read from the game's screen anymore, so the graphics are irrelevant.

Re: Shaiya bot

Posted: Wed Mar 05, 2008 1:17 pm
by hpr12951
I change the number to 30*1000, but still give me the same problem :)
"attempt to call glob al 'secondsToTimer' (a nil value)"


U said change the whold thing "PRIORITY_HIGH" in setPriority() to "1", right ?

Re: Shaiya bot

Posted: Wed Mar 05, 2008 5:56 pm
by Administrator
Search (CTRL+F) the script for another occurrence of secondsToTimer. It is probably used several times, so you must replace them all.

And yes, replace PRIORITY_HIGH with just 1.

Re: Shaiya bot

Posted: Wed Mar 05, 2008 7:02 pm
by hpr12951
I have changed all the secondTotimer value * 1000

I only found 2 secondsTotimer. Suppose to be more or just 2?

1. registerTimer("attack_timer", secondsToTimer(3000), attack_toggle);
2. skill1_time = secondsToTimer(30000);

But still micromacro says the same..." attempt to call global 'xxxxxx' "

Another question. Why is the old script would not work for pick up but only attack?
Aeria has changed something like graphic things? :)