Scanning for NPCs in range

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
CNKTHoward
Posts: 32
Joined: Thu Jul 12, 2012 8:31 am

Scanning for NPCs in range

#1 Post by CNKTHoward » Sun Jul 15, 2012 5:46 am

Hey again.

I'm looking for a way to scan for NPCs in range of my character.
Zone: House
I want the bot to scan all my housemaids, and get all the potions from them. It's no problem to get the potions, but since the names of the housemaids is variable, I wanted to find a generic solution for any character. So basically I just need a function, that stores all the names of NPCs in range.

Thx in advance.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Scanning for NPCs in range

#2 Post by lisa » Sun Jul 15, 2012 7:07 am

Code: Select all

local obj = nil;
local objectList = CObjectList();
objectList:update();

for i = 0,objectList:size() do
obj = objectList:getObject(i);
--obj here is any object in memory range, so things like obj.Name  obj.Type is what you want
end
My guess is a check for obj.Type == PT_NPC is what you want.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

CNKTHoward
Posts: 32
Joined: Thu Jul 12, 2012 8:31 am

Re: Scanning for NPCs in range

#3 Post by CNKTHoward » Sun Jul 15, 2012 7:50 am

Hm I got it working that the character is targeting the NPC and then opening the dialog window, but the character isn't doing anything with the options, although I call choiceoption

Code: Select all

		for k, v in ipairs(housemaids) do
			for variable = 1, 4 do	
				cprintf(cli.yellow, housemaids[k] .. "\n")
				player:target_NPC(housemaids[k]);
				cprintf(cli.yellow, variable .. "\n")
				RoMScript("ChoiceOption(6);")
				yrest(300)
			end
			yrest(300)
		end

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Scanning for NPCs in range

#4 Post by rock5 » Sun Jul 15, 2012 8:06 am

Sometimes ChoiceOption doesn't work so you have to use a different command "SpeakFrame_ListDialogOption". So..

Code: Select all

RoMScript("SpeakFrame_ListDialogOption(1,6)")
Or you could just use the bot function. It's designed to figure out which to use.

Code: Select all

ChoiceOptionByName("Crafting")
For that, though, you have to use the name.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

CNKTHoward
Posts: 32
Joined: Thu Jul 12, 2012 8:31 am

Re: Scanning for NPCs in range

#5 Post by CNKTHoward » Sun Jul 15, 2012 8:14 am

Ah nice, works like a charm. I have another question though. I'm using this WP for getting the potions - no problem. I do this 4 times in a row (then the exhaustion of a housemaid is at 100%). Can I somehow check if the housemaid has an exhaustion of 100% or can I surveil the chat if they tell me they are tired?
It doesn't really matter if it's possible, but it would make things faster.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Scanning for NPCs in range

#6 Post by rock5 » Sun Jul 15, 2012 9:16 am

I used this when I used to level my house maid Houses_GetServantInfo( 1 ). Hmm... Looks like theromwiki doesn't have info on it. So I'll include the variables as I use them.

Code: Select all

		local DBID, name, sex, character, month, day, horoscope, race,
		Affinity, AffinityMax,
		Charisma, CharismaMax,
		Fatigue, FatigueMax,
		Magic, MagicMax,
		Battle, BattleMax,
		Defense, DefenseMax,
		Cooking, CookingMax,
		Inventive, InventiveMax = RoMScript("Houses_GetServantInfo( 1 )")
The beauty of this is you can also use the 'name' to find and target the npc.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

CNKTHoward
Posts: 32
Joined: Thu Jul 12, 2012 8:31 am

Re: Scanning for NPCs in range

#7 Post by CNKTHoward » Sun Jul 15, 2012 9:31 am

My code right now:

Code: Select all

		for k, v in ipairs(housemaids) do
			for i = 1, 4 do	
				cprintf(cli.yellow, housemaids[k] .. "\n")
				player:target_NPC(housemaids[k]);
				ChoiceOptionByName("Handwerk")
			end
			yrest(100)
		end
This gets the potions 4 times from all the housemaids found.

