get mob id

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

get mob id

#1 Post by beanybabe » Thu Sep 15, 2016 1:20 pm

I now how to use tooltip to get id but im wondering how to get it in a wp.

This is my current code. This only hunts the theMob I want to change it so it will hunt the nearest mob or a mobs you have aggro on.

Code: Select all

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?

User avatar
Bill D Cat
Posts: 555
Joined: Sat Aug 10, 2013 8:13 pm
Location: Deep in the Heart of Texas

Re: get mob id

#2 Post by Bill D Cat » Thu Sep 15, 2016 5:44 pm

Try using this as a function in your onload section. It will return the ID of the closest mob so you can act on it as you see fit.

Disclaimer: Sections of this were borrowed from BlubBlab's waypoint file: Lyliya's Magic House.

Code: Select all

--==[ 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

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#3 Post by beanybabe » Fri Sep 16, 2016 5:14 am

bill the way you have it it will find any mob.

I am trying to make it only target 1 mob so this bit of code needs to be replaced

Code: Select all

theMob = 123456   

with something that looks for agro or the nearist mobs and gets its id

I tried this:

Code: Select all

theMob = player:findEnemy(aggroOnly, _id, evalFunc, ignore)
but it is not giving the id it gets some hex looking value.

User avatar
Bill D Cat
Posts: 555
Joined: Sat Aug 10, 2013 8:13 pm
Location: Deep in the Heart of Texas

Re: get mob id

#4 Post by Bill D Cat » Fri Sep 16, 2016 6:00 am

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.

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#5 Post by beanybabe » Sat Sep 17, 2016 12:14 pm

It took me a few tries finally got it working.
Last edited by beanybabe on Sat Sep 17, 2016 1:15 pm, edited 4 times in total.

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#6 Post by beanybabe » Sat Sep 17, 2016 12:30 pm

Here is sort of what I am trying to do next I need to set a start point and have it not wander off to far looking for mobs.

Code: Select all

<?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>

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#7 Post by beanybabe » Sat Sep 17, 2016 1:40 pm

maddness Why is loot not working?
Last edited by beanybabe on Mon Sep 19, 2016 9:51 am, edited 1 time in total.

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#8 Post by beanybabe » Sun Sep 18, 2016 6:50 pm

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.
=============================================================

Code: Select all

-- 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>

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#9 Post by beanybabe » Mon Sep 19, 2016 12:36 pm

basicly this wp is

target = mobid
attack target
loot target but it is not looting.

User avatar
Bill D Cat
Posts: 555
Joined: Sat Aug 10, 2013 8:13 pm
Location: Deep in the Heart of Texas

Re: get mob id

#10 Post by Bill D Cat » Thu Sep 29, 2016 6:17 am

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.

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: get mob id

#11 Post by beanybabe » Thu Sep 29, 2016 5:44 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests