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

[EVENT] antiTrash - antiTheft system for houses [TFS 1.x]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
Hello,

Well it been a while when i released scripts, so i made this to my server and i thougt about share it aswell. So other could get use of this system. It is self explanatory, meaning that people who is not invited to the house cannot trash the house or people who is just a guest into the house cannot move items.

Go into events/events.xml and enable, by change the 0 to 1:
Code:
<event class="Player" method="onMoveItem" enabled="1" />

Then go into events/scripts/player.lua and paste this under the function:
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)

Code:
        local antiTrash = true
        local antiTheft = true

        if antiTrash then
            local tile = Tile(toPosition)
            if tile and tile:hasFlag(TILESTATE_HOUSE) then
                local house = tile:getHouse()
                if house then
                    local accessList = House.getAccessList
                    local playerName = self:getName():lower()

                    if house ~= self:getHouse() and (playerName ~= accessList(house, GUEST_LIST):lower() or playerName ~= accessList(house, SUBOWNER_LIST):lower()) then
                        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot throw items into players houses, which you are not invited to.")
                        return false
                    end
                end
            end
        end

        if antiTheft then
            local tile = Tile(fromPosition)
            if tile and tile:hasFlag(TILESTATE_HOUSE) then
                local house = tile:getHouse()
                if house then
                    if house ~= self:getHouse() and self:getName():lower() ~= house:getAccessList(SUBOWNER_LIST):lower() then
                        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot move items from house, which you are only guest to.")
                        return false
                    end
                end
            end
        end

Enjoy!
 
Last edited:
Awesome job, thank you sir!

Edit:

Sorry Sir, i tested it and works 50%... (Using last commit of TFS at GitHub)

As we understand..
Guest: Aleta Sio
Sub-Owner: Aleta Som

I invited a secondary account as Guest and tried to move the items (Yes, i can't move them) But i can move into my equipment slots, but the error message is the one of the anti-trash, if i set antitrash to false and try to only use anti-theft, doesn't works :(

Did i something wrong or this is not able for TFS 1.X of the last commit?

Regards
 
Last edited:
Sounds nice, possible to convert it to 0.4? :p
 
Awesome job, thank you sir!

Edit:

Sorry Sir, i tested it and works 50%... (Using last commit of TFS at GitHub)

As we understand..
Guest: Aleta Sio
Sub-Owner: Aleta Som

I invited a secondary account as Guest and tried to move the items (Yes, i can't move them) But i can move into my equipment slots, but the error message is the one of the anti-trash, if i set antitrash to false and try to only use anti-theft, doesn't works :(

Did i something wrong or this is not able for TFS 1.X of the last commit?

Regards
Either you are installing it wrong or you have the guy invited. For me it works perfectly.

Sounds nice, possible to convert it to 0.4? :p
No idea what functions tfs 0.4 got.
 
You cannot move the items, if you are not a sub-owner("aleta som") off the house. So no you cannot equip!
 
Nice release as always from you. Great work and thanks for sharing :)
 
Either you are installing it wrong or you have the guy invited. For me it works perfectly.


No idea what functions tfs 0.4 got.

Oh wait... Now im confused.

So, if i invite anybody, even if its by "aleta sio" as guest, he can take the items? Or he should not be able to?

I'll try to install again, but my first try, i invited other char as guest with "aleta sio" and he can pickup the items...

Thanks for your reply Printer ^^
I like a lot your scripts
 
Oh wait... Now im confused.

So, if i invite anybody, even if its by "aleta sio" as guest, he can take the items? Or he should not be able to?

I'll try to install again, but my first try, i invited other char as guest with "aleta sio" and he can pickup the items...

Thanks for your reply Printer ^^
I like a lot your scripts
Ups recopy the code, only aleta som person should be able to move items.
 
Ups recopy the code, only aleta som person should be able to move items.

Thanks, I'll test right now ^^


Edit:

Now it works perfect!

Since TFS 1.x already have an anti-trash system for houses and non-invited players can't throw items to houses, i've set it to "false"

Thank you so much for this release :D
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This also works for GM, CM or GOD Characters, making it safer to prevent item stealing from house if you've set that charge to someone else :D
 
Last edited:
@Printer
With browse field every function in the script is dismissed and the player is able to move the item.

I'm using TFS 1.1 though, is it different on TFS 1.2?
 
can't you just copy
Code:
local antiTrash = true
local antiTheft = true

if antiTrash then
local tile = Tile(toPosition)
if tile and tile:hasFlag(TILESTATE_HOUSE) then
local house = tile:getHouse()
if house then
local accessList = House.getAccessList
local playerName = self:getName():lower()

if house ~= self:getHouse() and (playerName ~= accessList(house, GUEST_LIST):lower() or playerName ~= accessList(house, SUBOWNER_LIST):lower()) then
self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot throw items into players houses, which you are not invited to.")
return false
end
end
end
end

if antiTheft then
local tile = Tile(fromPosition)
if tile and tile:hasFlag(TILESTATE_HOUSE) then
local house = tile:getHouse()
if house then
if house ~= self:getHouse() and self:getName():lower() ~= house:getAccessList(SUBOWNER_LIST):lower() then
self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot move items from house, which you are only guest to.")
return false
end
end
end
end
under onBrowseField in player.lua too?

obv might require some changes since onmove and onbrowse doesn't have all the same values i think but you should be able to get it to work
 
@Ahilphino

Wow, I didn't even realize that onBrowseField was a player event. Thanks! :oops:

I guess he can add that to the first page too! :)
 
=)
the events folder is rly amazing

but yeah you will need to make a few adjustments since browsefield has other values
 
I was also having trouble with a list with multiple names:
For me it was only working with one player on the list and that's because if you print(#accessList) you'll receive the number of characters/spaces in each name.

For examples the 2 names below are on the accessList --> #accessList = 22
jack in the box
godric

To fix that I replaced this line and used string.find:
Code:
if house ~= self:getHouse() and self:getName():lower() ~= house:getAccessList(SUBOWNER_LIST):lower() then

with:
Code:
if (house ~= self:getHouse() and not string.find(house:getAccessList(SUBOWNER_LIST):lower(), self:getName():lower())) then

You'll have to replace the other line that performs the same function.
 
Back
Top