Add linkpearl to new characters

KOSMOS
Posts: 67
Joined: Thu Jan 29, 2015 10:36 pm

Re: Add linkpearl to new characters

Post by KOSMOS » Tue Feb 23, 2016 10:54 pm

Ok I am at a loss here. I got it down to one error. Think I got out all the others.

Two main questions how to properly declare linkshell in last line of your code kjLotus?
Also how do I properly put in my linkshell name?

I used teotwawki's guide but used kjLotus' code in the part for lua_baseentity.cpp for lines 169-213.

My code as is in the section is this

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;

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

            // auto-equip it //
            if (invSlotID != ERROR_SLOTID)
            {
                PItem->setSubType(ITEM_LOCKED);
                PChar->equip[SLOT_LINK1] = invSlotID;
                PChar->equipLoc[SLOT_LINK1] = LOC_INVENTORY;
                linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem);
            }
        }
    }

    return 1;
}
The only error it is still throwing is this

Code: Select all

src/map/lua/lua_baseentity.cpp:207:17: error: ‘linkshell’ has not been declared
                 linkshell::AddOnlineMember(PChar, (CItemLinkshell*)PItem);
Though I think I need to add in my linkshell name somewhere in the line

Code: Select all

const int8* linkshellName = lua_tostring(L, 1);
But not sure where, I have tried 50 some different options and just can not figure it out. I got it to where code is now and think that it is the closest to correct as I could get it to.

Any help would be greatly appreciated.

Thanks
Kosmos

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

Re: Add linkpearl to new characters

Post by tagban » Sun Feb 28, 2016 10:28 am

I was having similar issues, so I wound up converting /say into world chat.

KOSMOS
Posts: 67
Joined: Thu Jan 29, 2015 10:36 pm

Re: Add linkpearl to new characters

Post by KOSMOS » Sun Feb 28, 2016 2:09 pm

tagban wrote:I was having similar issues, so I wound up converting /say into world chat.
That seems like a much easier way to do it. Where is that found at, is it just a lua script modification? Or do I need to edit c++ for that as well?

Thanks

KOSMOS
Posts: 67
Joined: Thu Jan 29, 2015 10:36 pm

Re: Add linkpearl to new characters

Post by KOSMOS » Sun Feb 28, 2016 5:22 pm

tagban wrote:I was having similar issues, so I wound up converting /say into world chat.
Thanks for the suggestion! I do plan to get the linkshell thing working. But at least for now I am happy with having say/shout/yell all do world chat.

viewtopic.php?f=19&t=2251&p=16369#p16369

That is a link to the code I am using that is tested and works for world chat for all three on Ubuntu.

Thanks,
Kosmos

PS If someone does still know my wall on the auto linkpearl I'd greatly appreciate any help ty.

mizzy
Posts: 9
Joined: Tue Nov 03, 2015 8:33 pm

Re: Add linkpearl to new characters

Post by mizzy » Mon Apr 11, 2016 4:08 pm

I have just updated to the newest build and auto linkshell to inventory also broke. Im having the same issue as its throwing 2 errors

"linkshell":is not a class or a namespace"
"AddOnlineMember":identifier not found

are coming up. Was there a change to the core that broke these or replaced them with an alternate solution?

Thanks Mizzy

KOSMOS
Posts: 67
Joined: Thu Jan 29, 2015 10:36 pm

Re: Add linkpearl to new characters

Post by KOSMOS » Thu Apr 14, 2016 7:57 am

mizzy wrote:I have just updated to the newest build and auto linkshell to inventory also broke. Im having the same issue as its throwing 2 errors

"linkshell":is not a class or a namespace"
"AddOnlineMember":identifier not found

are coming up. Was there a change to the core that broke these or replaced them with an alternate solution?

Thanks Mizzy

The source has been greatly modified since this happened. I ended up converting say,shout, and yell to world chat and have everyone notified if new chars are created. Thanks TagBan :D

It was an easier solution for myself that in my eyes ended up serving the same purpose in the end. This way when I new char is created they can talk to whole server and/or we see someone new create a player and @zone over to them and give them a pearl.

Here is a link to the section of the forums with this information, if you choose to go this route. The coding near the bottom is mine and is working with the latest pull.
viewtopic.php?f=19&t=2251

