• 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+ Some items do not trigger onEquip/onDequip

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,336
Solutions
68
Reaction score
1,018
Hello everyone,

I am trying to create an onEquip that will get the stats off all worn items and print them out. The script seems to work properly on some items but not on others. Do we know of any problem in tfs that might cause this?

In the code I have registered two items. Demon shield and leather armor. When I equip the demon shield the script runs properly and I see the defense of it printed out. When I equip the leather armor nothing is printed but when I equip the demon shield again I also see the armor value included from the leather armor.

I also want to add the equip event fires 3x even though I have added the fix that should of made it only fire 1x so idk wth is up with that but it is a seperate issue.

Code:
Armor: 0 Defense: 21
Armor: 0 Defense: 21
Armor: 0 Defense: 56

here is the code but I don't think the issue is here.
Lua:
local moveeventEquip = MoveEvent()
moveeventEquip:type("equip")

local slots = {
    CONST_SLOT_HEAD,
    CONST_SLOT_NECKLACE,
    CONST_SLOT_ARMOR,
    CONST_SLOT_RIGHT,
    CONST_SLOT_LEFT,
    CONST_SLOT_LEGS,
    CONST_SLOT_FEET,
    CONST_SLOT_RING
}

function moveeventEquip.onEquip(player, item, slot, isCheck)
    if not player then return true end
   
    local armor = 0
    local defense = 0
    local dodge = 0
    local block = 0
    for i = 1, #slots do
        local slotItem = player:getSlotItem(slots[i])
       
        if slotItem then
            local slotItemArmor = slotItem:getArmor()
            local slotItemDefense = slotItem:getDefense()
            -- Add dodge, and block
           
            if slotItemArmor then armor = armor + slotItemArmor end
            if slotItemDefense then defense = defense + slotItemDefense end
        end
    end
   
    print("Armor: "..armor)
    print("Defense: "..defense)
    return true
end

local items = {2520, 2467}

for i = 1, #items do
    moveeventEquip:id(items[i])
end

moveeventEquip:register()
 
Last edited:
Lua:
if isCheck then
    print("item is now finished equipping, do stuff.")
else
    print("Item is still being equipped..")
end
 
C++:
int LuaScriptInterface::luaMoveEventRegister(lua_State* L)
{
    // moveevent:register()
    MoveEvent* moveevent = getUserdata<MoveEvent>(L, 1);
    if (moveevent) {
        if ((moveevent->getEventType() == MOVE_EVENT_EQUIP || moveevent->getEventType() == MOVE_EVENT_DEEQUIP) &&
            moveevent->getSlot() == SLOTP_WHEREEVER) {
            uint32_t id = moveevent->getItemIdRange().at(0);
            ItemType& it = Item::items.getItemType(id);
            moveevent->setSlot(it.slotPosition);
        }
It looks like moveevent with equip or deequip event type requires slot type.
This slot type is loaded from first item on list (probably item with lowest ID). So to make it execute for armors, legs, shields etc. you would need to create multiple moveevents and make them all execute same function - if you want all to execute same code.
 
Back
Top