Page 1 of 1
Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 9:48 am
by CNKTHoward
Hi
As the topic says, I'm looking for a way to only target NPCs in a loaded zone file.
I have the following issue:
I need to kill a mob that is spawned by a dailyquest.
The player should fight any mobs in the zone when he enters the repeat-until loop. I change the combat distance to 500, so he can attack anyone inside. Problem is though, since he is looping, he has no time for fighting. And I can't manually target the mob, because there is another one with the same name outside of the zone, but that one is unattackable (bot get stuck).
idea: As soon as the mob spawns I'm entering battle (player.Batteling == true), so if I could check, who I'm in battle with, then it would be easy to target the attacker and then call player.fight().
// OK, that doesn't work, since it's faceaggro and there could be other players in front of me-
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 10:05 am
by lisa
Bah this connection is annoying, had a reply all typed out and it bugged on me.
Ok short version, get more info on the NPC's =)
Code: Select all
local obj = nil;
local objectList = CObjectList();
objectList:update();
for i = 0,objectList:size() do
obj = objectList:getObject(i);
if obj.Name == "Anthony Taz" then
table.print(obj)
end
end
I am hoping Anthony Taz is the full name of the NPC.
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 10:09 am
by CNKTHoward
Well he is not the one to be killed, that's the problem. He gives us the quest. And with
Code: Select all
ChoiceOptionByName("(Meldet Euch freiwillig für die Demonstration.)")
I can spawn the mob needed for the quest. The name of that mob is more or less random (I think 3 possible names) :/
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 10:18 am
by lisa
Code: Select all
local _enemy = player:findEnemy()
if _enemy then
player:target(_enemy)
player:fight()
end
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 10:36 am
by CNKTHoward
I know there is a function to check if a quest is of the type dailyquest, but I don't know how to use it properly.
http://www.theromwiki.com/API:GetQuestInfo
Code: Select all
Returns a number of fields about a quest in the quest log
This requires me to know the index of the quest though, which I don't.
There is this function, that allows you to get the QuestName by the index
http://www.theromwiki.com/API:GetQuestNameByIndex
Code: Select all
Gets the name of a quest from the NPC Quest Dialog
What I thought of is looping all the quests in the questbook, trying to find a match of the GetQuestNameByIndex with a variable defined by me and then save the index variable and check if the quest is a dailyquest via the GetQuestInfo function. Since this is a little bit hacky imo, I was looking for a better way to solve that problem.
Because that quest I want to do exists as dailyquest and as a publicquest too.
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 10:47 am
by rock5
CNKTHoward wrote:And I can't manually target the mob, because there is another one with the same name outside of the zone, but that one is unattackable (bot get stuck).
Maybe use a kill zone?
http://www.solarstrike.net/phpBB3/viewt ... 791#p36791
CNKTHoward wrote:What I thought of is looping all the quests in the questbook, trying to find a match of the GetQuestNameByIndex with a variable defined by me and then save the index variable and check if the quest is a dailyquest via the GetQuestInfo function.
There is a small function
in "functions.lua" that looks for a quest in the quest book and cancels it. It could easily be copied and modified to do what you want.
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 11:13 am
by CNKTHoward
rock5 wrote:Maybe use a kill zone?
Code: Select all
<onLoad>
__WPL:setKillZone("schaukampf_zone");
I did, but it doesn't work properly. He is still running out of the zone and trying to attack the unattackable mob
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 11:20 am
by CNKTHoward
rock5 wrote:aggroed mobs excluded
That's the problem.
Code: Select all
local _enemy = player:findEnemy()
if _enemy then
player:target(_enemy)
player:fight()
end
gets any enemy, either in- or outside the killzone.
As stated before, the problem is that the character isn't attacking anything without the code above because he is in a loop and keeps spawning the mob, not attacking it.
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 11:51 am
by rock5
I'm not sure why findEnemy is identifying the npc as a monster but mayber the default eval function will sort it out.
Code: Select all
local _enemy = player:findEnemy(nil,nil,evalTargetDefault)
If not, you might have to create your own eval function that excludes the npc.
Re: Targetting NPCs in a zone
Posted: Mon Jul 16, 2012 11:53 am
by CNKTHoward
works perfectly, thanks rock5!
Re: Targetting NPCs in a zone
Posted: Wed Jul 18, 2012 4:56 pm
by pman
rock5 wrote:I'm not sure why findEnemy is identifying the npc as a monster but mayber the default eval function will sort it out.
Code: Select all
local _enemy = player:findEnemy(nil,nil,evalTargetDefault)
If not, you might have to create your own eval function that excludes the npc.
tried that, but i have the problem, that if i have not the aggro, it will drop the target, ANTI_KS is false.
debug message 36
Update: I looked into player.lua, where this debug message is printed. omg

Update 2: Sometimes the target is dropped, while the mob is killing you slowly.