Search nearest NPC until match found?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Search nearest NPC until match found?

#1 Post by noobbotter » Wed Sep 19, 2012 8:01 pm

I would like to have a part of my code where it will search friendly NPCs starting from closest one to bot and keep searching until the NPC name(or ID) matches one in a list (or specifically, a table). I was wondering if someone could set me in the right direction for this?

Also, just as a reminder, how do you use the command line function to find name/ID of nearby objects? I've seen it somewhere but can't find it.

Thanks.

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: Search nearest NPC until match found?

#2 Post by BillDoorNZ » Wed Sep 19, 2012 8:11 pm

noobbotter wrote:I would like to have a part of my code where it will search friendly NPCs starting from closest one to bot and keep searching until the NPC name(or ID) matches one in a list (or specifically, a table). I was wondering if someone could set me in the right direction for this?
Thanks.
check out the CPlayer:findNearestNameOrId(_objtable, ignore, evalFunc) function.

Code: Select all

  local namesToSearchFor = { "Mishlor", "Snoop the Stubborn" }

  local nearestNPC = player:findNearestNameOrId(namesToSearchFor, nil, nil);

  if (nearestNPC) then
    --we have found one of them...now do something with/to them :)
  end;

noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Re: Search nearest NPC until match found?

#3 Post by noobbotter » Wed Sep 19, 2012 8:28 pm

Great! That will do it. Thanks again for the quick reply.

--edit:

Actually, would this search for the first one it found in the list? If Snoop was closer than Mishlor, would it find snoop first or Mishlor first? Looking at it, I'd have to guess it would look for the first name in the list, then the second, and so-on until it found one. What I would need is something to find the nearest NPC and check it's name against a full list. If not found, then it would check the next closest NPC against the list of names.

Thanks.
Last edited by noobbotter on Wed Sep 19, 2012 10:13 pm, edited 1 time in total.

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: Search nearest NPC until match found?

#4 Post by BillDoorNZ » Wed Sep 19, 2012 9:13 pm

np :)

you might want to use something like the code below to convert your table too:

Code: Select all

__npcDatabase = {
     1={name="Snoop the Stubborn", x=123, y=987, z=456}
     2={name="Mishlor", x=321, y=789, z=654}
}

local npcsToSeachFor = {};
for k,npc in pairs(__npcDatabase) do
  table.insert(npcsToSearchFor, npc.name);
end;

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

Re: Search nearest NPC until match found?

#5 Post by rock5 » Thu Sep 20, 2012 1:31 am

BillDoorNZs table idea would save processing time as it doesn't need to search memory but it would would be more time consuming to create the table and there is a possibility it could make a mistake because the coordinate system overlaps on the different continents.

As to findNearestNameOrId, it finds the nearest, not the first. It goes through the memory list once comparing all the names to each entry and finds the closest one. If you want to do what you said, it would have to search for each in turn.

Code: Select all

local matched
local namesToSearchFor = { "Mishlor", "Snoop the Stubborn" } 
for k, name in pairs(namesToSearchFor) do
    matched = player:findNearestNameOrId(name)
    if matched then break end
end
That will return the first in the list as 'matched'. Then you can do whatever you want with it.
  • 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
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Search nearest NPC until match found?

#6 Post by lisa » Thu Sep 20, 2012 3:57 am

if it was me I would just do the object search

Code: Select all

local objectList = CObjectList();
objectList:update();
local objSize = objectList:size()
for i = 0,objSize do 
obj = objectList:getObject(i);
if obj.Name == "Mishlor" or obj.Name == "Snoop the Stubborn" then
--do stuff
end
end
note when using obj you can only get this info

Code: Select all

obj.Address
obj.Name
obj.Id
obj.Type
obj.X
obj.Y
obj.Z
if you want more then you need to create a Pawn of the object.
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

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: Search nearest NPC until match found?

#7 Post by BillDoorNZ » Thu Sep 20, 2012 5:16 am

lisa wrote:if it was me I would just do the object search
ya see...thats your whole problem right there lisa...you aren't lazy enough ;)

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

Re: Search nearest NPC until match found?

#8 Post by lisa » Thu Sep 20, 2012 7:35 am

BillDoorNZ wrote:thats your whole problem right there lisa...you aren't lazy enough
Lol nah it's probably more about being a control freak.

findnearest just gets the nearest object of that Id/name, Where as it sounds to me like they want to check more than just the nearest, I love options =)
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

noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Re: Search nearest NPC until match found?

#9 Post by noobbotter » Thu Sep 20, 2012 11:47 am

Yeah, what I was looking for was to start with the nearest NPC and compare to my table, which will have all NPCs that can transport you. If the nearest one isn't found (because he's not a transporting NPC), then it will do the same for the next nearest NPC it finds, and continue until it finds a match. I'm using this function within a userfunction I'm making so that the bot will know exactly where in the world he is, so that he can then do what it is he's supposed to do within the userfunction.