Code: Select all

		for k = 1, 4 do
			local DBID, name, sex, character, month, day, horoscope, race,
			Affinity, AffinityMax,
			Charisma, CharismaMax,
			Fatigue, FatigueMax,
			Magic, MagicMax,
			Battle, BattleMax,
			Defense, DefenseMax,
			Cooking, CookingMax,
			Inventive, InventiveMax = RoMScript("Houses_GetServantInfo("..k..")")
			for i = 1, 4 do	
				cprintf(cli.yellow, name .. "\n")
				player:target_NPC(name);
				if (Fatigue > 75) then
					break
				else
					player:target_NPC(name);
					ChoiceOptionByName("Handwerk")
				end
			end
			yrest(100)
		end
Last edited by CNKTHoward on Sun Jul 15, 2012 9:56 am, edited 1 time in total.

CNKTHoward
Posts: 32
Joined: Thu Jul 12, 2012 8:31 am

Re: Scanning for NPCs in range

#8 Post by CNKTHoward » Sun Jul 15, 2012 9:54 am

Code: Select all

Houses_GetServantInfo(1)
Best command EVAR

User avatar
buchaneer
Posts: 33
Joined: Tue Jul 01, 2014 4:30 pm

Re: Scanning for NPCs in range

#9 Post by buchaneer » Tue Sep 09, 2014 10:43 am

I am trying to acquire and use Pots from the Housemaids who all have different names and ID's for each of my characters. I have copied and pasted the code into a waypoint and modified the name of the action from "CNKTHoward" (nice work by the way :)). This code seems ideal and succesfully targets and acquires 4 lots of Potions (only tested in house with 1 housemaid).

Code: Select all

3  <!-- #  2 --><waypoint x="-55" z="64" y="0">
4        for k = 1, 4 do
5           local DBID, name, sex, character, month, day, horoscope, race,
6           Affinity, AffinityMax,
7           Charisma, CharismaMax,
8           Fatigue, FatigueMax,
9           Magic, MagicMax,
10          Battle, BattleMax,
11         Defense, DefenseMax,
12         Cooking, CookingMax,
13         Inventive, InventiveMax = RoMScript("Houses_GetServantInfo("..k..")")
14         for i = 1, 4 do   
15            cprintf(cli.yellow, name .. "\n")
16            player:target_NPC(name);
17            if (Fatigue > 75) then
18               break
19            else
20               player:target_NPC(name);
21               ChoiceOptionByName("Crafting")
22            end
23         end
24         yrest(100)
25      end
26		while inventory:itemTotalCount(207200) >0 do
27			inventory:useItem(207200)
28		end
29	</waypoint>
Howerver, I get the following Error:

Ceri Moore
We try to find NPC Ceri Moore:
We successfully target NPC Ceri Moore and try to open the dialog window.
We try to find NPC Ceri Moore:
We successfully target NPC Ceri Moore and try to open the dialog window.
The game client did not crash.
2014-09-09 15:59:43 - [string "..."]:13: attempt to concatenate local 'name' (a
nil value)

It is probably obvious to anyone that knows what they are doing but, I am still new to this and any help would be most welcome. :mrgreen:
Tradition and Dogma are the killers of Innovation. challenge them and change them!

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Scanning for NPCs in range

#10 Post by rock5 » Tue Sep 09, 2014 11:04 am

You said you tested it in a house with only 1 housemaid. Maybe when it went to get the data for the second one, it didn't get any data so 'name' would be nil. So you got the "'name' a nil value" error.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
buchaneer
Posts: 33
Joined: Tue Jul 01, 2014 4:30 pm

Re: Scanning for NPCs in range

#11 Post by buchaneer » Wed Sep 10, 2014 5:11 am

TY Rock5, I will test it with another housemaid. That said; wont it continue looking for yet another housemaid and if so, how can I stop it when there are no other housemaids. Some characters have only 1 housemaid and some others have upto 2 or 3 depending on their need. :?:

Also, is there anyway I can get the bot to only use 1 of the Potions provided rather than using up all the available selected pots

Code: Select all

26      while inventory:itemTotalCount(207200) >0 do
27         inventory:useItem(207200)
28      end
This instance it is "Unbridled Enthusiasm". It works great with "Arcane Transmutor charges" where all need to be consumed. :)
Tradition and Dogma are the killers of Innovation. challenge them and change them!

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Scanning for NPCs in range

#12 Post by rock5 » Wed Sep 10, 2014 5:36 am

buchaneer wrote:continue looking for yet another housemaid and if so, how can I stop it when there are no other housemaids.
Well obviously you know you are out of house maids when the returned name is nil. So something like

Code: Select all

