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

Lua How to prevent put the same item on EQ?

okurde

New Member
Joined
Jan 28, 2009
Messages
134
Reaction score
1
Hello, I am trying to prevent put the same item as character has already weared on this slot -> when player tries to put item there.
Code:
function onEquip(cid, item, slot)
        local itemWeared = getPlayerSlotItem(cid, 1).itemid
        if (itemWeared ~= item.itemid) then
               return true
        else
               return false
        end  
end
But it does not work, when item is put and I try on this slot wear the same item then both items are moved to backpack (generally the first one becasue the second is all the time there)

Thanks in advance
 
While moving item to slot with the same item it prints:
itemWeared - 0
item.itemid - 2342

and both iteams goes to backpack...
 
try, print both again but obviously print item.uid
Code:
function onEquip(cid, item, slot)
    local itemWeared = getPlayerSlotItem(cid, 1).uid
    if (itemWeared ~= item.uid) then
        return true
    else
        return false
    end 
end
 
So you want to prevent the player to wear an item that he has already previously worn in that slot at one time in the game?
Or you are trying to prevent the player from equipping the same item that he already has in this slot?
 
I know there is a problem with getPlayerSlotItem, however this could be handled differently, you could use storage values when an item is equipped in a certain slot.

Maybe something like this
Code:
function getSlotItem(index)
    local baseStorage = 10000
    local slots = 9 -- idk how many slots there are heh
    local slot = {}

    for i = 1, slots do
        slot[i] = baseStorage + i
    end
    return slot[index]
end

function onEquip(cid, item, slot)
    if getCreatureStorage(cid, getSlotItem(1)) ~= item.itemid then
        doCreatureSetStorage(cid, getSlotItem(1), item.itemid)
        return true
    end
end
 
Last edited:
Hmm, trying to do it in this way:
Code:
local storage = 23006
local exhausttime = 5

function onEquip(cid, item, slot)
    print("1")
    if getCreatureStorage(cid,15000) == 1 then
        print("2")
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have already weared this item.")
        return false
    else
        print("3")
        doCreatureSetStorage(cid, 15000, 1)
        exhaustion.set(cid, storage, exhausttime)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have been exhausted [onEquip].")
        return true
    end
    return true
end
and when I try put item to empty slot I see:
You have been exhausted [onEquip].
You have already weared this item

But item is still in backpack oO
and console prints
1
3
1
2

How it is possible that after "You have been exhausted [onEquip]" there is return true and code does not finish?
 
Because the movement scripts their interfaces, onEquip, onStepIn etc.. always seem to execute twice, so when you use a condition of if get this storage value else set this storage value, the if statement is ignored and else executes, but since it is called twice then the if statement executes and the else is ignored.

This is why the output is 1, 3, 1, 2, the 1 being printed twice shows that the onEquip interface was called twice since print('1') is called outside of everything else, while the print 2 or 3 shows how the function executed.

The return true did execute, inside of the else statement.
 
Back
Top