The other option is this also thanks to TagBan it uses the unity chat for same purpose with leaving say, shout, and yell in the normal function.
[urlhttps://forums.dspt.info/viewtopic.php?f=19&t=2968][/url]

Though it is also possible to still have new characters be equipped with a new pearl. But it will require updating this code a good deal. Either way good luck to you.

Avatarati
Posts: 53
Joined: Mon Jun 30, 2014 2:51 pm

Re: Add linkpearl to new characters

Post by Avatarati » Fri Apr 15, 2016 11:58 am

I've been playing around with this all day and the only thing I can get to work is adding the correct linkpearl to characters. As far as auto-equipping it, I've tried several different ways and no results. The closest I got was by manually adding it to the char_equip table after retrieving the slot from char_inventory. But once I call the function to load gear it doesn't want to equip an item in slot 16 (where LS1 gets equipped). It'll equip every other piece of gear though from slot 0-15 (the weapon+armor slots).

I'll play around with it some more in the near future, have other scripting jobs I need to get done first.

KOSMOS
Posts: 67
Joined: Thu Jan 29, 2015 10:36 pm

Re: Add linkpearl to new characters

Post by KOSMOS » Fri Apr 15, 2016 10:54 pm

Avatarati wrote:I've been playing around with this all day and the only thing I can get to work is adding the correct linkpearl to characters. As far as auto-equipping it, I've tried several different ways and no results. The closest I got was by manually adding it to the char_equip table after retrieving the slot from char_inventory. But once I call the function to load gear it doesn't want to equip an item in slot 16 (where LS1 gets equipped). It'll equip every other piece of gear though from slot 0-15 (the weapon+armor slots).

I'll play around with it some more in the near future, have other scripting jobs I need to get done first.
I'd like to see your final code that at least gets the linkpearl to the characters if you do not mind it would be greatly appreciated. I will gladly try to figure out how to get it to auto equip and share the code once I figure it out. I spent countless hours and was never able to figure it out. Thanks :D

Avatarati
Posts: 53
Joined: Mon Jun 30, 2014 2:51 pm

Re: Add linkpearl to new characters

Post by Avatarati » Sat Apr 16, 2016 12:15 am

Sure thing! It's basically just a modified version of what the OP wrote. I call this code during a new player quest, so it's not auto-added to the character. Thanks to the original author of this.

lua_baseentity.cpp

Code: Select all

inline int32 CLuaBaseEntity::addLinkshell(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;
	     CItemLinkshell* PLinkshell = NULL;

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

            int8 EncodedString[16];
            EncodeStringLinkshell((int8*)linkshellName, EncodedString);
            PItem->setSignature(EncodedString);
            ((CItemLinkshell*)PItem)->SetLSID(Sql_GetUIntData(SqlHandle, 0));
            ((CItemLinkshell*)PItem)->SetLSColor(Sql_GetIntData(SqlHandle, 1));
            charutils::AddItem(PChar, LOC_INVENTORY, PItem);
			
			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());
		}
    }
    return 1;
}
This is included as a reward to my new player orientation quest:

Code: Select all

player:addLinkshell("Your_LS_Name_Here")
player:messageSpecial(ITEM_OBTAINED,515)
But if you want to auto-add it to new characters, then it's probably best to add it scripts/globals/player.lua like so:

Code: Select all

function onGameIn(player, firstlogin, zoning)
    if (not zoning) then -- Things checked ONLY during logon go here.
        if (firstlogin) then
            CharCreate(player);
			   player:addLinkshell("Your_LS_Name_Here")
        end
    end
To be honest, I don't know why or how this line works: const int8* linkshellName = lua_tostring(L, 1); I would figure this had to be a string type variable or even a bigger size, like int32, but for some reason the compiler kept complaining when I tried to change it. (I'm totally new to C++). Haven't tested it with long LS names though...

EDIT: Not sure why my indents get all jacked up when I post code.

mizzy
Posts: 9
Joined: Tue Nov 03, 2015 8:33 pm

Re: Add linkpearl to new characters

Post by mizzy » Tue May 10, 2016 7:10 pm

I have actually got the code working. There was just a couple lines of code that needed to be deleted. While it wont auto equip it, all new players will have it show up in their inventory. Ill post it later, this way this you can still follow the directions on the thread and have it work. Im sure someone that has a better understanding of the code/game files can fix this in a matter of minutes. I just didnt want to spend alot of time with it.

mizzy

*EDIT here is the code. Its exactly the same as what is on the first page with the auto equip left out. I did not have to add my linkshell name in the code or anything. I suggest just adding what is on page 1 as is.

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

                
          }
    }

    return 1;
}

Post Reply