if name ~= nil then 
    -- Do stuff with house maid.
end
buchaneer wrote:Also, is there anyway I can get the bot to only use 1 of the Potions provided rather than using up all the available selected pots
Well the easiest way would be to just use the useGoodie() function. There are a few versions. Do a search on the forum for "usegoodie". My version (and versions based on my version) are called "userfunction_usegoodie_universal.lua"
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
buchaneer
Posts: 33
Joined: Tue Jul 01, 2014 4:30 pm

Re: Scanning for NPCs in range

#13 Post by buchaneer » Wed Sep 10, 2014 8:32 am

Many thanks for your help Rock5.

Unfortunately, the suggestion did not work as I have included it (probably the way I have included it); see below:

Code: Select all

3	<!-- #  2 --><waypoint x="-55" z="64" y="0">
4	[color=#0000FF]if name ~= nil then [/color]
5      for k = 1, 4 do
6         local DBID, name, sex, character, month, day, horoscope, race,
7         Affinity, AffinityMax,
8        Charisma, CharismaMax,
9         Fatigue, FatigueMax,
10         Magic, MagicMax,
11         Battle, BattleMax,
12         Defense, DefenseMax,
13         Cooking, CookingMax,
14         Inventive, InventiveMax = RoMScript("Houses_GetServantInfo("..k..")")
15         for i = 1, 4 do   
16            cprintf(cli.yellow, name .. "\n")
17            player:target_NPC(name);
18            if (Fatigue > 75) then
19               break
20            else
21               player:target_NPC(name);
22               ChoiceOptionByName("Crafting")
23            end
24         end
25         yrest(100)
26      end
27	 [color=#0000FF]end[/color]
28
29	</waypoint>
Coloured for clarity

The character moves to the waypoint with 2 maids in range, does nothing then moves to the next waypoint without collecting any Pots.

mm window:
We use the normal waypoint path z50_daily.xml now.
Moving to waypoint #1, (0, 0)
Moving to waypoint #2, (-55, 64)
Moving to waypoint #3, (3, 17)


Any Ideas :?: :?
Tradition and Dogma are the killers of Innovation. challenge them and change them!

User avatar
buchaneer
Posts: 33
Joined: Tue Jul 01, 2014 4:30 pm

Re: Scanning for NPCs in range

#14 Post by buchaneer » Wed Sep 10, 2014 8:36 am

Hmmm..obviously coloured text does not work in Coding section :lol:
Tradition and Dogma are the killers of Innovation. challenge them and change them!

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Scanning for NPCs in range

#15 Post by rock5 » Wed Sep 10, 2014 9:16 am

Well until you do the Houses_GetServantInfo command, 'name' is not going to have any value. Try

Code: Select all

   <!-- #  2 --><waypoint x="-55" z="64" y="0">
      for k = 1, 4 do
         local DBID, name, sex, character, month, day, horoscope, race,
         Affinity, AffinityMax,
         Charisma, CharismaMax,
         Fatigue, FatigueMax,
         Magic, MagicMax,
         Battle, BattleMax,
         Defense, DefenseMax,
         Cooking, CookingMax,
         Inventive, InventiveMax = RoMScript("Houses_GetServantInfo("..k..")")
         if name ~= nil then
            for i = 1, 4 do   
               cprintf(cli.yellow, name .. "\n")
               player:target_NPC(name);
               if (Fatigue > 75) then
                  break
               else
                  player:target_NPC(name);
                  ChoiceOptionByName("Crafting")
               end
            end
         end
         yrest(100)
      end

   </waypoint>
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
buchaneer
Posts: 33
Joined: Tue Jul 01, 2014 4:30 pm

Re: Scanning for NPCs in range

#16 Post by buchaneer » Wed Sep 10, 2014 2:35 pm

Yep..that did it and combined with the "usegoodie function", I almost have a useable Bot to run some very tedious and repetetive tasks..Almost! (just need to chew on and add a few more bits of code). Thank you so much Rock5 :D
Tradition and Dogma are the killers of Innovation. challenge them and change them!

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Scanning for NPCs in range

#17 Post by rock5 » Wed Sep 10, 2014 10:23 pm

* rock5 reads *
buchaneer wrote:just need to chew on and add a few more bits of code
* and looks across to buchaneers shark avatar and imagines buchaneer as a shark chewing on some code with those shark teeth *

LOL.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 21 guests