• 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+ onmoveitem

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,478
Solutions
18
Reaction score
195
Location
Sweden
I have a part in my events 'onMoveItem' which stopped to work as intended when i changed TFS from 1.4 to 1.4.2.

It prints correctly but it wont return false hence allowing the item to be moved, is this handled somewhere else?

events/scripts/player.lua: onMoveItem
LUA:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
local player = Player(self)
print("tja")
local chests = {1740,1747,1748,1749,7472}
if item:getActionId() == 9999 or item:getActionId() == 7404 or isInArray(chests, item.itemid) and item:getActionId() > 0 then
    print("bingbong") --this prints
    return false --this wont do shizzle
end
    if hasEventCallback(EVENT_CALLBACK_ONMOVEITEM) then
        return EventCallback(EVENT_CALLBACK_ONMOVEITEM, self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    end
    return true
end

XML:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<events>
    <!-- Creature methods -->
    <event class="Creature" method="onChangeOutfit" enabled="0" />
    <event class="Creature" method="onAreaCombat" enabled="0" />
    <event class="Creature" method="onTargetCombat" enabled="1" />
    <event class="Creature" method="onHear" enabled="0" />

    <!-- Party methods -->
    <event class="Party" method="onJoin" enabled="0" />
    <event class="Party" method="onLeave" enabled="0" />
    <event class="Party" method="onDisband" enabled="0" />
    <event class="Party" method="onShareExperience" enabled="1" />

    <!-- Player methods -->
    <event class="Player" method="onBrowseField" enabled="1" />
    <event class="Player" method="onLook" enabled="1" />
    <event class="Player" method="onLookInBattleList" enabled="1" />
    <event class="Player" method="onLookInTrade" enabled="1" />
    <event class="Player" method="onLookInShop" enabled="1" />
    <event class="Player" method="onMoveItem" enabled="1" /> <!--yep this is 1 -->
    <event class="Player" method="onItemMoved" enabled="1" />
    <event class="Player" method="onMoveCreature" enabled="0" />
    <event class="Player" method="onReportBug" enabled="1" />
    <event class="Player" method="onReportRuleViolation" enabled="1" />
    <event class="Player" method="onTurn" enabled="0" />
    <event class="Player" method="onTradeRequest" enabled="1" />
    <event class="Player" method="onTradeAccept" enabled="0" />
    <event class="Player" method="onTradeCompleted" enabled="0" />
    <event class="Player" method="onGainExperience" enabled="1" />
    <event class="Player" method="onLoseExperience" enabled="0" />
    <event class="Player" method="onGainSkillTries" enabled="1" />
    <event class="Player" method="onWrapItem" enabled="1" />

    <!-- Monster methods -->
    <event class="Monster" method="onDropLoot" enabled="1" />
    <event class="Monster" method="onSpawn" enabled="1" />
</events>
 
Last edited:
Solution
This TFS 1.4.2 is correct, you just add EventCallback directly. For example: data/scripts/EventCallback/player/default_onMoveItem.lua. Add your code there, save, restart, and test it works fine. You don’t need to edit the common player.lua anymore. It’s better to just add things like onMoveItem, onLook, and others. EventCallback solves it faster than the common way.


Usually, when I add systems like reward, chest, dummy, and other things, they worked fine… and I never had to touch player.lua again.
forgottenserver/src/game.cpp at d498855e773b6d9e77d310ae36f75c4c95ca3155 · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/d498855e773b6d9e77d310ae36f75c4c95ca3155/src/game.cpp#L1081)

Instead of returning false, it's best to return a valid ReturnValue such as RETURNVALUE_NOTPOSSIBLE.
But yes, line 1083 indicates that anything other than RETURNVALUE_NOERROR should return early.

(Obviously the above is for latest TFS, I'm not sure the related code is any different to your sources)
 
forgottenserver/src/game.cpp at d498855e773b6d9e77d310ae36f75c4c95ca3155 · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/d498855e773b6d9e77d310ae36f75c4c95ca3155/src/game.cpp#L1081)

Instead of returning false, it's best to return a valid ReturnValue such as RETURNVALUE_NOTPOSSIBLE.
But yes, line 1083 indicates that anything other than RETURNVALUE_NOERROR should return early.

(Obviously the above is for latest TFS, I'm not sure the related code is any different to your sources)
Thanks, that was exactly the change that was made which made it not work,

Old tfs:
C++:
    Player* actorPlayer = actor ? actor->getPlayer() : nullptr;
    if (actorPlayer && fromPos && toPos) {
        if (!g_events->eventPlayerOnMoveItem(actorPlayer, item, count, *fromPos, *toPos, fromCylinder, toCylinder)) {
            return RETURNVALUE_NOTPOSSIBLE;
        }
    }

New TFS:
C++:
    Player* actorPlayer = actor ? actor->getPlayer() : nullptr;
    if (actorPlayer && fromPos && toPos) {
        const ReturnValue ret = g_events->eventPlayerOnMoveItem(actorPlayer, item, count, *fromPos, *toPos, fromCylinder, toCylinder);
        if (ret != RETURNVALUE_NOERROR) {
            return ret;
        }
    }
 
Weirdly enough, returning false should have been enough to trigger the old code. Unless the eventPlayerOnMoveItem was returning something else other than the false.

But still glad you got it sorted 👍
 
This TFS 1.4.2 is correct, you just add EventCallback directly. For example: data/scripts/EventCallback/player/default_onMoveItem.lua. Add your code there, save, restart, and test it works fine. You don’t need to edit the common player.lua anymore. It’s better to just add things like onMoveItem, onLook, and others. EventCallback solves it faster than the common way.


Usually, when I add systems like reward, chest, dummy, and other things, they worked fine… and I never had to touch player.lua again.
 
Solution
Weirdly enough, returning false should have been enough to trigger the old code. Unless the eventPlayerOnMoveItem was returning something else other than the false.

But still glad you got it sorted 👍
Or so i thought I got it solved, seems like i cant move any items now, haha.
This TFS 1.4.2 is correct, you just add EventCallback directly. For example: data/scripts/EventCallback/player/default_onMoveItem.lua. Add your code there, save, restart, and test it works fine. You don’t need to edit the common player.lua anymore. It’s better to just add things like onMoveItem, onLook, and others. EventCallback solves it faster than the common way.


Usually, when I add systems like reward, chest, dummy, and other things, they worked fine… and I never had to touch player.lua again.
Tried that and reverted the source change but it acted the same, it prints but keeps moving the items with aid 9999 etc.

Edit: Nvm, I ofcourse had to use return RETURNVALUE_NOTPOSSIBLE and not return false, now it works as it was intended in 1.4.2.
Thank you both!
 
Last edited:
Back
Top