EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   is NPC spawned (https://www.eqemulator.org/forums/showthread.php?t=38403)

Esildor 06-19-2014 03:42 PM

is NPC spawned
 
Hola,

Is there a way to check if an NPC is spawned before doing something?

Something like:

Code:

if (defined $qglobals{"MjarakIsDead"}){
                my $mjarak = $entity_list->GetMobByNpcTypeID(4770015);
                if ($mjarak == 1){
                quest::ze(15, "texthere");
                quest::settimer(4772, 120);
                }
                else {
                }
                }

The if ($mjarak == 1) { was just wishful thinking, I've tried if ($mjarak->IsMob()){ too.

Esildor 06-19-2014 04:15 PM

Found EntityVariableExists() under the mob-> commands,

Tried the following with no luck.

Code:

if (defined $qglobals{"MjarakIsDead"}){ ###Mjarak 2 min warning
                my $mjarak = $entity_list->GetMobByNpcTypeID(4770015);
                if ($mjarak->EntityVariableExists()){
                quest::ze(15, "texthere");
                quest::settimer(4772, 120);
                }
                }


joligario 06-19-2014 05:14 PM

Quote:

Originally Posted by Esildor (Post 231421)
The if ($mjarak == 1) { was just wishful thinking, I've tried if ($mjarak->IsMob()){ too.

What about just:
if ($mjarak)

Esildor 06-19-2014 05:30 PM

Quote:

Originally Posted by joligario (Post 231424)
What about just:
if ($mjarak)


Tadah! if ($mjarak) { works, Thanks Jolig!

demonstar55 06-19-2014 08:52 PM

EntityList::IsMobSpawnedByNpcTypeID() should work with both lua and Perl. (I'm not sure the exact syntax though :P)

Esildor 06-20-2014 12:39 AM

Quote:

Originally Posted by demonstar55 (Post 231430)
EntityList::IsMobSpawnedByNpcTypeID() should work with both lua and Perl. (I'm not sure the exact syntax though :P)

Grabbing the entity with:

Code:

my $mjarak = $entity_list->GetMobByNpcTypeID(4770039);
if ($mjarak) {

Is working fine. Is there any reason that doing EntityList::IsMobSpawnedByNpcTypeID() any better?

demonstar55 06-20-2014 01:01 AM

Quote:

Originally Posted by Esildor (Post 231448)
Grabbing the entity with:

Code:

my $mjarak = $entity_list->GetMobByNpcTypeID(4770039);
if ($mjarak) {

Is working fine. Is there any reason that doing EntityList::IsMobSpawnedByNpcTypeID() any better?

It does the same thing, but in code, so you don't have to worry about go through the quest system. It also makes sure the NPC is alive, since the enity list can contain mobs that are dead and will be quickly removed :P (they get removed on the next cycle)

Esildor 06-20-2014 01:45 AM

Quote:

Originally Posted by demonstar55 (Post 231450)
It does the same thing, but in code, so you don't have to worry about go through the quest system. It also makes sure the NPC is alive, since the enity list can contain mobs that are dead and will be quickly removed :P (they get removed on the next cycle)

That seems silly, why would it contain dead mobs?

Also, you said in code but not in the quest system, what exactly do you mean by that, it wouldn't be handled in a perl for example?

Zaela_S 06-20-2014 02:11 AM

Quote:

Originally Posted by Esildor (Post 231451)
That seems silly, why would it contain dead mobs?

If I remember correctly, to prevent re-entrancy issues. Lots of things iterate through the NPC list, often with more than one iteration "in progress" at one time. Removing an NPC from the list at the "top level" iteration will make all the other iterations in progress stale and buggy. Much safer to flag the NPC as dead now and then remove it from the list on the next "bottom level" iteration (the NPC::Process cycle).

Because code, in other words.

Esildor 06-20-2014 02:18 AM

I see.

The entity variables I'm using won't last long, only 2 minutes. Using it for a lockout system, if someone zones in and the mob is up it's going to despawn it w/in 2 minutes unless the player leaves the zone. If I'm only using the variables for a relatively short amount of time, should I really be worried about them being buggy?

Sidenote, anyone know of a way to return the time remaining on a qglobal to players?


All times are GMT -4. The time now is 07:23 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.