Page 1 of 1
Help: Trying to make a user function
Posted: Wed Apr 13, 2011 3:22 pm
by kanta
Ok, first attempt at trying to make a custom user function. Please take a look and see what I've done wrong (yes, I'm assuming I have). Just want opinions before I drive myself crazy figuring out what's wrong when I have no clue what I'm doing. I just want to be able to insert this into a waypoint file and activate when I target boss/elite mobs.
Code: Select all
-- Boss buffs
function Killabuffs()
while not player:hasbuff("Blood Arrow") then
sendMacro("CastSpellByName(\"Blood Arrow\");")
end
while not player:hasbuff("Archer's Glory") then
sendMacro("CastSpellByName(\"Archer's Glory\");")
end
while not player:hasbuff("Arrow of Essence") then
sendMacro("CastSpellByName(\"Arrow of Essence\");")
end
end
While I'm at it, please take a look at the following code and tell me if it is ok.
Code: Select all
<!-- # 15 --><waypoint x="3890" z="2714" y="47">
player:restrnd(101, 100, 120); <!-- Rest till Boddosh aggros -->
local target = player:getTarget();
if not target == ("Boddosh") then
player:target_NPC("Boddosh");
player:updatebuffs();
if target == ("Boddosh") then
Killabuffs();
</waypoint>
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 3:51 pm
by Administrator
You should probably put a yrest(500) after each of your sendMacro commands. Otherwise, you'll send the command like 1000 times before you actually get the buff.
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 3:53 pm
by kanta
Ok, thanks for the tip. Does the coding itself look sound?
**EDIT**
Nope, not sound.
scripts\rom\bot.lua:760: Failed to compile and run Lua code for waypoint #148
guess I'll wait to try advanced coding like that.
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 5:05 pm
by Administrator
Could be anything. Try limiting what's in the waypoint code to figure out exactly which line the error is coming from.
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 7:42 pm
by kanta
Would this work better (or at all)?
Code: Select all
-- Boss buffs
function Killabuffs()
if( not player:hasbuff("Blood Arrow") and UnitSex("target") == 3 ) then
sendMacro("CastSpellByName(\"Blood Arrow\");")
yrest(500)
end
if( not player:hasbuff("Archer's Glory") and UnitSex("target") == 3 ) then
sendMacro("CastSpellByName(\"Archer's Glory\");")
yrest(500)
end
if( not player:hasbuff("Arrow of Essence") and UnitSex("target") == 3 ) then
sendMacro("CastSpellByName(\"Arrow of Essence\");")
yrest(500)
end
end
Or should it be player:target ?
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 8:15 pm
by rock5
A 'while' loop should go like this;
Instead of the sendMacros why not use the bots cast command? eg.
'UnitSex' is an in game command so if you are going to use it you would have to use sendMacro or RoMScipt but if you just want to know if it's a mob I think you could use target.Type instead.
In your waypoint 15 code I think you need to update 'target' after trying to target Boddosh.
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 9:03 pm
by kanta
I'm sorry but you completely lost me with your post. I am completely new to this scripting and can't seem to wrap my brain around it. Anything I'm trying I have found in various posts and other waypoint of custom files and am just trying to cut and paste them together.
I'm guessing you are advising me to change the main code such as:
Code: Select all
if( not player:hasbuff("Blood Arrow") and UnitSex("target") == 3 ) then
to
Code: Select all
while not player:hasbuff("Blood Arrow") and UnitSex("target") == 3 do
I'm not using the player:cast because whenever I put skills in my profile they get cast all the time, especially if they are buffs.
How would I implement the RoMScript into the coding?
something like?
Code: Select all
while not player:hasbuff("Blood Arrow") and RoMScript("UnitSex('target')") == 3 then
As for target.Type I do not think it will work. With the information I am able to find it can only detect if the target is a player or a mob. I only want these buffs to be cast while targeting a boss/elite.
**EDIT**
so frustrated.... now I get the following error:
C:/micromacro/scripts/rom/classes/player.lua:585: onPreSkillCast error: ...cript
s/rom/userfunctions/Userfunction_Killabuffs.lua:6: attempt to call method 'hasbu
ff' (a nil value)
with the edited code of:
Code: Select all
-- Boss buffs
function Killabuffs()
player:update()
local target = player:getTarget()
while not player:hasbuff("Blood Arrow") and UnitSex("target") == 3 do
sendMacro("CastSpellByName(\"Blood Arrow\");")
yrest(500)
end
while not player:hasbuff("Archer's Glory") and UnitSex("target") == 3 do
sendMacro("CastSpellByName(\"Archer's Glory\");")
yrest(500)
end
while not player:hasbuff("Arrow of Essence") and UnitSex("target") == 3 do
sendMacro("CastSpellByName(\"Arrow of Essence\");")
yrest(500)
end
end
Re: Help: Trying to make a user function
Posted: Wed Apr 13, 2011 10:53 pm
by lisa
At a quick glance I saw this
needs to be
you can add to the skill in your profile
and the bot won't use it unless you tell it to.
I'm at work atm so I can have a better look later tonight.
At the risk of sending you on a totally differnt path I'd be tempted to just check HP of the target on enter combat and then cast the skills you want.
So
Code: Select all
<onEnterCombat><![CDATA[
if target.HP > 100000 then
player:cast("SCOUT_BLOOD_ARROW")
player:cast("OTHER SKILL")
player:cast("OTHER SKILL")
end
]]></onEnterCombat>
Not sure on the bosses actual HP so you could adjust that to your liking but then it wouldn't matter the name of the boss or anything else, if it's HP is more then the stated value it will use those skills.
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 12:10 am
by rock5
kanta wrote:I'm guessing you are advising me to change the main code such as:
Code: Select all
if( not player:hasbuff("Blood Arrow") and UnitSex("target") == 3 ) then
to
Code: Select all
while not player:hasbuff("Blood Arrow") and UnitSex("target") == 3 do
Yes, except you can't use UnitSex like that.
kanta wrote:I'm not using the player:cast because whenever I put skills in my profile they get cast all the time, especially if they are buffs.
Just do what Lisa said.
kanta wrote:How would I implement the RoMScript into the coding?
something like?
Code: Select all
while not player:hasbuff("Blood Arrow") and RoMScript("UnitSex('target')") == 3 then
Yes but don't forget to change the 'then' to 'do'.
kanta wrote:As for target.Type I do not think it will work. With the information I am able to find it can only detect if the target is a player or a mob. I only want these buffs to be cast while targeting a boss/elite.
Fair enough but I'd test the command to make sure it returns the value you expect.
lisa wrote:At the risk of sending you on a totally differnt path I'd be tempted to just check HP of the target on enter combat and then cast the skills you want.
So
Code: Select all
<onEnterCombat><![CDATA[
if target.HP > 100000 then
player:cast("SCOUT_BLOOD_ARROW")
player:cast("OTHER SKILL")
player:cast("OTHER SKILL")
end
]]></onEnterCombat>
Except there is no such section. Maybe you could use onPreSkillCast?
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 12:24 am
by lisa
lol oops my bad
onPreSkillCast could work but means it would check for that every single time that character used a skill.
Code: Select all
<onPreSkillCast><![CDATA[
if target.HP > 100000 and ( not player:hasBuff("500871")) then -- blood arrow buff
player:cast("SCOUT_BLOOD_ARROW")
player:cast("OTHER SKILL")
player:cast("OTHER SKILL")
-- use pot or HoT skill to counter the blood arrow
end
]]></onPreSkillCast>
I'd be tempted to add in a boss event into the bot. So could call a function that can be user edited if a boss is targeted. Might look at adding it in with the party bot section.
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 11:23 am
by kanta
Thank you to all those that are helping me out. I'll see what I can do with your current suggestions and update here on the results.
One thing. The item set skills aren't in the skills.xml as of yet. Administrator asked me to post as many details about it as I could and I did so, but for now if I put the following code into skills.xml would this work?
Code: Select all
<skill name="SCOUT_ARCHERS_GLORY" concentration="35" cooldown="180" target="self" type="buff" />
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 11:41 am
by rock5
Looks correct, yes.
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 6:04 pm
by kanta
@lisa
your idea pretty much worked but I had to add
Code: Select all
local target = player:getTarget();
at the beginning of the code
this is what I ended up with:
Code: Select all
<onPreSkillCast><![CDATA[
-- This event receives the skill your going to cast and is accessible using arg1
-- Ex arg1.Name is the name of the skill
-- Add lua code you want to execute here
local target = player:getTarget();
if target.HP > 100000 and ( not player:hasBuff("500871")) then -- blood arrow buff
player:cast("SCOUT_BLOOD_ARROW")
yrest(500)
player:cast("SCOUT_ARROW_OF_ESSENCE")
yrest(500)
player:cast("SCOUT_ARCHERS_GLORY")
-- use pot or HoT skill to counter the blood arrow
end
]]></onPreSkillCast>
Once it targets Boddosh, the buffs activate.
I decided to not put it in my profile at this time though. The reason being that I don't want it to immediately cast the buffs at first sight of Boddosh. I first need to run a short distance away to deaggro the normal mobs so I am fighting Boddosh alone. I'm trying to work with the code that Giram mentioned to me in another post. (
http://solarstrike.net/phpBB3/viewtopic.php?f=21&t=2239)
** Many hours later **
And I finally have it successfully running now with the following code
Main waypoint:
Code: Select all
<!-- # 136 --><waypoint x="3580" z="2700" y="47">
__WPL:setForcedWaypointType("NORMAL")
while (true) do
settings.options.MAX_TARGET_DIST = 200;
player:findTarget("Boddosh");
local target = player:getTarget();
-- Should take few minutes max to get boddosh in range if we are in right place and range is right
if(target.Name == "Boddosh") then
player:cast("SCOUT_COMBO_SHOT");
loadPaths("RunFromBoddosh");
__WPL:setWaypointIndex(1);
break;
end
yrest(300);
end
</waypoint>
Run waypoint:
Code: Select all
<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onLoad>
changeProfileOption("MAX_TARGET_DIST", 80);
</onLoad>
<!-- # 1 --><waypoint x="3548" z="2698" y="47"> </waypoint>
<!-- # 2 --><waypoint x="3498" z="2694" y="50"> </waypoint>
<!-- # 3 --><waypoint x="3361" z="2683" y="47"> </waypoint>
<!-- # 4 --><waypoint x="3235" z="2605" y="47">
__WPL:setForcedWaypointType("NORMAL")
while (true) do
player:findTarget("Boddosh");
local target = player:getTarget();
if target.HP > 100000 and ( not player:hasBuff("500871")) then -- blood arrow buff
player:cast("SCOUT_BLOOD_ARROW")
yrest(500)
player:cast("SCOUT_ARROW_OF_ESSENCE")
yrest(500)
player:cast("SCOUT_ARCHERS_GLORY")
-- use pot or HoT skill to counter the blood arrow
break;
end
yrest(300);
end
</waypoint> <!-- Running to this waypoint to deaggro normal mobs and wait for Boddosh-->
<!-- # 5 --><waypoint x="3314" z="2656" y="47" type="NORMAL">
player:restrnd(101, 20, 30); <!-- Wait for Boddosh to finish going berserk and reaggro -->
</waypoint>
<!-- # 6 --><waypoint x="3452" z="2690" y="47"> </waypoint>
<!-- # 7 --><waypoint x="3581" z="2700" y="47">
loadPaths("clops-sell-run.xml");
__WPL:setWaypointIndex(137);
</waypoint>
</waypoints>
I may have to wait 1000 between the buffs, only got arrow of essence a couple times.
**EDIT**
Found the inherent problem with this.... If I die for some reason after Boddosh's room, it will get stuck waiting on the return path while it searches for a dead Boddosh.... Until I can find a better solution, I will just put a break party command in the <onDeath> section
**EDIT AGAIN**
Ok, not putting a break party in the ondeath.... didn't turn out so well. I'll just add a durability check to go along with the bag full check and break party if dura is low.
Btw, is there a possibility of adding a "do not buff if mounted" function?
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 9:30 pm
by lisa
Hmm I thought it was changed to not buff if mounted a little while back.
Re: Help: Trying to make a user function
Posted: Thu Apr 14, 2011 9:36 pm
by kanta
During a sell run, I mount up and ride to the NPC. If a mob aggros on me, my character dismounts and casts Frost Arrow even when waypoint type is TRAVEL.
I've also found that if I have Unbridled Enthusiasm active it tends to pass the waypoints a little bit even with a waypoint deviation of 0.