Search nearest NPC until match found?
-
- Posts: 527
- Joined: Fri Aug 31, 2012 1:15 pm
Search nearest NPC until match found?
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.
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.
-
- Posts: 446
- Joined: Wed Aug 03, 2011 7:37 pm
Re: Search nearest NPC until match found?
check out the CPlayer:findNearestNameOrId(_objtable, ignore, evalFunc) function.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.
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;
-
- Posts: 527
- Joined: Fri Aug 31, 2012 1:15 pm
Re: Search nearest NPC until match found?
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.
--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.
-
- Posts: 446
- Joined: Wed Aug 03, 2011 7:37 pm
Re: Search nearest NPC until match found?
np
you might want to use something like the code below to convert your table too:
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;
Re: Search nearest NPC until match found?
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.That will return the first in the list as 'matched'. Then you can do whatever you want with it.
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
- 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
Re: Search nearest NPC until match found?
if it was me I would just do the object search
note when using obj you can only get this info
if you want more then you need to create a Pawn of the object.
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
Code: Select all
obj.Address
obj.Name
obj.Id
obj.Type
obj.X
obj.Y
obj.Z
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
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
-
- Posts: 446
- Joined: Wed Aug 03, 2011 7:37 pm
Re: Search nearest NPC until match found?
ya see...thats your whole problem right there lisa...you aren't lazy enoughlisa wrote:if it was me I would just do the object search
Re: Search nearest NPC until match found?
Lol nah it's probably more about being a control freak.BillDoorNZ wrote:thats your whole problem right there lisa...you aren't lazy enough
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
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
-
- Posts: 527
- Joined: Fri Aug 31, 2012 1:15 pm
Re: Search nearest NPC until match found?
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.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 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
-
- Posts: 446
- Joined: Wed Aug 03, 2011 7:37 pm
Re: Search nearest NPC until match found?
I suspect that the AND used to be an OR. Or something like that.noobbotter wrote: First thing I picked up on, this looks wrong.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?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
Re: Search nearest NPC until match found?
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.
I would write it as
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.
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
Code: Select all
if settings.profile.options.PARTY == true and settings.profile.options.PARTY_ICONS == true then
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
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: Search nearest NPC until match found?
lol I just had to look into it.
rev 605
rev 606
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.
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
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
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
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: Search nearest NPC until match found?
So maybe something like this
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?
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
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?
- 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
Re: Search nearest NPC until match found?
Lol no it wasn't me this time.rock5 wrote:Edit: How did we end up talking about PARTY_ICONS here? Lisa, did you post in the wrong topic?
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.rock5 wrote:But how are followers expected to behave when there is no icon?
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.
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.rock5 wrote:Or do we only want it to appear once when loading the profile?
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
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: Search nearest NPC until match found?
Oops. I accidentally edited noobbotters post instead of my own a the other topic. And it looks like I can't move the posts the the dev section.
Anyway, I'll stop talking about party icons here.
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
Who is online
Users browsing this forum: No registered users and 7 guests