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

Item exhaustion

Hokku

Member
Joined
Jul 25, 2013
Messages
95
Reaction score
17
Location
Extremadura, Spain
Im trying to implement exhaustion to put on some items like rings and amulets, tried Red's scripts and this one:

Code:
local SSAdelay = 2 -- seconds
function Player:onMoveItem(item, count, fromPosition, toPosition)
    local tile = toPosition:getTile()
    if tile then
        local thing = tile:getItemByType(ITEM_TYPE_TELEPORT)
        if thing ~= nil then
            self:sendCancelMessage("Sorry, not possible.")
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:getId() == 2197 then
        if toPosition.y == CONST_SLOT_NECKLACE then
            if os.time() > self:getStorageValue(500000) then
                self:setStorageValue(500000, os.time() + SSAdelay)
            else
                self:sendCancelMessage("Sorry, not possible.")
                return false
            end
        end
    end

    if isInArray({1714, 1715, 1716, 1717, 1738, 1740, 1741, 1747, 1748, 1749}, item.itemid) and item.actionid > 0 then
        self:sendCancelMessage('You cannot move this object.')
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
   
    return true
end

seems no ones working, im using TFS 1.1! someone? :(
 
what doesnt work about it?
can try this
Lua:
local SSAdelay = 2 -- seconds
local items = {1714, 1715, 1716, 1717, 1738, 1740, 1741, 1747, 1748, 1749}

function Player:onMoveItem(item, count, fromPosition, toPosition)
    local tile = toPosition:getTile()
    if tile then
        local thing = tile:getItemByType(ITEM_TYPE_TELEPORT)
        if thing then
            self:sendCancelMessage("Sorry, not possible.")
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:getId() == 2197 then
        if toPosition.y == CONST_SLOT_NECKLACE then
            if os.mtime() >= self:getStorageValue(500000) then
                self:setStorageValue(500000, os.mtime() + (SSAdelay * 1000))
            else
                self:sendCancelMessage("Sorry, not possible.")
                return false
            end
        end
    end

    if isInArray(items, item.itemid) and item.actionid > 0 then
        self:sendCancelMessage('You cannot move this object.')
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
   
    return true
end
 
It's good, just use slot's number value instead of CONST value.
Lua:
if toPosition.y == 2 then

Lua:
    CONST_SLOT_WHEREEVER = 0,
    CONST_SLOT_HEAD = 1,
    CONST_SLOT_NECKLACE = 2,
    CONST_SLOT_BACKPACK = 3,
    CONST_SLOT_ARMOR = 4,
    CONST_SLOT_RIGHT = 5,
    CONST_SLOT_LEFT = 6,
    CONST_SLOT_LEGS = 7,
    CONST_SLOT_FEET = 8,
    CONST_SLOT_RING = 9,
    CONST_SLOT_AMMO = 10,
 
It's good, just use slot's number value instead of CONST value.
Lua:
if toPosition.y == 2 then

Lua:
    CONST_SLOT_WHEREEVER = 0,
    CONST_SLOT_HEAD = 1,
    CONST_SLOT_NECKLACE = 2,
    CONST_SLOT_BACKPACK = 3,
    CONST_SLOT_ARMOR = 4,
    CONST_SLOT_RIGHT = 5,
    CONST_SLOT_LEFT = 6,
    CONST_SLOT_LEGS = 7,
    CONST_SLOT_FEET = 8,
    CONST_SLOT_RING = 9,
    CONST_SLOT_AMMO = 10,
no, there's a point for using const in code
if you're a noob and you decide to take a look at tfs code and just see random 2s 4s 3s etc, you'll have no idea what's going on
the const names tell you what it corresponds to, and lets you know that it's not just random ass numbers all over the place
 
Add a print("test") below
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition)

If it dosn't show "test" in your console the script isn't even executed, check events.xml to see if it's enabled or not.
 
Add a print("test") below
Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition)

If it dosn't show "test" in your console the script isn't even executed, check events.xml to see if it's enabled or not.

tried

Code:
    <event class="Player" method="onMoveItem" enabled="1" />

Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
print("test")
    local tile = toPosition:getTile()

not respone on console :/
 
tried

Code:
    <event class="Player" method="onMoveItem" enabled="1" />

Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
print("test")
    local tile = toPosition:getTile()

not respone on console :/

Do you have your source code?
In that case can you check if you even have the onMoveItem function

It was added at 22 Dec 2013 so you should have it but please make sure and did you restart the server after changing enabled to 1(if it was 0)?

New Lua events, etc · otland/forgottenserver@9171c3c · GitHub
 
Do you have your source code?
In that case can you check if you even have the onMoveItem function

It was added at 22 Dec 2013 so you should have it but please make sure and did you restart the server after changing enabled to 1(if it was 0)?

New Lua events, etc · otland/forgottenserver@9171c3c · GitHub

I havent them, anyway it was compiled on Mar 2015. I restarted and tried but nothing, is another way to check it?

i alrdy got the func on events/scripts/player.lua
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    return true
end
 
I havent them, anyway it was compiled on Mar 2015. I restarted and tried but nothing, is another way to check it?

i alrdy got the func on events/scripts/player.lua
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    return true
end
did you add the code for item exhaustion after the onMoveItem that was already there?
aka do you have two onMoveItem functions inside 1 file?
if so the last one will overwrite it, and it will use that one instead
otherwise there's no reason there should be a problem if you have it set to enabled in xml
 
did you add the code for item exhaustion after the onMoveItem that was already there?
aka do you have two onMoveItem functions inside 1 file?
if so the last one will overwrite it, and it will use that one instead
otherwise there's no reason there should be a problem if you have it set to enabled in xml

I though that was neceseary to work the func, i removed but nothing happens, will try to check the exhaustion formula and compare to one of my server, im thinking is about it.
 
Back
Top