• 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!

TFS 1.X+ Item not replace if equipted

Gicu

Well-Known Member
Joined
Feb 26, 2011
Messages
187
Reaction score
52
example: If i put item on slot HELMET and is equipted other on i cant, why not change item on slot?
 
from ground
Post automatically merged:

Form backpack working good
TFS 1.3 newest

i use Upgrade system and change onMoveItem
function us_onMoveItem(player, item, fromPosition, toPosition)
if not item:getType():isUpgradable() or toPosition.y == CONST_SLOT_AMMO then
return true
end

if not item:getType():usesSlot(toPosition.y) then
return true
end

if item:isUnidentified() then
if toPosition.y <= CONST_SLOT_AMMO and toPosition.y ~= CONST_SLOT_BACKPACK then
--player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't wear unidentified items.")
player:say("You can't wear unidentified items!", TALKTYPE_MONSTER_SAY)
return false
end
end

if US_CONFIG.REQUIRE_LEVEL == true then
if player:getLevel() < item:getItemLevel() and not item:isLimitless() then
if toPosition.y <= CONST_SLOT_AMMO and toPosition.y ~= CONST_SLOT_BACKPACK then
--player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need higher level to equip that item.")
player:say("Need higher level!", TALKTYPE_MONSTER_SAY)
return false
end
end
end

if toPosition.y <= CONST_SLOT_AMMO then
if toPosition.y ~= CONST_SLOT_BACKPACK then
if fromPosition.y >= 64 or fromPosition.x ~= CONTAINER_POSITION then
-- remove old
local oldItem = player:getSlotItem(toPosition.y)
if oldItem then
if oldItem:getType():isUpgradable() then
local oldBonuses = oldItem:getBonusAttributes()
if oldBonuses then
for key, value in pairs(oldBonuses) do
local attr = US_ENCHANTMENTS[value[1]]
if attr then
if attr.combatType == US_TYPES.CONDITION then
if US_CONDITIONS[value[1]] and US_CONDITIONS[value[1]][value[2]] then
if US_CONDITIONS[value[1]][value[2]]:getType() ~= CONDITION_MANASHIELD then
player:removeCondition(
US_CONDITIONS[value[1]][value[2]]:getType(),
CONDITIONID_COMBAT,
US_CONDITIONS[value[1]][value[2]]:getSubId()
)
else
player:removeCondition(US_CONDITIONS[value[1]][value[2]]:getType(), CONDITIONID_COMBAT)
end
end
end
end
end
end
end
end

-- apply new
if item:getType():isUpgradable() then
local newBonuses = item:getBonusAttributes()
if newBonuses then
for key, value in pairs(newBonuses) do
local attr = US_ENCHANTMENTS[value[1]]
if attr then
if attr.combatType == US_TYPES.CONDITION then
if not US_CONDITIONS[value[1]] then
US_CONDITIONS[value[1]] = {}
end
if not US_CONDITIONS[value[1]][value[2]] then
US_CONDITIONS[value[1]][value[2]] = Condition(attr.condition)
if attr.condition ~= CONDITION_MANASHIELD then
US_CONDITIONS[value[1]][value[2]]:setParameter(attr.param, attr.percentage == true and 100 + value[2] or value[2])
US_CONDITIONS[value[1]][value[2]]:setParameter(CONDITION_PARAM_TICKS, -1)
US_CONDITIONS[value[1]][value[2]]:setParameter(CONDITION_PARAM_SUBID, 1000 + math.ceil(value[1] ^ 2) + value[2])
else
US_CONDITIONS[value[1]][value[2]]:setParameter(CONDITION_PARAM_TICKS, 86400000)
end
US_CONDITIONS[value[1]][value[2]]:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
player:addCondition(US_CONDITIONS[value[1]][value[2]])
if attr == BONUS_TYPE_MAXHP then
if player:getHealth() == maxHP then
player:addHealth(player:getMaxHealth())
end
end
if attr == BONUS_TYPE_MAXMP then
if player:getMana() == maxMP then
player:addMana(player:getMaxMana())
end
end
else
player:addCondition(US_CONDITIONS[value[1]][value[2]])
if attr.param == CONDITION_PARAM_STAT_MAXHITPOINTS then
if player:getHealth() == maxHP then
player:addHealth(player:getMaxHealth())
end
end
if attr.param == CONDITION_PARAM_STAT_MAXMANAPOINTS then
if player:getMana() == maxMP then
player:addMana(player:getMaxMana())
end
end
end
end
end
end
end
end
end
end
end

return true
end
And this si my events/player.h onMoveItem
function Player:eek:nMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if item:getActionId() == CURSED_CHESTS_AID then return false end

if toPosition.x ~= CONTAINER_POSITION then
return true
end

