Global Linkshell

Post Reply
User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Global Linkshell

Post by tagban » Fri Dec 28, 2012 2:30 pm

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.

User avatar
whasf
Site Admin
Posts: 1312
Joined: Thu Jul 19, 2012 9:11 pm

Re: Global Linkshell

Post by whasf » Fri Dec 28, 2012 6:21 pm

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.
-- Whasf

Vicrelant
Posts: 7
Joined: Sun Nov 11, 2012 5:03 pm

Re: Global Linkshell

Post by Vicrelant » Tue Jan 01, 2013 8:48 am

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 $$

PrBlahBlahtson
Developer
Posts: 539
Joined: Sun Jul 22, 2012 12:17 am

Re: Global Linkshell

Post by PrBlahBlahtson » Wed Jan 02, 2013 2:13 am

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

daftchops
Posts: 7
Joined: Tue Jun 23, 2015 7:38 pm

Re: Global Linkshell

Post by daftchops » Fri Jul 03, 2015 2:43 pm

Old post, but Has anyone been successful with this from triggers.sql?

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Global Linkshell

Post by kjLotus » Fri Jul 03, 2015 6:21 pm

i think the current solution people use is to give one in the character creation script

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

Re: Global Linkshell

Post by TeoTwawki » Fri Jul 03, 2015 6:59 pm

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
Last edited by TeoTwawki on Wed Feb 21, 2018 11:36 pm, edited 3 times in total.
Hi, I run The Demiurge server.


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
PLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
DO NOT PRIVATE MESSAGE ME ABOUT BUGS

daftchops
Posts: 7
Joined: Tue Jun 23, 2015 7:38 pm

Re: Global Linkshell

Post by daftchops » Fri Jul 03, 2015 7:48 pm

Awesome, appreciate the help! Thanks

Post Reply