[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,592
    Likes Received:
    1,872
    Best Answers:
    5
    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 (Text):
    1. <event class="Player" method="onMoveItem" enabled="1" />
    Then go into events/scripts/player.lua and paste this under the function:
    Code (Text):
    1. function Player:onMoveItem(item, count, fromPosition, toPosition)
    Code (Text):
    1.         local antiTrash = true
    2.         local antiTheft = true
    3.  
    4.         if antiTrash then
    5.             local tile = Tile(toPosition)
    6.             if tile and tile:hasFlag(TILESTATE_HOUSE) then
    7.                 local house = tile:getHouse()
    8.                 if house then
    9.                     local accessList = House.getAccessList
    10.                     local playerName = self:getName():lower()
    11.  
    12.                     if house ~= self:getHouse() and (playerName ~= accessList(house, GUEST_LIST):lower() or playerName ~= accessList(house, SUBOWNER_LIST):lower()) then
    13.                         self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot throw items into players houses, which you are not invited to.")
    14.                         return false
    15.                     end
    16.                 end
    17.             end
    18.         end
    19.  
    20.         if antiTheft then
    21.             local tile = Tile(fromPosition)
    22.             if tile and tile:hasFlag(TILESTATE_HOUSE) then
    23.                 local house = tile:getHouse()
    24.                 if house then
    25.                     if house ~= self:getHouse() and self:getName():lower() ~= house:getAccessList(SUBOWNER_LIST):lower() then
    26.                         self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot move items from house, which you are only guest to.")
    27.                         return false
    28.                     end
    29.                 end
    30.             end
    31.         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
    Likes Received:
    12
    Best Answers:
    0
    great job This is useful. :D
     
  3. osiann

    osiann Member

    Joined:
    Jul 28, 2011
    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    please tfs 1.0
     
  4. silveralol

    silveralol Well-Known Member

    Joined:
    Mar 16, 2010
    Messages:
    1,299
    Likes Received:
    151
    Best Answers:
    3
  5. Athenuz

    Athenuz Owlz!

    Joined:
    Oct 1, 2015
    Messages:
    234
    Likes Received:
    27
    Best Answers:
    0
    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 http://opentibia.net

    Joined:
    Jul 28, 2009
    Messages:
    6,464
    Likes Received:
    441
    Best Answers:
    3
    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,592
    Likes Received:
    1,872
    Best Answers:
    5
    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:
    52
    Likes Received:
    11
    Best Answers:
    0
    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,592
    Likes Received:
    1,872
    Best Answers:
    5
    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 Premium User

    Joined:
    Jun 15, 2008
    Messages:
    3,427
    Likes Received:
    1,110
    Best Answers:
    5
    Nice release as always from you. Great work and thanks for sharing :)
     
  11. Athenuz

    Athenuz Owlz!

    Joined:
    Oct 1, 2015
    Messages:
    234
    Likes Received:
    27
    Best Answers:
    0
    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,592
    Likes Received:
    1,872
    Best Answers:
    5
    Ups recopy the code, only aleta som person should be able to move items.
     
  13. Zakeen

    Zakeen Member

    Joined:
    Sep 27, 2015
    Messages:
    90
    Likes Received:
    29
    Best Answers:
    0
    Great work man, really.
     
  14. Athenuz

    Athenuz Owlz!

    Joined:
    Oct 1, 2015
    Messages:
    234
    Likes Received:
    27
    Best Answers:
    0
    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,194
    Likes Received:
    358
    Best Answers:
    5
    @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,149
    Likes Received:
    339
    Best Answers:
    0
    can't you just copy
    Code (Text):
    1.  
    2. local antiTrash = true
    3. local antiTheft = true
    4.  
    5. if antiTrash then
    6. local tile = Tile(toPosition)
    7. if tile and tile:hasFlag(TILESTATE_HOUSE) then
    8. local house = tile:getHouse()
    9. if house then
    10. local accessList = House.getAccessList
    11. local playerName = self:getName():lower()
    12.  
    13. if house ~= self:getHouse() and (playerName ~= accessList(house, GUEST_LIST):lower() or playerName ~= accessList(house, SUBOWNER_LIST):lower()) then
    14. self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot throw items into players houses, which you are not invited to.")
    15. return false
    16. end
    17. end
    18. end
    19. end
    20.  
    21. if antiTheft then
    22. local tile = Tile(fromPosition)
    23. if tile and tile:hasFlag(TILESTATE_HOUSE) then
    24. local house = tile:getHouse()
    25. if house then
    26. if house ~= self:getHouse() and self:getName():lower() ~= house:getAccessList(SUBOWNER_LIST):lower() then
    27. self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot move items from house, which you are only guest to.")
    28. return false
    29. end
    30. end
    31. end
    32. 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,194
    Likes Received:
    358
    Best Answers:
    5
    @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,149
    Likes Received:
    339
    Best Answers:
    0
    =)
    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,194
    Likes Received:
    358
    Best Answers:
    5
    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 (Text):
    1. if house ~= self:getHouse() and self:getName():lower() ~= house:getAccessList(SUBOWNER_LIST):lower() then
    with:
    Code (Text):
    1. 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
    Likes Received:
    3
    Best Answers:
    0
    tfs 0.4? r3884?
     

Share This Page

Loading...