Skip to content

Commit dbec732

Browse files
committed
fix OnNPCSpawn infinite loop
1 parent b876feb commit dbec732

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Server/Components/NPCs/NPC/npc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ NPC::NPC(NPCComponent* component, IPlayer* playerPtr)
3232
, animationFlags_(0)
3333
, specialAction_(SpecialAction_None)
3434
, invulnerable_(false)
35+
, spawning_(false)
3536
, meleeAttacking_(false)
3637
, meleeAttackDelay_(0)
3738
, meleeSecondaryAttack_(false)
@@ -264,7 +265,9 @@ void NPC::spawn()
264265
lastDamager_ = nullptr;
265266
lastDamagerWeapon_ = PlayerWeapon_End;
266267

268+
spawning_ = true;
267269
npcComponent_->getEventDispatcher_internal().dispatch(&NPCEventHandler::onNPCSpawn, *this);
270+
spawning_ = false;
268271
}
269272

270273
void NPC::respawn()
@@ -1438,7 +1441,7 @@ void NPC::exitVehicle()
14381441

14391442
bool NPC::putInVehicle(IVehicle& vehicle, uint8_t seat)
14401443
{
1441-
if (player_->getState() != PlayerState_OnFoot)
1444+
if (player_->getState() != PlayerState_OnFoot && spawning_ == false)
14421445
{
14431446
spawn();
14441447
}

Server/Components/NPCs/NPC/npc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ class NPC : public INPC, public PoolIDProvider, public NoCopy
402402
PlayerSpecialAction specialAction_;
403403
bool invulnerable_;
404404
PlayerSurfingData surfingData_;
405+
bool spawning_;
405406

406407
// Attack data
407408
bool meleeAttacking_;

0 commit comments

Comments
 (0)