Forgottenserver: new function for TFS 1.2 > Position:ownerIsPlayer() (or something similar)

Created on 22 Apr 2016  路  9Comments  路  Source: otland/forgottenserver

I created similar issue before, but couldn't find it.
I got back to the part in my game where I wanted to know am I moving item to player container or not.

I don't know how to do C++ so I wrote the idea with Lua

function Position:ownerIsPlayer()
If self.x ~= 65535 then return false end
if self.y <= 10 then return true end -- slot positions
if self.y == 11 then return true end -- this does not exist but perhaps should?
return false
end

Expected behaviour

container position y == 11 should mean that this container window is opened when the container was located on player (which would mean that if open container is moved it will close the window every time)
or
make it somehow get the userdata of the container and check for parent.

Actual behaviour

beyond the slots, next container y pos is 64.
Which simply means open container window (regardless where was it opened from)
When you open 2 windows. the new window will get y pos 65. and so on.
Quite useless information if you ask me, but what do I know.

Will it be possible to add such function into source?
Or if it's not going to happen, would it be possible make it with not much trouble?

This function would open up an option for virtual capacity.

All 9 comments

This should be checked using toCylinder, not a position. The x, y, z positions, when not a tile, should not be relied on as they are protocol internals.

Yes, now I remember something.
Last time you also said something like: "Might pass toCylinder parameter trough Player:onMoveItem event"

Is it possible right now, to get the cylinder userdata with on Player:onMoveItem() event?
How does cylinder userdata even look like? How do you construct it with Lua?

Wouldn't something like this work?

local CONTAINER_POSITION = 0xFFFF
local BIT_CONTAINER = 0x40
local BIT_CONTAINER_ID = 0x0F

function Position.ownerIsPlayer(player)
    if self.x == CONTAINER_POSITION then
        if bit.band(self.y, BIT_CONTAINER) == POS_CONTAINER then
            local container = player:getContainerById(bit.band(self.y, BIT_CONTAINER_ID))
            return container:getTopParent() == player
        end
    end

    return false
end

Actually nevermind since it'd always attempt to fetch the container from that specific player.

POS_CONTAINER
is nil value for me.
Should be be 64?

OMG Oo how its working and where the heck did you find this bit meta table.
What does the other functions do inside the bit? (like rol, bor, etc )

This function is perfect! finally I can give any item userdata its own weight regardless what does it say in xml.

Feel free to send pull request:

1446, #1686

Read what @marksamman said.

@whitevo

Yes sorry I forgot, POS_CONTAINER should be 64.

What does the other functions do inside the bit? (like rol, bor, etc )

https://en.wikipedia.org/wiki/Bitwise_operation
http://lua-users.org/wiki/BitwiseOperators

@whitevo why you close the issue?

because the problem was solved?

@whitevo issue tracker are suppose to track issues to this repository not for support, on repository still needed this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

souzajunior picture souzajunior  路  4Comments

EPuncker picture EPuncker  路  4Comments

MillhioreBT picture MillhioreBT  路  4Comments

irenicus30 picture irenicus30  路  5Comments

Zbizu picture Zbizu  路  5Comments