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

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Printer, Oct 6, 2015.

  1. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    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: Oct 7, 2015
    Glombers, primate, kito2 and 9 others like this.
  2. Scrappy Coco

    Scrappy Coco Member

    Joined:
    Dec 27, 2014
    Messages:
    95
    great job This is useful. :D
     
  3. osiann

    osiann Member

    Joined:
    Jul 28, 2011
    Messages:
    39
    please tfs 1.0
     
  4. silveralol

    silveralol Well-Known Member

    Joined:
    Mar 16, 2010
    Messages:
    1,227
  5. Athenuz

    Athenuz Owlz!

    Joined:
    Oct 1, 2015
    Messages:
    234
    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: Oct 7, 2015
  6. Amiroslo

    Amiroslo Well-Known Member

    Joined:
    Jul 28, 2009
    Messages:
    6,378
    Sounds nice, possible to convert it to 0.4? :p
     
  7. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    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.
     
  8. SN4KY

    SN4KY Member

    Joined:
    Mar 19, 2015
    Messages:
    37
    this will work if you try to equip items?
     
  9. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    You cannot move the items, if you are not a sub-owner("aleta som") off the house. So no you cannot equip!
     
    SN4KY likes this.
  10. Cornex

    Cornex Web Developer Staff Member Global Moderator

    Joined:
    Jun 15, 2008
    Messages:
    3,408
    Nice release as always from you. Great work and thanks for sharing :)
     
  11. Athenuz

    Athenuz Owlz!

    Joined:
    Oct 1, 2015
    Messages:
    234
    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
     
  12. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,556
    Ups recopy the code, only aleta som person should be able to move items.
     
  13. Zakeen

    Zakeen Member

    Joined:
    Sep 27, 2015
    Messages:
    90
    Great work man, really.
     
  14. Athenuz

    Athenuz Owlz!

    Joined:
    Oct 1, 2015
    Messages:
    234
    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: Oct 7, 2015
  15. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    @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?
     
  16. Ahilphino

    Ahilphino Well-Known Member

    Joined:
    Jun 5, 2013
    Messages:
    1,146
    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
     
    imkingran likes this.
  17. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    @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! :)
     
  18. Ahilphino

    Ahilphino Well-Known Member

    Joined:
    Jun 5, 2013
    Messages:
    1,146
    =)
    the events folder is rly amazing

    but yeah you will need to make a few adjustments since browsefield has other values
     
  19. imkingran

    imkingran Learning everyday. Premium User

    Joined:
    Jan 15, 2014
    Messages:
    1,151
    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.
     
  20. Cys9211

    Cys9211 Sencor!

    Joined:
    Aug 21, 2008
    Messages:
    72
    tfs 0.4? r3884?
     

Share This Page