Page 1 of 1

Scanning for NPCs in range

Posted: Sun Jul 15, 2012 5:46 am
by CNKTHoward
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.

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 7:07 am
by lisa

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.

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 7:50 am
by CNKTHoward
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

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 8:06 am
by rock5
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.

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 8:14 am
by CNKTHoward
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.

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 9:16 am
by rock5
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.

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 9:31 am
by CNKTHoward
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

Re: Scanning for NPCs in range

Posted: Sun Jul 15, 2012 9:54 am
by CNKTHoward

Code: Select all

Houses_GetServantInfo(1)
Best command EVAR

Re: Scanning for NPCs in range

Posted: Tue Sep 09, 2014 10:43 am
by buchaneer
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:

Re: Scanning for NPCs in range

Posted: Tue Sep 09, 2014 11:04 am
by rock5
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.

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 5:11 am
by buchaneer
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. :)

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 5:36 am
by rock5
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"

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 8:32 am
by buchaneer
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 :?: :?

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 8:36 am
by buchaneer
Hmmm..obviously coloured text does not work in Coding section :lol:

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 9:16 am
by rock5
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>

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 2:35 pm
by buchaneer
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

Re: Scanning for NPCs in range

Posted: Wed Sep 10, 2014 10:23 pm
by rock5
* 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.