feat: add despawn command (#1847)

This commit is contained in:
David Markowitz
2025-07-19 16:25:14 -07:00
committed by GitHub
parent 6b52cf67a0
commit 4c42eea819
4 changed files with 35 additions and 0 deletions

View File

@@ -1461,4 +1461,12 @@ void SlashCommandHandler::Startup() {
.handle = DEVGMCommands::Barfight, .handle = DEVGMCommands::Barfight,
.requiredLevel = eGameMasterLevel::DEVELOPER .requiredLevel = eGameMasterLevel::DEVELOPER
}); });
RegisterCommand({
.help = "Despawns an object by id",
.info = "Despawns an object by id",
.aliases = {"despawn"},
.handle = DEVGMCommands::Despawn,
.requiredLevel = eGameMasterLevel::DEVELOPER
});
} }

View File

@@ -762,6 +762,7 @@ namespace DEVGMCommands {
info.spawner = nullptr; info.spawner = nullptr;
info.spawnerID = entity->GetObjectID(); info.spawnerID = entity->GetObjectID();
info.spawnerNodeID = 0; info.spawnerNodeID = 0;
info.settings = { new LDFData<bool>(u"SpawnedFromSlashCommand", true) };
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr); Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
@@ -803,6 +804,7 @@ namespace DEVGMCommands {
info.spawner = nullptr; info.spawner = nullptr;
info.spawnerID = entity->GetObjectID(); info.spawnerID = entity->GetObjectID();
info.spawnerNodeID = 0; info.spawnerNodeID = 0;
info.settings = { new LDFData<bool>(u"SpawnedFromSlashCommand", true) };
auto playerPosition = entity->GetPosition(); auto playerPosition = entity->GetPosition();
while (numberToSpawn > 0) { 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()); const auto msg = u"Pvp has been turned on for all players by " + GeneralUtils::ASCIIToUTF16(characterComponent->GetName());
ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, msg, true); 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<LWOOBJID>(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<bool>(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()));
}
}; };

View File

@@ -75,6 +75,7 @@ namespace DEVGMCommands {
void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args); void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Shutdown(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 Barfight(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Despawn(Entity* entity, const SystemAddress& sysAddr, const std::string args);
} }
#endif //!DEVGMCOMMANDS_H #endif //!DEVGMCOMMANDS_H

View File

@@ -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| |getfactions|`/getfactions`|Shows the player's factions|8|
|setrewardcode|`/setrewardcode <code>`|Sets the rewardcode for the account you are logged into if it's a valid rewardcode, See cdclient table `RewardCodes`|8| |setrewardcode|`/setrewardcode <code>`|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| |barfight|`/barfight start`|Starts a barfight (turns everyones pvp on)|8|
|despawn|`/despawn <objectID>`|Despawns the entity objectID IF it was spawned in through a slash command.|8|
|crash|`/crash`|Crashes the server.|9| |crash|`/crash`|Crashes the server.|9|
|rollloot|`/rollloot <loot matrix index> <item id> <amount>`|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| |rollloot|`/rollloot <loot matrix index> <item id> <amount>`|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 <skill id>`|Casts the skill as the player|9| |castskill|`/castskill <skill id>`|Casts the skill as the player|9|