From 4a1d026215584f82143ccd55df56d528ab1d4935 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Mon, 13 Feb 2023 00:46:01 -0500 Subject: [PATCH] [Quest API] Export $spawned to EVENT_SPAWN_ZONE in Perl (#2877) * [Quest API] Export $spawned to EVENT_SPAWN_ZONE in Perl # Notes - Exports `$spawned` to `EVENT_SPAWN_ZONE` in Perl. - Allows operators to use the mob reference instead of having to grab it from entity list. * Optional parsing. --- zone/bot.cpp | 10 ++++++++-- zone/embparser.cpp | 1 + zone/entity.cpp | 8 ++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index 0ae8899a6..ed6b7a3b8 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -8370,7 +8370,11 @@ void EntityList::AddBot(Bot *new_bot, bool send_spawn_packet, bool dont_queue) { new_bot->SetID(GetFreeID()); bot_list.push_back(new_bot); mob_list.insert(std::pair(new_bot->GetID(), new_bot)); - parse->EventBot(EVENT_SPAWN, new_bot, nullptr, "", 0); + + if (parse->BotHasQuestSub(EVENT_SPAWN)) { + parse->EventBot(EVENT_SPAWN, new_bot, nullptr, "", 0); + } + new_bot->SetSpawned(); if (send_spawn_packet) { if (dont_queue) { @@ -8388,7 +8392,9 @@ void EntityList::AddBot(Bot *new_bot, bool send_spawn_packet, bool dont_queue) { } } - new_bot->DispatchZoneControllerEvent(EVENT_SPAWN_ZONE, new_bot, "", 0, nullptr); + if (parse->HasQuestSub(ZONE_CONTROLLER_NPC_ID, EVENT_SPAWN_ZONE)) { + new_bot->DispatchZoneControllerEvent(EVENT_SPAWN_ZONE, new_bot, "", 0, nullptr); + } } } diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 657ad2d3c..1a21ea23f 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -1870,6 +1870,7 @@ void PerlembParser::ExportEventVariables( ExportVar(package_name.c_str(), "spawned_entity_id", mob->GetID()); ExportVar(package_name.c_str(), "spawned_bot_id", mob->IsBot() ? mob->CastToBot()->GetBotID() : 0); ExportVar(package_name.c_str(), "spawned_npc_id", mob->IsNPC() ? mob->GetNPCTypeID() : 0); + ExportVar(package_name.c_str(), "spawned", "Mob", mob); break; } diff --git a/zone/entity.cpp b/zone/entity.cpp index b01785f42..37d828e8a 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -683,7 +683,9 @@ void EntityList::AddNPC(NPC *npc, bool send_spawn_packet, bool dont_queue) npc_list.insert(std::pair(npc->GetID(), npc)); mob_list.insert(std::pair(npc->GetID(), npc)); - parse->EventNPC(EVENT_SPAWN, npc, nullptr, "", 0); + if (parse->HasQuestSub(npc->GetNPCTypeID())) { + parse->EventNPC(EVENT_SPAWN, npc, nullptr, "", 0); + } const auto emote_id = npc->GetEmoteID(); if (emote_id != 0) { @@ -722,7 +724,9 @@ void EntityList::AddNPC(NPC *npc, bool send_spawn_packet, bool dont_queue) entity_list.ScanCloseMobs(npc->close_mobs, npc, true); - npc->DispatchZoneControllerEvent(EVENT_SPAWN_ZONE, npc, "", 0, nullptr); + if (parse->HasQuestSub(ZONE_CONTROLLER_NPC_ID, EVENT_SPAWN_ZONE)) { + npc->DispatchZoneControllerEvent(EVENT_SPAWN_ZONE, npc, "", 0, nullptr); + } if (zone->HasMap() && zone->HasWaterMap()) { npc->SetSpawnedInWater(false);