• 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 0.X Block moveItem fromContainer to ground if player has storage

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
48
Hello, I'm using tfs 0.4 and I have this 2 functions on my source

Lua:
onMoveItem(moveItem, frompos, position, cid)
Lua:
onMoveItem2(cid, item, count, toContainer, fromContainer, fromPos, toPos)

I want to block the player from trowing the items let's 2160, 2161, 2162 (an array of items) to the ground IF he has x storageValue == 1. I found some threads where this was answered but my move function on source is different than theirs so I was trying to just print stuff like this
Lua:
function onMoveItem2(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    print("Item id: " ..item.itemid)
    print("From pos x:" ..frompos.x)
    print("From pos y:" ..frompos.y)
    print("From pos z:" ..frompos.z)
    print("To pos x:" ..toPos.x)
    print("To pos y:" ..toPos.y)
    print("To pos z:" ..toPos.z)  
    print("From Container?:" ..fromContainer)
end
just to understand what is going on but I'm stuck and I'm getting this console error
Code:
1:18:01.352] [Error - CreatureScript Interface]
[1:18:01.355] data/creaturescripts/scripts/petGround.lua:onMoveItem2
[1:18:01.360] Description:
[1:18:01.362] data/creaturescripts/scripts/petGround.lua:10: attempt to index global 'frompos' (a nil value)
[1:18:01.369] stack traceback:
[1:18:01.371]   data/creaturescripts/scripts/petGround.lua:10: in function <data/creaturescripts/scripts/petGround.lua:3
can anyone help? I have this moveItem2 code that blocks players from trowing stuff on depot so it might help to understand what's possible with the function
Lua:
local depottiles = {} --piso pra n jogar
local depots = {2591, 2589, 2590, 2592} --id dos dps
local group = 3 --id dos group 6 é todos.
  
local function checkIfThrow(pos,topos)
                    if topos.x == 0xffff then
                        return false
                    end
                local thing = getThingFromPos(pos)
                if isInArray(depottiles,thing.itemid) then
                            if not isInArea(topos,{x=pos.x-1,y=pos.y-1,z=pos.z},{x=pos.x+1,y=pos.y+1, z=pos.z}) then                   
                            return true
                        end   
                else   
                for i = 1, #depots do
                    if depots[i] == getTileItemById(topos,depots[i]).itemid or getTileInfo(topos).actionid == 7483 then
                        return true
                    end
                end
            end                               
    return false
end


function onMoveItem2(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if isPlayer(cid) then
        local pos = getThingPos(cid)
            if getPlayerGroupId(cid) > group then
                return true
        end
          
        if checkIfThrow({x=pos.x,y=pos.y,z=pos.z,stackpos=0},toPos) then
            doPlayerSendCancel(cid,"You can't throw items there.")
            doSendMagicEffect(getThingPos(cid),CONST_ME_POFF)
            return false
        end
    end
    return true
end
 
Solution
maybe this help you
movements.xml
Lua:
<movevent type="AddItem" tileitem="1" actionid="xxxxx" event="script" value="bpantitrash.lua"/>
lua
Code:
function onAddItem(moveItem, tileItem, position, cid)
local blockeditem = {2591, 2589, 2590, 2592}
    if table.contains(blockeditem,moveItem.itemid) then
    doRemoveItem(moveItem.uid)
    doPlayerSendTextMessage(cid,22,"You're not allowed to throw this item here. The item has been removed.")
    end
    return true
end
yeah it's just that I don't know how to compare if the players it trying to move topos == ground and to check if the item being moved is in the array
 
Oh sorry I had misunderstood what you said, it prints everything but the container so that's probably wrong. from pos x shows that it is from my inventory, y is the slot id (right hand) z shows 0 and toPos are xyz coordinates like in rme
Code:
Item id: 12469
From pos x:65535
From pos y:5
From pos z:0
To pos x:163
To pos y:54
To pos z:7

[2:37:00.327] [Error - CreatureScript Interface]
[2:37:00.330] data/creaturescripts/scripts/petGround.lua:onMoveItem2
[2:37:00.333] Description:
[2:37:00.334] data/creaturescripts/scripts/petGround.lua:11: attempt to concatenate local 'fromContainer' (a table value)
[2:37:00.344] stack traceback:
[2:37:00.352]   data/creaturescripts/scripts/petGround.lua:11: in function <data/creaturescripts/scripts/petGround.lua:3>

so it would have to be like if fromPos == 65535 to any toPos that is not inventory == false, but how do I code that any toPos? also, would help to know how to print this fromContainer
 
Last edited:
maybe this help you
movements.xml
Lua:
<movevent type="AddItem" tileitem="1" actionid="xxxxx" event="script" value="bpantitrash.lua"/>
lua
Code:
function onAddItem(moveItem, tileItem, position, cid)
local blockeditem = {2591, 2589, 2590, 2592}
    if table.contains(blockeditem,moveItem.itemid) then
    doRemoveItem(moveItem.uid)
    doPlayerSendTextMessage(cid,22,"You're not allowed to throw this item here. The item has been removed.")
    end
    return true
end
 
Solution
Back
Top