Page 1 of 1

adding a function the bot will recognize

Posted: Fri Dec 25, 2009 12:51 pm
by j_schlott
how /where would i place a function so the bot is able to use it

i would like to script something for a warden in the onleavecombat tags

they get a spells to summon/sacrifice a pet for buffs, i dont think the bot can handle that correctly as-is

so i want to use a custom function i found on the runes forums to check for that buff on leaving combat, and if not present, run the summon/sacrifice script

atm im using:

Code: Select all

	<onLeaveCombat><![CDATA[
      if(player.free_counter2 == 0) then player.free_counter2 = os.time(); end;
      if( os.difftime(os.time(), player.free_counter2) > 600 ) then
      player.free_counter2 = os.time();
      player:rest(1);
      RoMScript("UseSkill(4,3)");  ---sumon skill
      player:rest(9);
      RoMScript("UseSkill(4,9)");  ---sacrifice skill
      player:rest(1);
      end
	]]></onLeaveCombat>
but sometimes it lags through, doesnt cast then waits 600seconds for the cooldown, or sometimes it regains agro and gets interrupted halfway through and then has to wait 600seconds, or sometimes even the fast looting seems to mess it up

so i think it would be much more effective to use a buff check after each kill, instead of a timer
function:

Code: Select all

function ChkBuff(tgt, ...)
    local counter = 1;
    local friendly = UnitIsPlayer(tgt);
    local currentbuff = "none";

    while (currentbuff ~= nil) do
        if friendly then
            currentbuff = UnitBuff(tgt, counter);
        else
            currentbuff = UnitDebuff(tgt, counter);
        end

        for i,v in pairs(arg) do
            if (currentbuff == tostring(v)) then
                return true;
            end
        end

        counter = counter + 1;
    end

    return false;
end
i tried adding the function into functions.lua but i get a error saying tried to call global UnitIsPlayer a nil value, i also tried adding it as its own lua file inside the scripts/rom folder and having bot.lua call it, but i get the same error

so i think the bot isnt set up to see the game function UnitIsPlayer, and im not sure how to set it as something the bot recognizes

Re: adding a function the bot will recognize

Posted: Fri Dec 25, 2009 1:06 pm
by j_schlott
it would look something like this:

Code: Select all

	<onLeaveCombat><![CDATA[
      local counter = 1;
      if ChkBuff("BUFFNAME") then
      counter = counter+1;
      else
      player:rest(1);
      RoMScript("UseSkill(4,3)");  ---sumon skill
      player:rest(9);
      RoMScript("UseSkill(4,9)");  ---sacrifice skill
      player:rest(1);
      end
	]]></onLeaveCombat>

Re: adding a function the bot will recognize

Posted: Fri Dec 25, 2009 1:34 pm
by Administrator
You can use this:

Code: Select all

local haveBuff = RoMScript("};a=false;for b=1,20 do if(UnitBuff('player',b)=='Buff Name') then a=true; end;");
Untested, but it should work.

Re: adding a function the bot will recognize

Posted: Fri Dec 25, 2009 2:16 pm
by j_schlott
hm im a nub, and i have no idea what that is going to return, the variables and crap is way over my coding head

do i change the 'Buff Name' section to my buff? and then it returns true or false?


i get a error on you code aswell, " unexpected symbol near '}' "

Re: adding a function the bot will recognize

Posted: Fri Dec 25, 2009 11:14 pm
by Administrator
Oh, right, forgot to make the end brackets match up. Try this:

Code: Select all

local haveBuff = RoMScript("false};for b=1,20 do if(UnitBuff('player',b)=='Buff Name') then a[1]=true; end;b={");
The brackets are used kind of hackishly, but the general idea is to just complete the code segment that's put in there automatically with RoMScript(). Any values we place into variable 'a' will be returned by RoMScript. So, yes, it should now return true or false if the player has the buff named 'Buff Name' (which you should change to whatever you're searching for.

Re: adding a function the bot will recognize

Posted: Mon Dec 28, 2009 8:22 am
by j_schlott
hi, sorry i didnt get back sooner, holidays and all.

i get an error still with your script, a different one this time: end expected near eof

i started using this, it works pretty well
***edit2 i changed the buff time left to 20sec so potions/HoT wouldnt affect it:

Code: Select all

	<onLeaveCombat>
	local buff = RoMScript("GetPlayerBuffLeftTime(GetPlayerBuff(1, 'HELPFUL'))");
	if (buff < 20) then
		player:rest(1.2);
		keyboardPress(key.VK_6);
		player:rest(11);
	end
	</onLeaveCombat>
key 6 is a ingame macro that cast summons/waits/cast sacrifice

Re: adding a function the bot will recognize

Posted: Mon Dec 28, 2009 10:20 am
by Administrator

Code: Select all

   <onLeaveCombat><![CDATA[
   local buff = RoMScript("GetPlayerBuffLeftTime(GetPlayerBuff(1, 'HELPFUL'))");
   if (buff < 20) then
      player:rest(1.2);
      keyboardPress(key.VK_6);
      player:rest(11);
   end
   ]]></onLeaveCombat>