Page 1 of 1
target next Npc with same Id
Posted: Wed Jul 24, 2013 12:09 pm
by lolita
is there way to target next Npc with same id?
i need this for Quest Concernen Notes. in Qest you need to deliver notes to "New Soldiers".
There are 5 soldiers relativ close to each other, so bot keep targething same one.
I tryed with
Code: Select all
function doQuest()
repeat
SlashCommand("script TargetNearestFriend()")
yrest(500)
until RoMScript("UnitName('target')") == "New Soldiers"
player:target_NPC(119750)
yrest(1000)
if RoMScript("GetNumSpeakOption()") == 1 then
ChoiceOptionByName("This letter is from Commander Shar Talos.")
end
player:clearTarget()
end
but it still target same Npc.
any idea
Re: target next Npc with same Id
Posted: Wed Jul 24, 2013 12:25 pm
by Ego95
This is not really an answer to your question but in this topic there's a huge discussion about this daily quest:
http://solarstrike.net/phpBB3/viewtopic.php?f=27&t=4931
Re: target next Npc with same Id
Posted: Wed Jul 24, 2013 12:35 pm
by rock5
The best solution would be to find some indicator in memory as to whether the npc has been visited before or not and use that to filter the search but an easier solution would be to just make a table of npcs and visit them one at a time.Eg.
Code: Select all
local objectList = CObjectList()
objectList:update()
local npcs = {}
local obj
for i = 0, objectList:size() do
obj = objectList:getObject(i);
if obj.Id == 119750 then
table.insert(npcs,obj)
end
end
for k, npc in pairs(npcs) do
player:target(npc)
player:moveInRange(npc, 50, true) yrest(500)
Attack() yrest(1000)
if RoMScript("GetNumSpeakOption()") == 1 then
ChoiceOptionByName("This letter is from Commander Shar Talos.")
end
end
Note: This is untested.
Re: target next Npc with same Id
Posted: Wed Jul 24, 2013 1:49 pm
by lolita
code you posted rock5 is working, it target difrent npc every time, just it try to go npc on other side of camp.
so i need to limit distance of object's wich will be added to list.
or to check if (obj.x,obj.y) > (player.x+50,player.y+50)
what would be easyest way?
Re: target next Npc with same Id
Posted: Wed Jul 24, 2013 2:39 pm
by rock5
Code: Select all
if obj.Id == 119750 and 50 > distance(player,npc) then
Re: target next Npc with same Id
Posted: Wed Jul 24, 2013 3:41 pm
by Ego95
Oh lol the link I posted is an other daily. You can delete these two posts -.-
Re: target next Npc with same Id
Posted: Wed Jul 24, 2013 5:55 pm
by lolita
ty rock5, you are helpful as always.
just in my case was
Code: Select all
distance(player,obj)
not
distance(player,npc)
any way here is working code if someone need it
Code: Select all
local objectList = CObjectList()
objectList:update()
local npcs = {}
local obj
for i = 0, objectList:size() do
obj = objectList:getObject(i);
if obj.Id == 119750 and 50 > distance(player,obj) then
table.insert(npcs,obj)
end
end
for k, npc in pairs(npcs) do
player:target(npc)
Attack() yrest(1000)
if RoMScript("GetNumSpeakOption()") == 1 then
ChoiceOptionByName("This letter is from Commander Shar Talos.")
end
end