theMob = 123456 -- I need something to get this number from the nearest mob
changeProfileOption("MAX_TARGET_DIST", 250)
changeProfileOption("COMBAT_DISTANCE", 250)
repeat
player:target_NPC(theMob)
if player:haveTarget() then
-- buffs and such here
player:fight()
end
yrest(200)
until hellfreezesover
-----------------------
I tried to use theMob = local atheMob = player:findEnemy(aggroOnly, _id, evalFunc, ignore)
but that puts some hex number not the mobid
Anyone have a idea how to do this? Also is there a way so if bot is paused and unpaused it can be set to locate mob id again?
--==[ Function to return ID of target mob. Will attempt to target nearest mob if none already selected. ]==--
function getTargetMobId()
repeat
local target = nil
player:updateBattling()
player:updateTargetPtr()
if player.TargetPtr ~= 0 then
target = CPawn.new(player.TargetPtr)
target:updateType()
if target.Type == PT_MONSTER and target:isAlive() == true then
target:updateXYZ()
print("Mob found! ("..target.Id..")")
local angle = math.atan2(target.Z - player.Z, target.X - player.X);
local yangle = math.atan2(target.Y - player.Y, ((target.X - player.X)^2 + (target.Z - player.Z)^2)^.5 );
player:faceDirection(angle, yangle);
camera:setRotation(angle);
return(target.Id)
end
else
print("Tring to find a target...")
RoMScript("TargetNearestEnemy()")
end
until hellfreezesover
end
My code will either report the ID of the currently targeted mob, or if you have no target it will find the nearest mob and target it and return that ID.
As for the hex value, I think it is actually returning a pointer to a table. You could try checking the value of theMob.Id to see if that is what you want.
<?xml version="1.0" encoding="utf-8"?><waypoints>
<onLoad>
changeProfileOption("MAX_TARGET_DIST", 200)
changeProfileOption("COMBAT_DISTANCE", 200)
--==[ Function to return ID of target mob. Will attempt to target nearest mob if none already selected. ]==--
function getTargetMobId()
repeat
local target = nil
player:updateBattling()
player:updateTargetPtr()
if player.TargetPtr ~= 0 then
target = CPawn.new(player.TargetPtr)
target:updateType()
if target.Type == PT_MONSTER and target:isAlive() == true then
target:updateXYZ()
print("Mob found! ("..target.Id..")")
local angle = math.atan2(target.Z - player.Z, target.X - player.X);
local yangle = math.atan2(target.Y - player.Y, ((target.X - player.X)^2 + (target.Z - player.Z)^2)^.5 );
player:faceDirection(angle, yangle);
camera:setRotation(angle);
return(target.Id)
end
else
print("Tring to find a target...")
end
until hellfreezesover
end
function dobuffs()
--player:updateBuffs();
if not player:hasBuff(503957) then --elven amulet
player:cast("WARDEN_ELVEN_AMULET");
end
if not player:hasBuff(506062) and not player:hasBuff(501321) and not player:hasBuff(503327) then --strong stimulant
inventory:useItem(200173)
end
if not player:hasBuff(506062) and not player:hasBuff(501321) and not player:hasBuff(503327) then
player:cast("ALL_SOLDIERS_ATTACK");
end
if not player:hasBuff(506062) and not player:hasBuff(501321) and not player:hasBuff(503327) then --lute
inventory:useItem(204544)
--yrest(1000)
end
end
function fighttarget()
repeat
print("themob=",theMob)
player:target_NPC(theMob)
local target = player:getTarget();
target:update()
if target.Lootable then
player:loot()
elseif target.Alive then
dobuffs()
player:cast("WARDEN_THORNY_VINES")
player:cast("ROGUE_SHADOWSTAB")
player:cast("WARDEN_CHARGED_CHOP")
player:cast("ROGUE_SHADOWSTAB")
elseif target.Dead then
return
end
until hellfreezesover
end
----main----------------------
theMob = getTargetMobId() -----set the mob to always hunt.
repeat
fighttarget()
until hellfreezesover
</onLoad>
</waypoints>
Something is wrong I am using basically same code I have seen in other way points but this is not looting. I tried player:loot() player:lootAll() player:loot(target) anyone have any idea. This is a problem as it just sits at the dead mob and will not go on to fight another till it disappears.
=============================================================
-- this is for leveling 2h axe on warden/rogue
print(" change mirror buffs to bendor and salo get housemaid defense buff")
print("stock lots of mana and heal pots. get maid defence buff and tower defence buff")
local weapon1type = "AXE2H";
local starttime = os.time();
local startlevel1, startlevel2;
local startpercent1, startpercent2;
local reset1 = 0;
local reset2 = 0;
local hittarget, resetAutoShot
sendMacro('SetFindPartyState(false)')
sendMacro('SetLootMethod("freeforall","")');
sendMacro('SetInstanceLevel("hard")');
changeProfileOption("MAX_TARGET_DIST", 150)
changeProfileOption("COMBAT_DISTANCE", 150)
--==[ Function to return ID of target mob. Will attempt to target nearest mob if none already selected. ]==--
function getTargetMobId()
repeat
target = nil
player:updateBattling()
player:updateTargetPtr()
if player.TargetPtr ~= 0 then
target = CPawn.new(player.TargetPtr)
target:updateType()
if target.Type == PT_MONSTER and target:isAlive() == true then
target:updateXYZ()
print("Mob found! ("..target.Id..")")
local angle = math.atan2(target.Z - player.Z, target.X - player.X);
local yangle = math.atan2(target.Y - player.Y, ((target.X - player.X)^2 + (target.Z - player.Z)^2)^.5 );
player:faceDirection(angle, yangle);
camera:setRotation(angle);
return(target.Id)
end
else
print("Tring to find a target...")
end
yrest(500)
until hellfreezesover
end
function dobuffs()
--player:updateBuffs();
if not player:hasBuff(503957) then --elven amulet
player:cast("WARDEN_ELVEN_AMULET");
end
if not player:hasBuff(506062) and not player:hasBuff(501321) and not player:hasBuff(503327) then --strong stimulant
inventory:useItem(200173)
end
if not player:hasBuff(506062) and not player:hasBuff(501321) and not player:hasBuff(503327) then
player:cast("ALL_SOLDIERS_ATTACK");
end
if not player:hasBuff(506062) and not player:hasBuff(501321) and not player:hasBuff(503327) then --lute
inventory:useItem(204544)
end
checkthemana()
checkthehealth()
end
function fighttarget()
repeat
if not target.Alive then
player:lootAll()
target:update()
end
if target == nil then
player:target_NPC(theMob)
local target = player:getTarget();
player:cast("WARDEN_WALKER_SPIRIT");
end
if target.Alive then
dobuffs()
player:cast("WARDEN_THORNY_VINES")
player:cast("ROGUE_SHADOWSTAB")
checkthemana()
checkthehealth()
player:cast("WARDEN_CHARGED_CHOP")
player:cast("ROGUE_SHADOWSTAB")
else
player:lootAll()
return
end
showthetime()
until hellfreezesover
end
function showthetime()
local skill = RoMScript("GetPlayerCurrentSkillValue(\""..weapon1type.."\")");
local levelmax = RoMScript("GetPlayerMaxSkillValue(\""..weapon1type.."\")");
local level = math.floor(skill);
local percent = math.floor((skill-level)*10000+0.5)/100;
if (startlevel1 == nil) then
reset1 = 1;
startlevel1 = level;
startpercent1 = skill-level;
end
if(startlevel1 ~= level) then
reset1 = 1;
startlevel1 = level;
startpercent1 = skill-level;
starttime = os.time();
end
local timediff = os.time() - starttime;
local currentpercent = skill-level;
local secondsleft = math.floor(((1-currentpercent)*timediff)/(currentpercent-startpercent1));
local hours = math.floor(secondsleft/3600);
local minutes = math.floor((secondsleft-(hours*3600))/60);
local seconds = secondsleft - (hours*3600) - (minutes*60);
if (reset1 == 1) then
reset1 = 0;
cprintf(cli.lightred,"%s level: %s/%s ... %s%%\tLvl in:: insufficient data to calculate time...\n", weapon1type, level, levelmax, percent);
else
cprintf(cli.lightgreen,"%s level: %s/%s ... %s%%\tLvl in: %sh %sm %ss\n", weapon1type, level, levelmax, percent, hours, minutes, seconds);
end
--yrest(1000);
player:update()
end
function checkthehealth()
if 90 > player.HP/player.MaxHP*100 then
cprintf(cli.yellow,"\nLow on Health!!\n")
if inventory:itemTotalCount(208479) ~= 0 then
inventory:useItem(208479)
--yrest(1000)
end
end
end
function checkthemana()
if 30 > player.Mana/player.MaxMana*100 then
cprintf(cli.yellow,"\nLow on Mana!!\n")
if inventory:itemTotalCount(208483) ~= 0 then
inventory:useItem(208483)
else
if inventory:itemTotalCount(208484) ~= 0 then
inventory:useItem(208484)
else
if inventory:itemTotalCount(208485) ~= 0 then
inventory:useItem(208485)
else
if inventory:itemTotalCount(208486) ~= 0 then
inventory:useItem(208486)
else
print ("YOUR OUT OF MANA POTS AND WILL DIE SOON")
end
end
end
end
end
end
----main----------------------
theMob = getTargetMobId() -----set the mob to always hunt.
repeat
fighttarget()
until hellfreezesover
</onLoad>
</waypoints>
If player:loot() doesn't work, you could try using Attack() instead. Basically the same function as targeting a dead mob and hitting the 1 key (default settings) to loot.
Ok Ill give that a try, I had about gave up on getting this auto way-point to work and just created a path. If this works it will make for a nice wp to level weapons and gather items and tp. This is an attempt to rewrite the weapon leveling wp and making it more useful.