Page 1 of 1

Global Linkshell

Posted: Fri Dec 28, 2012 2:30 pm
by tagban
So I just finished setting up my server, I am updating FFXI right now.

How hard is it/would it be, to create a global linkshell, that is auto-given to ANY new account/charactor? I really only intend to have a few friends on my server so its not going to be anything crazy, but I just thought it'd be neat.

Re: Global Linkshell

Posted: Fri Dec 28, 2012 6:21 pm
by whasf
It'd probably be best to do with a SQL trigger since you have to copy the "signature" which defines the linkshell name for the item. To start you off, I can say you can look at the char_insert trigger that is already there. That is called when someone creates a new character. Simply add an "INSERT INTO char_inventory ..blah..blah" line as appropriate.

Re: Global Linkshell

Posted: Tue Jan 01, 2013 8:48 am
by Vicrelant
I am agreement with this with some of the servers being more personal to home and not as large as some of the others would like to be able to do this as well.

When i checked the triggers in SQL this is what i found; is there anyone here who knows how to finish this so can complete when a new account is created the linkshell is automatically in their inventory.

Code: Select all

CREATE TRIGGER char_insert
	BEFORE INSERT ON chars
	FOR EACH ROW
BEGIN
	INSERT INTO `char_equip`     SET `charid` = NEW.charid;
	INSERT INTO `char_exp`       SET `charid` = NEW.charid;
	INSERT INTO `char_jobs`      SET `charid` = NEW.charid;
	INSERT INTO `char_points`    SET `charid` = NEW.charid;
	INSERT INTO `char_profile`   SET `charid` = NEW.charid;
	INSERT INTO `char_storage`   SET `charid` = NEW.charid;
	INSERT INTO `char_inventory` SET `charid` = NEW.charid;
END $$

Re: Global Linkshell

Posted: Wed Jan 02, 2013 2:13 am
by PrBlahBlahtson
Lemme make a linkshell...

Eh, clearly I screwed up somewhere. I got this far, but it doesn't actually work:

Code: Select all

INSERT INTO `char_inventory` (charid, slot, itemid, quantity, signature) VALUES (NEW.charid, 1, 515, 1, "¹ûn´L3");

Re: Global Linkshell

Posted: Fri Jul 03, 2015 2:43 pm
by daftchops
Old post, but Has anyone been successful with this from triggers.sql?

Re: Global Linkshell

Posted: Fri Jul 03, 2015 6:21 pm
by kjLotus
i think the current solution people use is to give one in the character creation script

Re: Global Linkshell

Posted: Fri Jul 03, 2015 6:59 pm
by TeoTwawki
See : viewtopic.php?f=20&t=2256

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;
}
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

Re: Global Linkshell

Posted: Fri Jul 03, 2015 7:48 pm
by daftchops
Awesome, appreciate the help! Thanks