• 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+ get equipped item name

T

Tibia Demon

Guest
i have made this to check if player have set but how i say which item he don't have?
Lua:
local DemonItems = {
    [CONST_SLOT_HEAD] = {2493},
    [CONST_SLOT_NECKLACE] = {2197},
    [CONST_SLOT_BACKPACK] = {10518},
    [CONST_SLOT_ARMOR] = {2494},
    [CONST_SLOT_RIGHT] = {2520},
    [CONST_SLOT_LEFT] = {7420},
    [CONST_SLOT_LEGS] = {2495},
    [CONST_SLOT_FEET] = {5462},
    [CONST_SLOT_RING] = {2214},
}

for slotId = CONST_SLOT_HEAD, CONST_SLOT_RING do
    local slotItem = player:getSlotItem(slotId)
    if not (slotItem) or not (table.contains(DemonItems[slotId], slotItem:getId())) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have "..slotItem:getName()..".")
        return true
        end
    end
Lua:
player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have "..slotItem:getName()..".")
i need this to say what items he is missing
 
Solution
i have made this to check if player have set but how i say which item he don't have?
Lua:
local DemonItems = {
    [CONST_SLOT_HEAD] = {2493},
    [CONST_SLOT_NECKLACE] = {2197},
    [CONST_SLOT_BACKPACK] = {10518},
    [CONST_SLOT_ARMOR] = {2494},
    [CONST_SLOT_RIGHT] = {2520},
    [CONST_SLOT_LEFT] = {7420},
    [CONST_SLOT_LEGS] = {2495},
    [CONST_SLOT_FEET] = {5462},
    [CONST_SLOT_RING] = {2214},
}

for slotId = CONST_SLOT_HEAD, CONST_SLOT_RING do
    local slotItem = player:getSlotItem(slotId)
    if not (slotItem) or not (table.contains(DemonItems[slotId], slotItem:getId())) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have "..slotItem:getName()..".")
        return true
        end
    end
Lua:
player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have "..slotItem:getName()..".")
i need this to say what items he is missing
...
i have made this to check if player have set but how i say which item he don't have?
Lua:
local DemonItems = {
    [CONST_SLOT_HEAD] = {2493},
    [CONST_SLOT_NECKLACE] = {2197},
    [CONST_SLOT_BACKPACK] = {10518},
    [CONST_SLOT_ARMOR] = {2494},
    [CONST_SLOT_RIGHT] = {2520},
    [CONST_SLOT_LEFT] = {7420},
    [CONST_SLOT_LEGS] = {2495},
    [CONST_SLOT_FEET] = {5462},
    [CONST_SLOT_RING] = {2214},
}

for slotId = CONST_SLOT_HEAD, CONST_SLOT_RING do
    local slotItem = player:getSlotItem(slotId)
    if not (slotItem) or not (table.contains(DemonItems[slotId], slotItem:getId())) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have "..slotItem:getName()..".")
        return true
        end
    end
Lua:
player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have "..slotItem:getName()..".")
i need this to say what items he is missing

If you want the player to know what items they are missing, you have to let the loop go through the entire table, and store the information for use later.

Lua:
local DemonItems = {
    [CONST_SLOT_HEAD] = {2493},
    [CONST_SLOT_NECKLACE] = {2197},
    [CONST_SLOT_BACKPACK] = {10518},
    [CONST_SLOT_ARMOR] = {2494},
    [CONST_SLOT_RIGHT] = {2520},
    [CONST_SLOT_LEFT] = {7420},
    [CONST_SLOT_LEGS] = {2495},
    [CONST_SLOT_FEET] = {5462},
    [CONST_SLOT_RING] = {2214},
}

local missingItems = ""

for slotId = CONST_SLOT_HEAD, CONST_SLOT_RING do
    local slotItem = player:getSlotItem(slotId)
    if not slotItem or not table.contains(DemonItems[slotId], slotItem:getId()) then
        if missingItems ~= "" then
            missingItems = missingItems .. ", "
        end
        missingItems = missingItems .. ItemType(DemonItems[slotId][1]):getName()
    end
end

if missingItems ~= "" then
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You are missing these items from the demon set: " .. missingItems .. ".")
    return true
end

player:sendTextMessage(MESSAGE_INFO_DESCR, "You have the full demon set worn.")

Now if the demon set can have multiple id's for helmet, armor, et cetera.. you might want to set up another table that says the equipment slot that is missing, instead of grabbing the item name directly.

Anyway, that should get you going.
 
Solution
Back
Top