Add linkpearl to new characters

AlZaabiXIV
Posts: 6
Joined: Thu Jun 16, 2016 11:08 pm
Location: Dubai

Re: Add linkpearl to new characters

Post by AlZaabiXIV » Sat Jun 25, 2016 12:58 am

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.

markap
Posts: 10
Joined: Tue May 23, 2017 1:41 pm

Re: Add linkpearl to new characters

Post by markap » Wed May 24, 2017 10:32 pm

I can confirm this method works,with one change:

Change this line:

Code: Select all

linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem);
To this: (the last parameter is the slot to equip the pearl, 1 or 2)

Code: Select all

linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem,2);

Drajek
Posts: 2
Joined: Tue Nov 28, 2017 2:20 am

Re: Add linkpearl to new characters

Post by Drajek » Sat Dec 02, 2017 6:31 am

markap wrote:I can confirm this method works,with one change:

Change this line:

Code: Select all

linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem);
To this: (the last parameter is the slot to equip the pearl, 1 or 2)

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.

User avatar
TeoTwawki
Developer
Posts: 523
Joined: Mon Jul 15, 2013 9:50 pm

Re: Add linkpearl to new characters

Post by TeoTwawki » Sat Dec 09, 2017 2:36 pm

new version, returns a true/false so you can check if it worked.

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'";
    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;

        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)
        {
            CItem* PItem = itemutils::GetItem(515);

            // 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));
            uint8 invSlotID = charutils::AddItem(PChar, LOC_INVENTORY, PItem, 1);

            lua_pushboolean(L, true);
            return 1;
        }
    }
    lua_pushboolean(L, false);
    return 1;
}

Code: Select all

    LUNAR_DECLARE_METHOD(CLuaBaseEntity,addLSpearl),
in luabaseenitity.h

Code: Select all

int32 addLS(lua_State* L);         // Adds LS to player
In player.lua char create section or a GM command or wherever

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.

Code: Select all

PLS USE [code]CODE TAGS[/code] WHEN POSTING CODE
Image
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 BUGS

Post Reply