Advertisement
Guest User

dropbloot

a guest
Aug 27th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. local function playerDeathInfo(info)
  2. local file = io.open("data/logs/itemdrop.txt", "a")
  3. if not file then
  4. return true
  5. end
  6.  
  7. io.output(file)
  8. io.write(info)
  9. io.close(file)
  10. end
  11.  
  12. function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
  13. if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
  14. return true
  15. end
  16.  
  17. local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
  18. local amulets = {ITEM_AMULETOFLOSS, 2131, 18407, 18402}
  19. if amulet and isInArray(amulets, amulet.itemid) and not isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
  20. local isPlayer = false
  21. if killer then
  22. if killer:isPlayer() then
  23. isPlayer = true
  24. else
  25. local master = killer:getMaster()
  26. if master and master:isPlayer() then
  27. isPlayer = true
  28. end
  29. end
  30. end
  31. if amulet.itemid == ITEM_AMULETOFLOSS then
  32. if not isPlayer or not player:hasBlessing(6) then
  33. player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
  34. end
  35. end
  36. else
  37. local lossPercent = player:getLossPercent()
  38. playerDeathInfo(string.format("Player Name: %s, Skull Type: %d, Blessings: %d, Loss Percent: %d.\n", player:getName(), player:getSkull(), player:getBlessings(), lossPercent))
  39. for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
  40. local item = player:getSlotItem(i)
  41. if item then
  42. if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
  43. if not item:moveTo(corpse) then
  44. item:remove()
  45. end
  46. end
  47. end
  48. end
  49. end
  50.  
  51. if not player:getSlotItem(CONST_SLOT_BACKPACK) then
  52. player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
  53. end
  54.  
  55. return true
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement