[Release] Add Sockets to Wearable Objects via screenplay or CPP.

Phoenix

Moderator
Staff member
Moderator
Joined
Sep 25, 2010
Messages
235
Due to a request I created the code to be able to add sockets manually via item creation in LUA or via CPP. Right now I have it set to 4 as max, due to the maxSockets Variable also being 4. That can easily be changed.

Files to modify:

src/server/zone/objects/tangible/wearables/WearableObject.idl

C++:
public void setMaxSockets(int maxSockets) {
    if (maxSockets <0) {
        maxSockets = 0;
    } else if (maxSockets > MAXSOCKETS) {
        maxSockets = MAXSOCKETS
    }
    socketCount = maxSockets;
    socketsGenerated = true;
}

// NEW CODE BELOW

public void setSockets(int count)
{
    socketCount = count;
}
src/server/zone/objects/tangible/LuaTangibleObject.h

C++:
int isSliced(lua_State* L);
int isNoTrade(lua_State* L);
// NEW CODE BELOW
int setSocketCount(lua_State* L);
src/server/zone/objects/tangible/LuaTangibleObject.cpp

C++:
#include "server/zone/objects/player/FactionStatus.h"
//NEW INCLUDE BELOW
#include "server/zone/objects/tangible/wearables/WearableObject.h"
----------------------------------------------------------------------
{ "isSliced", &LuaTangibleObject::isSliced},
{ "isNoTrade", &LuaTangibleObject::isNoTrade},
// NEW CODE BELOW
{ "setSocketCount", &LuaTangibleObject::setSocketCount},
----------------------------------------------------------------------
int LuaTangibleObject::isNoTrade(lua_State* L){
    bool noTrade = realObject->isNoTrade();
    
    lua_pushboolean(L, noTrade);
    
    return 1;
}

// NEW CODE BELOW

int LuaTangibleObject::setSocketCount(lua_State* L){

    int count = lua_tointeger(L, -1);
    
    if (realObject->isWearableObject() && realObject != nullptr)
    {
        Locker locker(realObject);
        
        WearableObject* wo = cast<WearableObject*>(realObject);
        
        // Prevent over 4 sockets
        if (count > 4)
        { count = 4; }
        // Prevent trying to set negative sockets
        if (count < 0)
        { count = 0; }
        
        wo->setSockets(count);
    }
    
    return 0;
}

How to Use:

LUA EXAMPLE:

Code:
local pInventory = CreatureObject(pPLayer):getSlottedObject("inventory")

if (pInventory == nil) then
    return 0
end

local pItem = giveItem(pInventory, "object/tangible/wearables/goggles/goggles_s01.iff", -1)

TangibleObject(pItem):setSocketCount(4);
 

netyoda

Member
Joined
Oct 18, 2017
Messages
42
Thank you for sharing this, I know many Jedi will cry in their cantinas with happiness at the thought that we may introduce sockets into robes in the future :p

I had to add
#include "server/zone/objects/tangible/wearables/WearableObject.h"
at the top of
src/server/zone/objects/tangible/LuaTangibleObject.cpp
but you probably already had that included for some other wonderful stuff
 

netyoda

Member
Joined
Oct 18, 2017
Messages
42
Joined Oct 18, 2017
Messages31

New Member
*sobs* it doesn't matter how long I've lived here. I wasn't born here so I'll never be accepted*
 

Valkyra

Member
Joined
Aug 31, 2010
Messages
211
Thank you for sharing this, I know many Jedi will cry in their cantinas with happiness at the thought that we may introduce sockets into robes in the future :p

I had to add
#include "server/zone/objects/tangible/wearables/WearableObject.h"
at the top of
src/server/zone/objects/tangible/LuaTangibleObject.cpp
but you probably already had that included for some other wonderful stuff
You could theoretically do that without needing Phoenix's code, but it's been forever since I coded in jedi robes initially iirc it just uses it's own attrib component, though you could have it inherit wearable object, maybe(TM) (don't quote me on this)
 

Phoenix

Moderator
Staff member
Moderator
Joined
Sep 25, 2010
Messages
235
You could theoretically do that without needing Phoenix's code, but it's been forever since I coded in jedi robes initially iirc it just uses it's own attrib component, though you could have it inherit wearable object, maybe(TM) (don't quote me on this)
Yea, Jedi Robes have their own attrib component, so this works but it won't show up on the robe. You have to modify the custom attribute list component of the robes to get it to show.
 

Phoenix

Moderator
Staff member
Moderator
Joined
Sep 25, 2010
Messages
235
Thank you for sharing this, I know many Jedi will cry in their cantinas with happiness at the thought that we may introduce sockets into robes in the future :p

I had to add
#include "server/zone/objects/tangible/wearables/WearableObject.h"
at the top of
src/server/zone/objects/tangible/LuaTangibleObject.cpp
but you probably already had that included for some other wonderful stuff

It is located up there where I posted. the include. it is first couple lines of that section

C++:
#include "server/zone/objects/player/FactionStatus.h"
//NEW INCLUDE BELOW
#include "server/zone/objects/tangible/wearables/WearableObject.h"
 
Top Bottom