• 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+ TFS 1.2 Anti-trash house system.

ots49

Member
Joined
Jun 7, 2022
Messages
61
Reaction score
17
Hello people.
I am using This version of tfs 1.2 and I've been trying all the anti-trash house systems but nothing seems to be working.
When I use This script I cannot move items at all. Not in bp or eq even when I am outside the house. It just freezez every item in place.

So I was wondering if anyone can guide me if there is a possible way to fix this in the sources or if you might know what the issue might be? I don't care much for the antiTheft system. I just want to make antiTrash to work. I Tried inactivating the antitheft part of the script I posted but it's the same symptom.

Thankful for any help I can get.
 
Solution
I thought you had more things in the method so I asked you to show me, but I just noticed that you have everything empty, so just pasting the code like this should work:

Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    local toTile = Tile(toPosition)
    if toTile then
        local house = toTile:getHouse()
        if house then
            if house:getOwnerGuid() ~= self:getGuid() then
                if not isInArray(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), self:getName()) then
                    self:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                    return false
                end
            end
        end
    end

    local...
I don't know if it's the best way to do it or if it's the right one, but here's an example:

Lua:
local toTile = Tile(toPosition)
if toTile then
    local house = toTile:getHouse()
    if house then
        if house:getOwnerGuid() ~= player:getGuid() then
            local playerName = player:getName()
            if not table.contains(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not table.contains(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                return false
            end
        end
    end
end
 
I don't know if it's the best way to do it or if it's the right one, but here's an example:

Lua:
local toTile = Tile(toPosition)
if toTile then
    local house = toTile:getHouse()
    if house then
        if house:getOwnerGuid() ~= player:getGuid() then
            local playerName = player:getName()
            if not table.contains(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not table.contains(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                return false
            end
        end
    end
end

Same thing can't move items at all.

also getting this error when I try to throw something in a house:
Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
data/events/scripts/player.lua:89: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:89: in function <data/events/scripts/player.lua:84>

Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition)
local toTile = Tile(toPosition)
if toTile then
    local house = toTile:getHouse()
    if house then
        if house:getOwnerGuid() ~= player:getGuid() then
            local playerName = player:getName()
            if not table.contains(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not table.contains(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                return false
            end
        end
    end
end

I tried this too and the error went away but still can't move items in eq field or anytimes at all outside house:
Lua:
function Player:onMoveItem(player, item, count, fromPosition, toPosition)
local toTile = Tile(toPosition)
if toTile then
    local house = toTile:getHouse()
    if house then
        if house:getOwnerGuid() ~= player:getGuid() then
            local playerName = player:getName()
            if not table.contains(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not table.contains(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                return false
            end
        end
    end
end
 
try this:
Lua:
function Player.onMoveItem(player, item, count, fromPosition, toPosition)
local toTile = Tile(toPosition)
if toTile then
    local house = toTile:getHouse()
    if house then
        if house:getOwnerGuid() ~= player:getGuid() then
            local playerName = player:getName()
            if not table.contains(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not table.contains(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                return false
            end
        end
    end
end
 
try this:
Lua:
function Player.onMoveItem(player, item, count, fromPosition, toPosition)
local toTile = Tile(toPosition)
if toTile then
    local house = toTile:getHouse()
    if house then
        if house:getOwnerGuid() ~= player:getGuid() then
            local playerName = player:getName()
            if not table.contains(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not table.contains(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                return false
            end
        end
    end
end
Same issue, can't move anything anywhere 😭
 
Maybe you should post the full onItemMove function so I can help you insert my code
Sorry for being a noob. Where can I find this full function?

This is my player.lua in events before adding this script
Lua:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:isPlayer() and thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInBattleList(creature, distance)
    local description = "You see " .. creature:getDescription(distance)
    if self:getGroup():getAccess() then
        local str = "%s\nHealth: %d / %d"
        if creature:getMaxMana() > 0 then
            str = string.format("%s, Mana: %d / %d", str, creature:getMana(), creature:getMaxMana())
        end
        description = string.format(str, description, creature:getHealth(), creature:getMaxHealth()) .. "."

        local position = creature:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if creature:isPlayer() then
            description = string.format("%s\nIP: %s", description, Game.convertIpToString(creature:getIp()))
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInTrade(partner, item, distance)
    self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))
end

function Player:onLookInShop(itemType, count)
    return true
end

function Player:onMoveItem(item, count, fromPosition, toPosition)
    return true
end

function Player:onMoveCreature(creature, fromPosition, toPosition)
    return true
end

function Player:onTurn(direction)
    if self:getGroup():getAccess() and self:getDirection() == direction then
        local nextPosition = self:getPosition()
        nextPosition:getNextPosition(direction)

        self:teleportTo(nextPosition, true)
    end

    return true
end

function Player:onTradeRequest(target, item)
    return true
end

function Player:onTradeAccept(target, item, targetItem)
    return true
end

local soulCondition = Condition(CONDITION_SOUL, CONDITIONID_DEFAULT)
soulCondition:setTicks(4 * 60 * 1000)
soulCondition:setParameter(CONDITION_PARAM_SOULGAIN, 1)

local function useStamina(player)
    local staminaMinutes = player:getStamina()
    if staminaMinutes == 0 then
        return
    end

    local playerId = player:getId()
    local currentTime = os.time()
    local timePassed = currentTime - nextUseStaminaTime[playerId]
    if timePassed <= 0 then
        return
    end

    if timePassed > 60 then
        if staminaMinutes > 2 then
            staminaMinutes = staminaMinutes - 2
        else
            staminaMinutes = 0
        end
        nextUseStaminaTime[playerId] = currentTime + 120
    else
        staminaMinutes = staminaMinutes - 1
        nextUseStaminaTime[playerId] = currentTime + 60
    end
    player:setStamina(staminaMinutes)
end

function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    -- Soul regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())

    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 3240 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end

    return exp
end

function Player:onLoseExperience(exp)
    return exp
end

function Player:onGainSkillTries(skill, tries)
    if APPLY_SKILL_MULTIPLIER == false then
        return tries
    end

    if skill == SKILL_MAGLEVEL then
        return tries * configManager.getNumber(configKeys.RATE_MAGIC)
    end
    return tries * configManager.getNumber(configKeys.RATE_SKILL)
end
 
I thought you had more things in the method so I asked you to show me, but I just noticed that you have everything empty, so just pasting the code like this should work:

Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    local toTile = Tile(toPosition)
    if toTile then
        local house = toTile:getHouse()
        if house then
            if house:getOwnerGuid() ~= self:getGuid() then
                if not isInArray(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), self:getName()) then
                    self:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                    return false
                end
            end
        end
    end

    local fromTile = Tile(fromPosition)
    if fromTile then
        local house = fromTile:getHouse()
        if house then
            if house:getOwnerGuid() ~= self:getGuid() then
                if not isInArray(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), self:getName()) then
                    self:sendCancelMessage("You cannot move items from house, which you are only guest to.")
                    return false
                end
            end
        end
    end
    return true
end

Don't forget to activate the method in data/events/events.xml
XML:
<event class="Player" method="onMoveItem" enabled="1" />

If you get any errors regarding splitTrimmed then add this to the end of the file data/global.lua
Lua:
string.splitTrimmed = function (str, sep)
    local res = {}
    for v in str:gmatch("([^" .. sep .. "]+)") do
        res[#res + 1] = v:trim()
    end
    return res
end
 
Last edited:
Solution
I thought you had more things in the method so I asked you to show me, but I just noticed that you have everything empty, so just pasting the code like this should work:

Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    local toTile = Tile(toPosition)
    if toTile then
        local house = toTile:getHouse()
        if house then
            if house:getOwnerGuid() ~= self:getGuid() then
                local playerName = self:getName()
                if not isInArray(house:getAccessList(GUEST_LIST):splitTrimmed("\n"), playerName) and not isInArray(house:getAccessList(SUBOWNER_LIST):splitTrimmed("\n"), playerName) then
                    player:sendCancelMessage("You cannot throw items into players houses, which you are not invited to.")
                    return false
                end
            end
        end
    end
    return true
end

Don't forget to activate the method in data/events/events.xml
XML:
<event class="Player" method="onMoveItem" enabled="1" />

If you get any errors regarding splitTrimmed then add this to the end of the file data/global.lua
Lua:
string.splitTrimmed = function (str, sep)
    local res = {}
    for v in str:gmatch("([^" .. sep .. "]+)") do
        res[#res + 1] = v:trim()
    end
    return res
end
The anti trash is now functional however
If a player is invited or even subowner to the house and picks something up inside the house they can't put it back down in the house (also they can't move stuff around in the house) haha :<


The only error I am getting is again which seems to be linked to the player:sendCancelMessage function. <- EDIT: fixed error below by changing
Lua:
player:sendCancelMessage
to
Lua:
self:sendCancelMessage
Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
data/events/scripts/player.lua:92: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:92: in function <data/events/scripts/player.lua:84>

We are getting close atleast. I appreciate you helping me alot!
 
Last edited:
You are amazing!!! thank you so much!

Just one last thing. Is it possible to make it so only sub owners of the house can pick up and move stuff around in the house? :D
Sorry to bother your more than I have already done!
Of course yes, I already did it, check the code again.
a pleasure to help you.
 
Of course yes, I already did it, check the code again.
a pleasure to help you.
Yes indeed you did. I'm just blind LOL.

I found the issue:
For future refrence if anyone reads this and subowner of the house is not able to shuffle around in the house:
Sub owner list is case sensitive!
Ex:
testname <-- wont work
Testname <-- will work

Once again super thanks, much appreciated @Sarah Wesker
 
Back
Top