ForgottenNot
Member
- Joined
- Feb 10, 2023
- Messages
- 289
- Reaction score
- 24
The replaceable function in my server is not letting fields be used over items with replaceable flag set to 0 field, would like the field appear over it but not removing the item below
if i set flag to 1 the field works but the item below simply disapears
i use tfs 1.3/ 1.5 8.6
have not editied anything related to it
solved changed whole thing to this
enjoy
this casuses bugs xd up
if i set flag to 1 the field works but the item below simply disapears
i use tfs 1.3/ 1.5 8.6
LUA:
<item fromid="1423" toid="1425" article="a" name="campfire">
<attribute key="replaceable" value="1" />
<attribute key="field" value="fire">
<attribute key="initdamage" value="20" />
<attribute key="ticks" value="4000" />
<attribute key="count" value="2" />
<attribute key="damage" value="10" />
</attribute>
</item>
Post automatically merged:
solved changed whole thing to this
Code:
void Tile::addThing(int32_t, Thing* thing)
{
std::cout << "addThing called with thing ID: " << thing->getID() << std::endl;
Creature* creature = thing->getCreature();
if (creature) {
std::cout << "Adding a creature." << std::endl;
g_game.map.clearSpectatorCache();
if (creature->getPlayer()) {
g_game.map.clearPlayersSpectatorCache();
}
creature->setParent(this);
CreatureVector* creatures = makeCreatures();
creatures->insert(creatures->begin(), creature);
} else {
Item* item = thing->getItem();
if (item == nullptr) {
std::cout << "Item is nullptr, returning." << std::endl;
return; // Handle the case where it's neither creature nor item
}
TileItemVector* items = getItemList();
if (!items) {
items = makeItemList(); // Create new item list if it doesn't exist
} else if (items->size() >= 0xFFFF) {
std::cout << "Too many items, returning." << std::endl;
return; // Too many items
}
item->setParent(this);
const ItemType& itemType = Item::items[item->getID()];
if (itemType.isGroundTile()) {
if (ground == nullptr) {
ground = item;
onAddTileItem(item);
} else {
const ItemType& oldType = Item::items[ground->getID()];
Item* oldGround = ground;
ground->setParent(nullptr);
g_game.ReleaseItem(ground);
ground = item;
resetTileFlags(oldGround);
setTileFlags(item);
onUpdateTileItem(oldGround, oldType, item, itemType);
postRemoveNotification(oldGround, nullptr, 0);
}
} else if (itemType.alwaysOnTop) {
if (itemType.isSplash() && items) {
// Remove old splash if exists
for (auto it = items->getBeginTopItem(); it != items->getEndTopItem(); ++it) {
Item* oldSplash = *it;
if (Item::items[oldSplash->getID()].isSplash()) {
removeThing(oldSplash, 1);
oldSplash->setParent(nullptr);
g_game.ReleaseItem(oldSplash);
postRemoveNotification(oldSplash, nullptr, 0);
break;
}
}
}
bool isInserted = false;
for (auto it = items->getBeginTopItem(); it != items->getEndTopItem(); ++it) {
// Insert according to alwaysOnTopOrder
if (itemType.alwaysOnTopOrder <= Item::items[(*it)->getID()].alwaysOnTopOrder) {
items->insert(it, item);
isInserted = true;
break;
}
}
if (!isInserted) {
items->push_back(item);
}
onAddTileItem(item);
} else if (itemType.isMagicField()) {
// Handle magic field addition
bool replaceExistingField = false;
if (items) {
// Check if there's an existing magic field
for (auto it = items->getBeginDownItem(); it != items->getEndDownItem(); ++it) {
MagicField* existingField = (*it)->getMagicField();
if (existingField) {
if (existingField->isReplaceable()) {
// Remove the existing field if replaceable
removeThing(*it, 1);
(*it)->setParent(nullptr);
g_game.ReleaseItem(*it);
postRemoveNotification(*it, nullptr, 0);
replaceExistingField = true;
break;
} else {
// Non-replaceable magic field, add new field without removing existing field
std::cout << "Adding non-replaceable magic field over existing field." << std::endl;
item->setParent(this);
items->insert(items->getBeginDownItem(), item);
items->addDownItemCount(1);
onAddTileItem(item);
return;
}
}
}
}
// Insert the new magic field if no replacement needed or existing field was replaceable
if (!replaceExistingField) {
std::cout << "Inserting new magic field." << std::endl;
items->insert(items->getBeginDownItem(), item);
items->addDownItemCount(1);
onAddTileItem(item);
}
} else {
// Handle other types of items if necessary
std::cout << "Adding a non-magic field item." << std::endl;
items->insert(items->getBeginDownItem(), item);
items->addDownItemCount(1);
onAddTileItem(item);
}
}
}
Post automatically merged:
this casuses bugs xd up
Last edited: