I added a lua function in the core to automatically add a linkpearl to new characters and it will auto-equip. Make sure the linkshell already exists or your linkpearl will become a ronin (pearl with no master )
Here's the code:
lua_baseentity.h
Code: Select all
+ int32 AddLinkpearl(lua_State* L);
int32 ChangeMusic(lua_State* L); // Sets the specified music Track for specified music block.
lua_baseentity.cpp
Code: Select all
+ inline int32 CLuaBaseEntity::AddLinkpearl(lua_State* L) {
+ DSP_DEBUG_BREAK_IF(m_PBaseEntity->objtype == TYPE_NPC);
+
+ CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
+ const int8* linkshellName = lua_tostring(L, 1);
+
+ uint8 invSlotID = charutils::AddItem(PChar, LOC_INVENTORY, 515, 1);
+ CItem* PItem = PChar->getStorage(LOC_INVENTORY)->GetItem(invSlotID);
+
+ if (PItem != NULL)
+ {
+ std::string qStr = ("UPDATE char_inventory SET signature='");
+ qStr += linkshellName;
+ qStr += "' WHERE charid = " + std::to_string(PChar->id);
+ qStr += " AND itemId = 515 AND signature = ''";
+ Sql_Query(SqlHandle, qStr.c_str());
+
+ const int8* Query = "SELECT linkshellid,color FROM linkshells WHERE name='%s'";
+ int32 ret = Sql_Query(SqlHandle, Query, linkshellName);
+ if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
+ {
+ CItemLinkshell* PLinkshell = NULL;
+
+ // Update item with name & color //
+ int8 EncodedString[16];
+ EncodeStringLinkshell((int8*)linkshellName, EncodedString);
+ PItem->setSignature(EncodedString);
+ ((CItemLinkshell*)PItem)->SetLSID(Sql_GetUIntData(SqlHandle, 0));
+ ((CItemLinkshell*)PItem)->SetLSColor(Sql_GetIntData(SqlHandle, 1));
+
+ // auto-equip it //
+ PItem->setSubType(ITEM_LOCKED);
+ PChar->equip[SLOT_LINK] = invSlotID;
+ PChar->equipLoc[SLOT_LINK] = LOC_INVENTORY;
+ PLinkshell = (CItemLinkshell*)PItem;
+ if (PLinkshell)
+ linkshell::AddOnlineMember(PChar, PLinkshell);
+ }
+ }
+
+ return 1;
+}
inline int32 CLuaBaseEntity::ChangeMusic(lua_State *L)
{
DSP_DEBUG_BREAK_IF(m_PBaseEntity == NULL);
lua_baseentity.cpp
Code: Select all
Lunar<CLuaBaseEntity>::Register_t CLuaBaseEntity::methods[] =
{
+ LUNAR_DECLARE_METHOD(CLuaBaseEntity, AddLinkpearl),
LUNAR_DECLARE_METHOD(CLuaBaseEntity,ChangeMusic),
player.lua
Code: Select all
function CharCreate(player)
+ if not(player:hasItem(515)) then
+ player:AddLinkpearl("you_linkshell_name");
+ end