if item:getTopParent() == self and bit.band(toPosition.y, 0x40) == 0 then
local itemType, moveItem = ItemType(item:getId())
if bit.band(itemType:getSlotPosition(), SLOTP_TWO_HAND) ~= 0 and toPosition.y == CONST_SLOT_LEFT then
moveItem = self:getSlotItem(CONST_SLOT_RIGHT)
elseif itemType:getWeaponType() == WEAPON_SHIELD and toPosition.y == CONST_SLOT_RIGHT then
moveItem = self:getSlotItem(CONST_SLOT_LEFT)
if moveItem and bit.band(ItemType(moveItem:getId()):getSlotPosition(), SLOTP_TWO_HAND) == 0 then
return true
end
end

if moveItem then
local parent = item:getParent()
if parent:isContainer() and parent:getSize() == parent:getCapacity() then
self:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CONTAINERNOTENOUGHROOM))
return false
else
return moveItem:moveTo(parent)
end
end
end
return us_onMoveItem(self, item, fromPosition, toPosition)
end
 
bump
Post automatically merged:

Simple script if item is on ground cant equip in slots :(
 
Last edited:
Here
Remove those then recompile and it will work like you want.
C++:
        const Cylinder* cylinder = item->getTopParent();
        if (cylinder && (dynamic_cast<const DepotChest*>(cylinder) || dynamic_cast<const Player*>(cylinder)))
        return RETURNVALUE_NOTENOUGHROOM;
 
As I mentioned, I only changed this in player.cpp
C++:
    //need an exchange with source? (destination item is swapped with currently moved item)
    const Item* inventoryItem = getInventoryItem(static_cast<slots_t>(index));
    if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) {
        const Cylinder* cylinder = item->getTopParent();
        if (cylinder && (dynamic_cast<const DepotChest*>(cylinder) || dynamic_cast<const Player*>(cylinder))) {
            return RETURNVALUE_NEEDEXCHANGE;
        }

        return RETURNVALUE_NOTENOUGHROOM;
    }
    return ret;
}
to this
C++:
    //need an exchange with source? (destination item is swapped with currently moved item)
    const Item* inventoryItem = getInventoryItem(static_cast<slots_t>(index));
    if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) {
            return RETURNVALUE_NEEDEXCHANGE;
    }
    return ret;
}
 
As I mentioned, I only changed this in player.cpp
C++:
    //need an exchange with source? (destination item is swapped with currently moved item)
    const Item* inventoryItem = getInventoryItem(static_cast<slots_t>(index));
    if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) {
        const Cylinder* cylinder = item->getTopParent();
        if (cylinder && (dynamic_cast<const DepotChest*>(cylinder) || dynamic_cast<const Player*>(cylinder))) {
            return RETURNVALUE_NEEDEXCHANGE;
        }

        return RETURNVALUE_NOTENOUGHROOM;
    }
    return ret;
}
to this
C++:
    //need an exchange with source? (destination item is swapped with currently moved item)
    const Item* inventoryItem = getInventoryItem(static_cast<slots_t>(index));
    if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) {
            return RETURNVALUE_NEEDEXCHANGE;
    }
    return ret;
}
Was looking for this, thanks. How too add a bool to read config.lua so if it has classicequpmentslot turned on it would work with the new config? To not delete code
 
This should work
C++:
    //need an exchange with source? (destination item is swapped with currently moved item)
    const Item* inventoryItem = getInventoryItem(static_cast<slots_t>(index));
    if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) {
        if (!g_config.getBoolean(ConfigManager::CLASSIC_EQUIPMENT_SLOTS)) {
            const Cylinder* cylinder = item->getTopParent();
            if (cylinder && (dynamic_cast<const DepotChest*>(cylinder) || dynamic_cast<const Player*>(cylinder))) {
                return RETURNVALUE_NEEDEXCHANGE;
            }
            return RETURNVALUE_NOTENOUGHROOM;
        }

        return RETURNVALUE_NEEDEXCHANGE;
    }
    return ret;
}
 
This should work
C++:
    //need an exchange with source? (destination item is swapped with currently moved item)
    const Item* inventoryItem = getInventoryItem(static_cast<slots_t>(index));
    if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) {
        if (!g_config.getBoolean(ConfigManager::CLASSIC_EQUIPMENT_SLOTS)) {
            const Cylinder* cylinder = item->getTopParent();
            if (cylinder && (dynamic_cast<const DepotChest*>(cylinder) || dynamic_cast<const Player*>(cylinder))) {
                return RETURNVALUE_NEEDEXCHANGE;
            }
            return RETURNVALUE_NOTENOUGHROOM;
        }

        return RETURNVALUE_NEEDEXCHANGE;
    }
    return ret;
}
Thank gonna test later but I'm sure it's working, thanks again

It worked, thanks

Regards
 
Last edited:
Back
Top