diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index ffa9ff8e..904509a6 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1461,4 +1461,12 @@ void SlashCommandHandler::Startup() { .handle = DEVGMCommands::Barfight, .requiredLevel = eGameMasterLevel::DEVELOPER }); + + RegisterCommand({ + .help = "Despawns an object by id", + .info = "Despawns an object by id", + .aliases = {"despawn"}, + .handle = DEVGMCommands::Despawn, + .requiredLevel = eGameMasterLevel::DEVELOPER + }); } diff --git a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp index d0a799e7..34ebf982 100644 --- a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp +++ b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp @@ -762,6 +762,7 @@ namespace DEVGMCommands { info.spawner = nullptr; info.spawnerID = entity->GetObjectID(); info.spawnerNodeID = 0; + info.settings = { new LDFData(u"SpawnedFromSlashCommand", true) }; Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr); @@ -803,6 +804,7 @@ namespace DEVGMCommands { info.spawner = nullptr; info.spawnerID = entity->GetObjectID(); info.spawnerNodeID = 0; + info.settings = { new LDFData(u"SpawnedFromSlashCommand", true) }; auto playerPosition = entity->GetPosition(); while (numberToSpawn > 0) { @@ -1637,4 +1639,27 @@ namespace DEVGMCommands { const auto msg = u"Pvp has been turned on for all players by " + GeneralUtils::ASCIIToUTF16(characterComponent->GetName()); ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, msg, true); } + + void Despawn(Entity* entity, const SystemAddress& sysAddr, const std::string args) { + if (args.empty()) return; + + const auto splitArgs = GeneralUtils::SplitString(args, ' '); + const auto objId = GeneralUtils::TryParse(splitArgs[0]); + if (!objId) return; + + auto* const target = Game::entityManager->GetEntity(*objId); + if (!target) { + ChatPackets::SendSystemMessage(sysAddr, u"Entity not found: " + GeneralUtils::UTF8ToUTF16(splitArgs[0])); + return; + } + + if (!target->GetVar(u"SpawnedFromSlashCommand")) { + ChatPackets::SendSystemMessage(sysAddr, u"You cannot despawn this entity as it was not despawned from a slash command."); + return; + } + + target->Smash(LWOOBJID_EMPTY, eKillType::SILENT); + LOG("Despawned entity (%llu)", target->GetObjectID()); + ChatPackets::SendSystemMessage(sysAddr, u"Despawned entity: " + GeneralUtils::to_u16string(target->GetObjectID())); + } }; diff --git a/dGame/dUtilities/SlashCommands/DEVGMCommands.h b/dGame/dUtilities/SlashCommands/DEVGMCommands.h index a583342d..b1abb07e 100644 --- a/dGame/dUtilities/SlashCommands/DEVGMCommands.h +++ b/dGame/dUtilities/SlashCommands/DEVGMCommands.h @@ -75,6 +75,7 @@ namespace DEVGMCommands { void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args); void Shutdown(Entity* entity, const SystemAddress& sysAddr, const std::string args); void Barfight(Entity* entity, const SystemAddress& sysAddr, const std::string args); + void Despawn(Entity* entity, const SystemAddress& sysAddr, const std::string args); } #endif //!DEVGMCOMMANDS_H diff --git a/docs/Commands.md b/docs/Commands.md index b9a5ee5c..2a93e3de 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -115,6 +115,7 @@ These commands are primarily for development and testing. The usage of many of t |getfactions|`/getfactions`|Shows the player's factions|8| |setrewardcode|`/setrewardcode `|Sets the rewardcode for the account you are logged into if it's a valid rewardcode, See cdclient table `RewardCodes`|8| |barfight|`/barfight start`|Starts a barfight (turns everyones pvp on)|8| +|despawn|`/despawn `|Despawns the entity objectID IF it was spawned in through a slash command.|8| |crash|`/crash`|Crashes the server.|9| |rollloot|`/rollloot `|Given a `loot matrix index`, look for `item id` in that matrix `amount` times and print to the chat box statistics of rolling that loot matrix.|9| |castskill|`/castskill `|Casts the skill as the player|9|