diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 4c92c4969..4185c145f 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -6774,6 +6774,17 @@ XS(XS__getcleannpcnamebyid) { XSRETURN(1); } +XS(XS__rename); +XS(XS__rename) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::rename(string name)"); + + std::string name = (std::string) SvPV_nolen(ST(0)); + quest_manager.rename(name); + XSRETURN_EMPTY; +} + /* This is the callback perl will look for to setup the quest package's XSUBs @@ -7079,6 +7090,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "remove_expedition_lockout_by_char_id"), XS__remove_expedition_lockout_by_char_id, file); newXS(strcpy(buf, "removeitem"), XS__removeitem, file); newXS(strcpy(buf, "removetitle"), XS__removetitle, file); + newXS(strcpy(buf, "rename"), XS__rename, file); newXS(strcpy(buf, "repopzone"), XS__repopzone, file); newXS(strcpy(buf, "resettaskactivity"), XS__resettaskactivity, file); newXS(strcpy(buf, "respawn"), XS__respawn, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 046b8c7d6..7b6c5bcdb 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -2459,6 +2459,10 @@ std::string lua_get_clean_npc_name_by_id(uint32 npc_id) { return quest_manager.getcleannpcnamebyid(npc_id); } +void lua_rename(std::string name) { + quest_manager.rename(name); +} + #define LuaCreateNPCParse(name, c_type, default_value) do { \ cur = table[#name]; \ if(luabind::type(cur) != LUA_TNIL) { \ @@ -3024,6 +3028,7 @@ luabind::scope lua_register_general() { luabind::def("cross_zone_add_ldon_loss_by_expedition_id", &lua_cross_zone_add_ldon_loss_by_expedition_id), luabind::def("cross_zone_add_ldon_points_by_expedition_id", &lua_cross_zone_add_ldon_points_by_expedition_id), luabind::def("cross_zone_add_ldon_win_by_expedition_id", &lua_cross_zone_add_ldon_win_by_expedition_id), + luabind::def("rename", &lua_rename), /** * Expansions */ diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 640d5f4f6..1dc080d65 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -1044,6 +1044,31 @@ void QuestManager::snow(int weather) { safe_delete(outapp); } +void QuestManager::rename(std::string name) { + QuestManagerCurrentQuestVars(); + if (initiator && initiator->IsClient()) { + std::string current_name = initiator->GetName(); + if (initiator->ChangeFirstName(name.c_str(), current_name.c_str())) { + initiator->Message( + Chat::White, + fmt::format( + "Successfully renamed to {}, kicking to character select.", + name + ).c_str() + ); + initiator->Kick("Name was changed."); + } else { + initiator->Message( + Chat::Red, + fmt::format( + "Failed to rename {} to {}.", + current_name, name + ).c_str() + ); + } + } +} + void QuestManager::surname(const char *name) { QuestManagerCurrentQuestVars(); //Changes the last name. diff --git a/zone/questmgr.h b/zone/questmgr.h index 999e128e6..90d31f434 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -117,6 +117,7 @@ public: void safemove(); void rain(int weather); void snow(int weather); + void rename(std::string name); void surname(const char *name); void permaclass(int class_id); void permarace(int race_id);