I think I've got the main part of my userfunction set up so after I test it, hopefully tonight, then I'll post it with what the function is for and (more than likely) questions on how I can either make it work, or make it better/more efficient. What are the odds of it working right the first time? For me, odds are pretty high that it won't work.

First thing I picked up on, this looks wrong.

Code: Select all

	if ( settings.profile.options.PARTY == true ) and (settings.profile.options.PARTY_ICONS == true) then
		sendMacro('SetRaidTarget("target", 1);')
		if (settings.profile.options.PARTY_ICONS ~= true) then printf("Raid Icons not set in character profile.\n") end
	end
If PARTY_ICONS == true then it isn't false. Looks like it would never print that message. When is it supposed to print? If PARTY is true and PARTY_ICONS is false?

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: Search nearest NPC until match found?

#10 Post by BillDoorNZ » Thu Sep 20, 2012 2:41 pm

noobbotter wrote: First thing I picked up on, this looks wrong.

Code: Select all

	if ( settings.profile.options.PARTY == true ) and (settings.profile.options.PARTY_ICONS == true) then
		sendMacro('SetRaidTarget("target", 1);')
		if (settings.profile.options.PARTY_ICONS ~= true) then printf("Raid Icons not set in character profile.\n") end
	end
If PARTY_ICONS == true then it isn't false. Looks like it would never print that message. When is it supposed to print? If PARTY is true and PARTY_ICONS is false?
I suspect that the AND used to be an OR. Or something like that.

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

Re: Search nearest NPC until match found?

#11 Post by lisa » Thu Sep 20, 2012 6:59 pm

hmmm well my first thought was that I was either really really tired or drunk when I wrote it but it doesn't look like my style of writing though.

I don't do the () for each bit.

Code: Select all

if ( settings.profile.options.PARTY == true ) and (settings.profile.options.PARTY_ICONS == true) then
I would write it as

Code: Select all

if settings.profile.options.PARTY == true and settings.profile.options.PARTY_ICONS == true then
So I got no idea, either way it will never do that print.
You wouldn't want that printed everytime you first attack a mob anyway.
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

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

Re: Search nearest NPC until match found?

#12 Post by lisa » Thu Sep 20, 2012 7:17 pm

lol I just had to look into it.

rev 605

Code: Select all

	if ( settings.profile.options.PARTY == true ) then sendMacro('SetRaidTarget("target", 1);')
	if (settings.profile.options.PARTY_ICONS ~= true) then printf("Raid Icons not set in character profile.\n") end
	-- if (not sendMacro("IsPartyLeader()")) then printf("Not set to leader.\n") end
	end
rev 606

Code: Select all

	if ( settings.profile.options.PARTY == true ) and (settings.profile.options.PARTY_ICONS == true) then 
		sendMacro('SetRaidTarget("target", 1);')
		if (settings.profile.options.PARTY_ICONS ~= true) then printf("Raid Icons not set in character profile.\n") end
	end
and yes I commited 606 lol

So it has been like that for over a year, still since it doesn't break anything then I'm not surprised, it just doesn't do anything either.
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

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

Re: Search nearest NPC until match found?

#13 Post by rock5 » Thu Sep 20, 2012 10:37 pm

So maybe something like this

Code: Select all

	if ( settings.profile.options.PARTY == true ) then
		if (settings.profile.options.PARTY_ICONS == true) then
			sendMacro('SetRaidTarget("target", 1);')
		else 
			printf("Raid Icons not set in character profile.\n") 
		end
	end
Or do we only want it to appear once when loading the profile? That should be easy enough to do as well. And do we need to check PARTY? Maybe just have "if PARTY_ICON then do it".

What exactly is the difference between partying with PARTY_ICONS and partying without? What's the difference in play style? I understand that with the party icon the following bots using the party functions prioritize attacking the iconed mob. But how are followers expected to behave when there is no icon?

Edit: How did we end up talking about PARTY_ICONS here? Lisa, did you post in the wrong topic? :D
  • 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
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Search nearest NPC until match found?

#14 Post by lisa » Fri Sep 21, 2012 6:00 am

rock5 wrote:Edit: How did we end up talking about PARTY_ICONS here? Lisa, did you post in the wrong topic?
Lol no it wasn't me this time.
rock5 wrote:But how are followers expected to behave when there is no icon?
If the followers are set to use the icons then they ONLY attack mobs with icons, it allows the entire party to work as a team, very important in instances. You want the party leader to be the tank and basically tell what the dps chars to attack, if a dps attacks something else then it will probably pull aggro and die.

As for out of instances it is also good that the party all attack the same mob, it dies faster and less chance of party members dieing.
rock5 wrote:Or do we only want it to appear once when loading the profile?
Yeah once in profile would probably be good at startup, you don't want the message every single time you start a fight and you only want the party leader to check it as other party members can't set icons anyway.
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

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

Re: Search nearest NPC until match found?

#15 Post by rock5 » Fri Sep 21, 2012 7:00 am

Oops. I accidentally edited noobbotters post instead of my own a the other topic. :oops: And it looks like I can't move the posts the the dev section.

Anyway, I'll stop talking about party icons here.
  • 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] and 33 guests