• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Constructionkits.lua

manutd4evr7

New Member
Joined
Jul 11, 2009
Messages
51
Reaction score
1
Hello, if anyone could post their constructionkits.lua for 8.5(tfs 0.3.5) i would appreciate it. it seems as if mine are bugged, a player will buy for example a small table, try to use the construction kit, it will open as a regular item, such as opening a backpack, then when you walk away from the kit until it appears off your screen, then come back to it, it finally works.
Thanks in advance!
 
game.cpp, you should the whole function
[cpp]Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
{
if(item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0)))
return item;

Cylinder* cylinder = item->getParent();
if(!cylinder)
return NULL;

int32_t itemIndex = cylinder->__getIndexOfThing(item);
if(itemIndex == -1)
{
#ifdef __DEBUG__
std::cout << "Error: transformItem, itemIndex == -1" << std::endl;
#endif
return item;
}

if(!item->canTransform())
return item;

const ItemType& curType = Item::items[item->getID()];
const ItemType& newType = Item::items[newId];
if(curType.alwaysOnTop != newType.alwaysOnTop)
{
//This only occurs when you transform items on tiles from a downItem to a topItem (or vice versa)
//Remove the old, and add the new
ReturnValue ret = internalRemoveItem(NULL, item);
if(ret != RET_NOERROR)
return item;

Item* newItem = NULL;
if(newCount == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);

newItem->copyAttributes(item);
if(internalAddItem(NULL, cylinder, newItem, INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
return newItem;

delete newItem;
return NULL;
}

if(curType.type == newType.type)
{
//Both items has the same type so we can safely change id/subtype
if(!newCount && (item->isStackable() || item->hasCharges()))
{
if(!item->isStackable() && (!item->getDefaultDuration() || item->getDuration() <= 0))
{
int32_t tmpId = newId;
if(curType.id == newType.id)
tmpId = curType.decayTo;

if(tmpId != -1)
{
item = transformItem(item, tmpId);
return item;
}
}

internalRemoveItem(NULL, item);
return NULL;
}

uint16_t itemId = item->getID();
int32_t count = item->getSubType();

cylinder->postRemoveNotification(NULL, item, cylinder, itemIndex, false);
if(curType.id != newType.id)
{
itemId = newId;
if(newType.group != curType.group)
item->setDefaultSubtype();
}

if(newCount != -1 && newType.hasSubType())
count = newCount;

cylinder->__updateThing(item, itemId, count);
cylinder->postAddNotification(NULL, item, cylinder, itemIndex);
return item;
}

//Replacing the the old item with the new while maintaining the old position
Item* newItem = NULL;
if(newCount == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);

if(!newItem)
{
#ifdef __DEBUG__
std::cout << "Error: [Game::transformItem] Item of type " << item->getID() << " transforming into invalid type " << newId << std::endl;
#endif
return NULL;
}

cylinder->__replaceThing(itemIndex, newItem);
cylinder->postAddNotification(NULL, newItem, cylinder, itemIndex);

item->setParent(NULL);
cylinder->postRemoveNotification(NULL, item, cylinder, itemIndex, true);

FreeThing(item);
return newItem;
}[/cpp]
with
[cpp]Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
{
if(item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0)))
return item;

Cylinder* cylinder = item->getParent();
if(!cylinder)
return NULL;

int32_t itemIndex = cylinder->__getIndexOfThing(item);
if(itemIndex == -1)
{
#ifdef __DEBUG__
std::cout << "Error: transformItem, itemIndex == -1" << std::endl;
#endif
return item;
}

if(!item->canTransform())
return item;

const ItemType& curType = Item::items[item->getID()];
const ItemType& newType = Item::items[newId];
if(curType.alwaysOnTop != newType.alwaysOnTop)
{
//This only occurs when you transform items on tiles from a downItem to a topItem (or vice versa)
//Remove the old, and add the new
ReturnValue ret = internalRemoveItem(NULL, item);
if(ret != RET_NOERROR)
return item;

Item* newItem = NULL;
if(newCount == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);

if(!newItem)
return NULL;

newItem->copyAttributes(item);
if(internalAddItem(NULL, cylinder, newItem, INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
return newItem;

delete newItem;
return NULL;
}

if(!newCount && (item->isStackable() || item->hasCharges()))
{
if(!item->isStackable() && (!item->getDefaultDuration() || item->getDuration() <= 0))
{
int32_t tmpId = newId;
if(curType.id == newType.id)
tmpId = curType.decayTo;

if(tmpId != -1)
{
item = transformItem(item, tmpId);
return item;
}
}

internalRemoveItem(NULL, item);
return NULL;
}

uint16_t itemId = item->getID();
int32_t count = item->getSubType();

if(curType.id != newType.id)
{
itemId = newId;
if(newType.group != curType.group)
item->setDefaultSubtype();
}

if(newCount != -1 && newType.hasSubType())
count = newCount;

if(curType.type != newType.type && (curType.type == ITEM_TYPE_CONTAINER || newType.type == ITEM_TYPE_CONTAINER)) {
internalRemoveItem(NULL, item);
Item* newItem = NULL;
if(count == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);

if(!newItem)
return NULL;

if(internalAddItem(NULL, cylinder, newItem, INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
return newItem;

delete newItem;
return NULL;
}
cylinder->postRemoveNotification(NULL, item, cylinder, itemIndex, false);
cylinder->__updateThing(item, itemId, count);
cylinder->postAddNotification(NULL, item, cylinder, itemIndex);
return item;
}[/cpp]
 
it's a file in sources.
You have to download the sources for TFS you're using.
36pl1 or 0.4 whatever TFS trunk you use.
 
Back
Top