Add linkpearl to new characters
-
- Posts: 6
- Joined: Thu Jun 16, 2016 11:08 pm
- Location: Dubai
Re: Add linkpearl to new characters
Is this still working? if so , and can anyone rearrange/simplify this post , i got lost trying to apply these changes to my server but failed to do so cuz of the page 3 > back to page one > page 2 says this does't work anymore so please any help would be appreciated, thanks.
Re: Add linkpearl to new characters
I can confirm this method works,with one change:
Change this line:
To this: (the last parameter is the slot to equip the pearl, 1 or 2)
Change this line:
Code: Select all
linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem);
Code: Select all
linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem,2);
Re: Add linkpearl to new characters
markap wrote:I can confirm this method works,with one change:
Change this line:To this: (the last parameter is the slot to equip the pearl, 1 or 2)Code: Select all
linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem);
Code: Select all
linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem,2);
Which step did you follow? Vivitaru's or TeoTwawki? That would clear that up a little bit more.
Re: Add linkpearl to new characters
new version, returns a true/false so you can check if it worked.
in luabaseenity.cpp
in luabaseenitity.h
In player.lua char create section or a GM command or wherever
Note: doesn't check if inventory was full, you'd need to do that in lua or adjust further, not a problem if only used in player.lua to give pearl to new players since they'll always have room.
in luabaseenity.cpp
Code: Select all
inline int32 CLuaBaseEntity::addLSpearl(lua_State* L)
{
DSP_DEBUG_BREAK_IF(m_PBaseEntity->objtype == TYPE_NPC);
std::string linkshellName = lua_tostring(L, 1);
const char* Query = "SELECT name FROM linkshells WHERE name='%s'";
char* lsName = const_cast<char*>(linkshellName.c_str());
Sql_EscapeString(SqlHandle, lsName, lsName);
int32 ret = Sql_Query(SqlHandle, Query, lsName);
if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
std::string qStr = ("UPDATE char_inventory SET signature='");
qStr += lsName;
qStr += "' WHERE charid = " + std::to_string(PChar->id);
qStr += " AND itemId = 515 AND signature = ''";
Sql_Query(SqlHandle, qStr.c_str());
Query = "SELECT linkshellid,color FROM linkshells WHERE name='%s'";
ret = Sql_Query(SqlHandle, Query, lsName);
if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
CItem* PItem = itemutils::GetItem(515);
// Update item with name & color //
int8 EncodedString[16];
EncodeStringLinkshell((int8*)lsName, EncodedString);
PItem->setSignature(EncodedString);
((CItemLinkshell*)PItem)->SetLSID(Sql_GetUIntData(SqlHandle, 0));
((CItemLinkshell*)PItem)->SetLSColor(Sql_GetIntData(SqlHandle, 1));
charutils::AddItem(PChar, LOC_INVENTORY, PItem, 1);
// To force equip, UN comment the rest of this!
// uint8 invSlotID = PItem->getSlotID();
// linkshell::AddOnlineMember(PChar, PItem, PItem->GetLSID());
// PItem->setSubType(ITEM_LOCKED);
// PChar->equip[SLOT_LINK1] = invSlotID;
// PChar->equipLoc[SLOT_LINK1] = LOC_INVENTORY;
// PChar->pushPacket(new CInventoryAssignPacket(PItem, INV_LINKSHELL));
// charutils::SaveCharEquip(PChar);
// PChar->pushPacket(new CLinkshellEquipPacket(PChar, PItem->GetLSID()));
// PChar->pushPacket(new CInventoryItemPacket(PItem, LOC_INVENTORY, PItem->getSlotID()));
// PChar->pushPacket(new CInventoryFinishPacket());
// charutils::LoadInventory(PChar);
lua_pushboolean(L, true);
return 1;
}
}
lua_pushboolean(L, false);
return 1;
}
Code: Select all
LUNAR_DECLARE_METHOD(CLuaBaseEntity,addLSpearl),
Code: Select all
int32 addLSpearl(lua_State* L); // Adds LS to player
Code: Select all
player:addLSpearl("linkshell name")
Note: doesn't check if inventory was full, you'd need to do that in lua or adjust further, not a problem if only used in player.lua to give pearl to new players since they'll always have room.
Code: Select all
if (player:getFreeSlotsCount() > 0) then
if (player:addLSpearl("linkshell name")) then
player:PrintToPlayer("LinkPearl given, don't forget to equip it. ");
else
player:PrintToPlayer("An error occurred. Does the LS exist? ");
end
else
player:PrintToPlayer("Item could not be given: free up some inventory space and try again. ");
end
Hi, I run The Demiurge server.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
DO NOT PRIVATE MESSAGE ME ABOUT BUGSPLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE