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

Addams

OTMadness.com OTSes Services
Staff member
Board Moderator
Joined
Sep 29, 2009
Messages
2,920
Solutions
342
Reaction score
1,688
Location
Egypt
If many warnings appear in your console it is because you have scripts that pass invalid numbers to methods. reversing the PR is omitting our misuse of numbers.
example:
If we're trying to get a creature by ID, we have to use something like: local creature = Creature(1)
If we try to do local creature = Creature(-1) makes no sense, since an unsigned number is expected.
The same with others methods.

This is not necessarily about unsigned or signed numbers, but also about the limits of each type of number, so if a method expects int8_t, it will throw a warning if it passes a higher or much lower number.
@Sarah Wesker Sorry for the mention just wanted to continue asking about this and didn't want to do it on a semi-solved thread.
So what is the case here? I just wanted to get sure I do understand it.
Lua:
        pdump(toPosition)
        if toPosition.x == CONTAINER_POSITION then
        local containerId = toPosition.y - 64
        local container = self:getContainerById(containerId)
        if not container then
            return RETURNVALUE_NOERROR
        end

Code:
{
    ["y"] = 8,
    ["x"] = 65535,
    ["z"] = 0,
    ["stackpos"] = 0
}

Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
LuaScriptInterface::getNumber(). Argument 2 has out-of-range value for unsigned char: -56.0
stack traceback:
        [C]: in function 'getContainerById'
        data/events/scripts/player.lua:58: in function <data/events/scripts/player.lua:41>
{
    ["y"] = 9,
    ["x"] = 65535,
    ["z"] = 0,
    ["stackpos"] = 0
}

Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
LuaScriptInterface::getNumber(). Argument 2 has out-of-range value for unsigned char: -55.0
stack traceback:
        [C]: in function 'getContainerById'
        data/events/scripts/player.lua:58: in function <data/events/scripts/player.lua:41>
Is it passing the int value?
C++:
Container* container = player->getContainerByID(getNumber<uint8_t>(L, 2));
 
Solution
when trying to move to inventory we are using range 0 to 63, this range is reserved for the player's inventory.
your script is ignoring the player inventory case, it just tries to fetch non-slot from the player inventory.
local containerId = toPosition.y - 64 <-- HERE
(boots slot (8)) - 64 = -56 <- warning no is uint8_t
1658292312553.png
in this case, we are using a trick to get the slot index, however we are ignoring the results that don't work
local containerId = toPosition.y - 64

in correct case it will give us the index of the slot, but when it comes to moving the element to the ground this number will give results not expected by this method.
the way to fix it is to simply convert the number to the correct range or just do an if
uint8_t = 0 to 255
.
la posicion del mapa podria ser X:270, Y:270, Z:7
if we subtract from Y, 64 = 206 so this number is valid, this slot does not exist, however it will not give any warning since we are within the range uint8_t
at this point you can imagine the case that the subtraction is less than 0 or greater than 255.
 
Not sure if I understand this correct, I got more confused.
The first error occurred because I moved/equipped an item to (boots slot (8))
The second error occurred because I moved/equipped an item to (ring slot (9))
So both had ["y"] = lower than uint8_t range why would it give an error then? or we're talking here about X? which is 65535 in both situations?
 
Last edited:
when trying to move to inventory we are using range 0 to 63, this range is reserved for the player's inventory.
your script is ignoring the player inventory case, it just tries to fetch non-slot from the player inventory.
local containerId = toPosition.y - 64 <-- HERE
(boots slot (8)) - 64 = -56 <- warning no is uint8_t
1658292312553.png
 
Solution
Back
Top