I recently started my server and have been digging through these forums like a madman but I've reached wits end here and I could really use some help, if possible.
I am trying to add a linkshell to a new character upon creation. I was using this post as reference but I've tried at least 4 different variations of the code in this post to no avail. (viewtopic.php?f=20&t=2256)
I am not even getting any errors with this script added, just.. the linkshell is not added upon creation of the character. Is this still "up to date" and working with current builds of Darkstar Servers?
The last one I tried was:
luabaseenitty.cpp:
Code: Select all
inline int32 CLuaBaseEntity::AddLinkpearl(lua_State* L)
{
DSP_DEBUG_BREAK_IF(m_PBaseEntity->objtype == TYPE_NPC);
const int8* linkshellName = lua_tostring(L, 1);
const int8* Query = "SELECT name 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)
{
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
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());
Query = "SELECT linkshellid,color FROM linkshells WHERE name='%s'";
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;
}
Code: Select all
lua_register(LuaHandle,"isValidLS",luautils::isValidLS);
Code: Select all
/************************************************************************
* *
* Check if a given linkshell exists by checking the name in database *
* *
************************************************************************/
int32 isValidLS(lua_State* L)
{
const int8* linkshellName = lua_tostring(L, 1);
const int8* Query = "SELECT name 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)
{
lua_pushboolean(L, true);
}
else
{
lua_pushboolean(L, false);
}
return 1;
}
Code: Select all
int32 isValidLS(lua_State*);
Code: Select all
if (isValidLS(("you_linkshell_name") then
if not(player:hasItem(515)) then
player:AddLinkpearl("you_linkshell_name");
end
end