PDA

View Full Version : Proximity check for surrounding NPCs


Figback65
03-28-2015, 04:41 PM
Hi all,

I am trying to have a NPC do proximity check that will check for any NPC in the proximity.

The purpose of this is, im starting from scratch and im trying to globally do a scripted distance chain aggro so I can bypass factions. Also other uses.

I have read that NPC proximity can only check for PC. If thats the case. there is also the
if(plugin::CheckDistBetween2Ents($npc1, $npc2, 50)){
stuff. If this is set to a timer and I want it to check for ANY NPC within the range, would I use an array of all my npcs in the zone or whatever i want it to link to?

Everything I have tried so far has failed, am just looken for direction. Hopefully I can write it when on the path lol

Thank you.

Akkadius
03-28-2015, 05:06 PM
I've written small tutorials for NPC list iterations in the entity list:

http://wiki.eqemulator.org/p?Entity_Lists_-_How_to_Use_Them

Anytime you are using $client or $npc, those are IMPLIED entity objects.

You can create your own entity objects by fetching them selectively in your code.

$some_boss = $entity_list->GetNPCByNPCTypeID(40005); # Example
$some_boss->Say("hi");

You would use that same object in the distance check

if(plugin::CheckDistBetween2Ents($npc, $some_boss, 50)){

If you want to find all NPC's say within 50 units of the NPC you are triggering the code on, you would do something like this:

my @nlist = $entity_list->GetNPCList(); #::: Use Entity List Object to get this
foreach my $n (@nlist){ #::: Iterate through each NPC in the @nlist array
if(plugin::CheckDistBetween2Ents($npc, $n, 50)){
$n->Shout("Hi I am an NPC that is within your distance check");
}
}

Figback65
03-28-2015, 05:23 PM
Nice! Thank you, reading over it all now :)

Figback65
03-28-2015, 09:21 PM
Well I would think this would work, been worken on it and tryen to get it to work but it does not and i am blinded by the reason why.

Its fairly simple, It looks like it would work but it doesnt.

sub EVENT_SPAWN{
quest::settimer(1, 3);
}

sub EVENT_TIMER{
if($timer == 1) {
my @nlist = $entity_list->GetNPCList(); #::: Use Entity List Object to get this
foreach my $n (@nlist){ #::: Iterate through each NPC in the @nlist array
if(plugin::CheckDistBetween2Ents($mob, $n, 50)){
#$n->AddToHateList($client,1);
$n->Shout("Hi I am an NPC that is within your distance check");
}
}
}
}

Akkadius
03-28-2015, 10:08 PM
How is the script bring initiated and how are you testing

Figback65
03-28-2015, 10:09 PM
I have the script on 2 npcs in a zone by themselves. I agro one from a distance and run it by the other one to check if they recognize each other to eventually chain aggro.

Akkadius
03-28-2015, 10:17 PM
I have the script on 2 npcs in a zone by themselves. I agro one from a distance and run it by the other one to check if they recognize each other to eventually chain aggro.

Add debug messages to see what conditionals are working versus not

Figback65
03-28-2015, 10:28 PM
sub EVENT_SPAWN{
quest::settimer(1, 3);
}

sub EVENT_TIMER{
if($timer == 1) {
quest::say("timer hits");
my @nlist = $entity_list->GetNPCList(); #::: Use Entity List Object to get this
foreach my $n (@nlist){ #::: Iterate through each NPC in the @nlist array
quest::say("got entity list");
if (plugin::CheckDistBetween2Ents($npc, $n, 50)) {
#$n->AddToHateList($client,1);
quest::say("im too close");
}
}
}
}

Included debugging. I get to pulled entity list. So checkdistbetween must not be working. I had noticed early i didnt have your additions for it in the pluggins, so i snagged those and restarted server. But that was a while ago.

Figback65
03-28-2015, 11:58 PM
Script above works, Thank you

EDIT: Now I just gotta get the agro to share lol

Figback65
04-03-2015, 02:59 AM
Finalized Template to get npc to npc distance checks and add agro, to script agro linking for whatever reason you may want. I will be usen it for many reasons including bypassing faction linking on a wiped custom server.
GetHateRandom can be changed to whatever you like, GetHateTop works as well, depending what you want to happen.

sub EVENT_TIMER{
if($timer == 1) {
my @nlist = $entity_list->GetNPCList();
foreach my $n (@nlist){
if (plugin::CheckDistBetween2Ents($npc, $n, 20)) {
$n->AddToHateList($npc->GetHateRandom());
}
}
}
}

Asylum
04-04-2015, 08:28 PM
Modified for use as a "guard" without using faction. Basically you can change the target NPCIDs to have the guard attack specific npcs that come close enough.


#2211 Enclave_Protector in postorms v.1

sub EVENT_SPAWN {
quest::settimer(1,6);
}

sub EVENT_TIMER {
if($timer == 1) {
my @nlist = $entity_list->GetNPCList();
foreach my $n(@nlist) {
my $typeID = $n->GetNPCTypeID();
if($typeID >= 2213) {
if(plugin::CheckDistBetween2Ents($npc,$n,50)) {
$npc->AddToHateList($n);
}
}
}
}
}