Advertisement
Rochet2

NotHawthorne

Nov 18th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.81 KB | None | 0 0
  1. --Full Loot On Death Script by NotHawthorne of ModCraft/EmuDevs--
  2. local AIO = require("AIO")
  3.  
  4. --DEFINE VARS
  5. local leveldiff = 5         --Amount of levels higher someone can be than the person they're killing and still recieve an HK
  6. local decaytime = 300       --Time in seconds it takes for belongings to decay
  7. local creaturedeath = true  --Enable inventory dropping on creature death?
  8. local playerdeath = true    --Enable inventory dropping on player death?
  9. local ContainerID = 818001
  10. local maxitems = 25 --Equal to amount of buttons that I have declared.
  11.  
  12. local guid_linking_table = {}
  13. local item_table = {}
  14.  
  15. --DEFINE LOOT FRAME
  16. local FullLootFrame = AIO:CreateFrame("Frame", "FullLootFrame", "UIParent", nil)
  17. FullLootFrame:SetSize(350, 500)
  18. FullLootFrame:SetMovable(true)
  19. FullLootFrame:SetEnabledMouse(true)
  20. FullLootFrame:RegisterForDrag("LeftButton")
  21. FullLootFrame:SetPoint("BOTTOMRIGHT", -270, 60)
  22. FullLootFrame:SetToplevel(true)
  23. FullLootFrame:SetClampedToScreen(true)
  24. FullLootFrame:SetBackdrop({
  25.     bgFile = "Interface/DialogFrame/UI-DialogBox-Background-Dark",
  26.     edgeFile = "Interface/DialogFrame/UI-DialogBox-Gold-Border",
  27.     edgeSize = 20,
  28.     --tile = true,
  29.     --tilesize = 256,
  30.     insets = { left = 5, right = 5, top = 5, bottom = 5 }
  31. })
  32. FullLootFrame:SetScript("OnDragStart", "StartMoving")
  33. FullLootFrame:SetScript("OnHide", "StopMovingOrSizing")
  34. FullLootFrame:SetScript("OnDragStop", "StopMovingOrSizing")
  35. FullLootFrame:Hide()
  36.  
  37. local FullLootFrame_TitleBar = AIO:CreateFrame("Frame", "FullLootFrame_TitleBar", FullLootFrame, nil)
  38. FullLootFrame_TitleBar:SetSize(255, 25)
  39. FullLootFrame_TitleBar:SetPoint("TOP", 0, 9)
  40. FullLootFrame_TitleBar:SetBackdrop({
  41.     bgFile = "Interface/CHARACTERFRAME/UI-Party-Background",
  42.     edgeFile = "Interface/DialogFrame/UI-DialogBox-Border",
  43.     tile = true,
  44.     edgeSize = 16,
  45.     tileSize = 16,
  46.     insets = { left = 5, right = 5, top = 5, bottom = 5 }
  47. })
  48.  
  49. local FullLootFrame_TitleText = FullLootFrame_TitleBar:CreateFontString("FullLootFrame_TitleText")
  50. FullLootFrame_TitleText:SetFont("Fonts\\FRIZQT__.TTF", 13)
  51. FullLootFrame_TitleText:SetSize(190, 5)
  52. FullLootFrame_TitleText:SetPoint("CENTER", 0, 0)
  53.  
  54. local FullLootFrame_CloseButton = AIO:CreateFrame("Button", "FullLootFrame_CloseButton", FullLootFrame, "UIPanelCloseButton")
  55. FullLootFrame_CloseButton:SetPoint("TOPRIGHT", -5, -5)
  56. FullLootFrame_CloseButton:SetEnabledMouse(true)
  57. FullLootFrame_CloseButton:SetSize(27, 27)
  58.  
  59. local FullLoot_ButtonTable = {}
  60. local FullLoot_TextTable = {}
  61.  
  62. local function AddItem(player, Event, EventParamsTable, ClientFuncRet)
  63.     local lootindex = ClientFuncRet[1]
  64.     local lootguid = ClientFuncRet[2]
  65.     if(type(lootindex) ~= "number") then
  66.         return
  67.     end
  68.     if(type(lootguid) ~= "number") then
  69.         return
  70.     end
  71.    
  72.     if(not item_table[lootguid]) then
  73.         return
  74.     end
  75.     local item = item_table[lootguid][lootindex]
  76.     if(not item) then
  77.         return
  78.     end
  79.    
  80.     table.remove(item_table[lootguid], lootindex)
  81.    
  82.     player:AddItem(v[2], v[3])
  83.     player:SendBroadcastMessage("You got a "..item[1])
  84. end
  85. for i = 1, maxitems do
  86.     local OnHoverTooltip = [[
  87.         local button = select(1, ...)
  88.         if not button.itemlink then
  89.             return
  90.         end
  91.         GameTooltip:SetOwner(button, "ANCHOR_RIGHT")
  92.         GameTooltip:SetHyperlink(button.itemlink)
  93.         GameTooltip:Show()
  94.     ]]
  95.     local button = AIO:CreateFrame("Button", "FullLoot_Button"..i, FullLootFrame, nil)
  96.     button:SetSize(200, 13)
  97.     button:SetPoint("TOPLEFT", 25, (-10-(i*15)))
  98.     button:SetEnabledMouse(true)
  99.     button:SetHighlightTexture("Interface/Buttons/UI-Listbox-Highlight")
  100.     button:SetPushedTexture("Interface/Buttons/CheckButtonHilight")
  101.     button:SetScript("OnLeave", AIO:ToFunction("GameTooltip:Hide()"))
  102.     button:SetScript("OnEnter", AIO:ToFunction(OnHoverTooltip))
  103.     button:SetScript("OnMouseUp", AddItem, AIO:ObjDo(button, ".lootindex", button, ".lootguid", "GameTooltip", ":Hide()", button, "SetText('|cff9d9d9dLooted Item|r')"))
  104.    
  105.     local text = button:CreateFontString("FullLoot_Text"..i)
  106.     text:SetFont("Fonts\\FRIZQT__.TTF", 11)
  107.     text:SetSize(200, 5)
  108.     text:SetPoint("CENTER", 0, 0)
  109.     text:SetJustifyH("LEFT")
  110.    
  111.     table.insert(FullLoot_ButtonTable, button)
  112.     table.insert(FullLoot_TextTable, text)
  113. end
  114.  
  115. --Function that removes bag from world.
  116. local function Remove_FullLootContainer(event, delay, call, object)
  117.     guid_linking_table[object:GetGUIDLow()] = nil
  118.     item_table[object:GetGUIDLow()] = nil
  119.    
  120.     FullLootFrame:Clear()
  121.     FullLootFrame:Hide()
  122.     local hidemsg = AIO:CreateMsg()
  123.     hidemsg:Append(FullLootFrame)
  124.     FullLootFrame:Clear()
  125.    
  126.     local nearbyplayers = object:GetPlayersInRange(100)
  127.     for k, v in ipairs(nearbyplayers) do
  128.         v:SendBroadcastMessage("|CFFFF8040The sack of items turns to dust, and blows away with the wind.|r")
  129.         hidemsg:Send(v)
  130.     end
  131.    
  132.     object:Despawn(1)
  133.     object:RemoveFromWorld(false)
  134. end
  135.  
  136. local function EntropyPvP(event, pKiller, pKilled)
  137.     if (not playerdeath) then
  138.         return
  139.     end
  140.    
  141.     local pKilledGUID = pKilled:GetGUIDLow()
  142.     local pKillerGUID = pKiller:GetGUIDLow()
  143.    
  144.     -- Dont trigger on self kill
  145.     if(pKilledGUID == pKillerGUID) then
  146.         return
  147.     end
  148.    
  149.     --Fetch Guild Names
  150.     local killerguild_name
  151.     if (pKiller:GetGuildName()~=nil) then
  152.         killerguild_name = " of "..pKiller:GetGuildName()
  153.     else
  154.         killerguild_name = ", a Lone Wolf"
  155.     end
  156.     local killedguild_name
  157.     if (pKilled:GetGuildName()~=nil) then
  158.         killedguild_name = " of"..killedguild:GetName()
  159.     else
  160.         killedguild_name = ", a Lone Wolf"
  161.     end
  162.  
  163.     --Class color codes (Killed)
  164.     local killed_color = 0
  165.     if (pKilled:GetClass()==1) then killed_color = "C79C6E"
  166.     elseif (pKilled:GetClass()==2) then killed_color = "F58CBA"
  167.     elseif (pKilled:GetClass()==3) then killed_color = "ABD473"
  168.     elseif (pKilled:GetClass()==4) then killed_color = "FFF569"
  169.     elseif (pKilled:GetClass()==5) then killed_color = "FFFFFF"
  170.     elseif (pKilled:GetClass()==6) then killed_color = "C41F3B"
  171.     elseif (pKilled:GetClass()==7) then killed_color = "0070DE"
  172.     elseif (pKilled:GetClass()==8) then killed_color = "69CCF0"
  173.     elseif (pKilled:GetClass()==9) then killed_color = "9482C9"
  174.     elseif (pKilled:GetClass()==11) then killed_color = "FF7D0A"
  175.     elseif (pKilled:GetClass()==12) then killed_color = "EB2FDE"
  176.     end
  177.  
  178.     --Class color codes (Killer)
  179.     local killer_color = 0
  180.     if (pKiller:GetClass()==1) then killer_color = "C79C6E"
  181.     elseif (pKiller:GetClass()==2) then killer_color = "F58CBA"
  182.     elseif (pKiller:GetClass()==3) then killer_color = "ABD473"
  183.     elseif (pKiller:GetClass()==4) then killer_color = "FFF569"
  184.     elseif (pKiller:GetClass()==5) then killer_color = "FFFFFF"
  185.     elseif (pKiller:GetClass()==6) then killer_color = "C41F3B"
  186.     elseif (pKiller:GetClass()==7) then killer_color = "0070DE"
  187.     elseif (pKiller:GetClass()==8) then killer_color = "69CCF0"
  188.     elseif (pKiller:GetClass()==9) then killer_color = "9482C9"
  189.     elseif (pKiller:GetClass()==11) then killer_color = "FF7D0A"
  190.     elseif (pKiller:GetClass()==12) then killer_color = "EB2FDE"
  191.     end
  192.  
  193.     --Fetch PvP Stats
  194.     local killerstats = CharDBQuery("SELECT honorable_kills,dishonorable_kills FROM shard_pvp_stats WHERE playerguid="..pKillerGUID)
  195.     if (math.abs(pKiller:GetLevel() - pKilled:GetLevel()) <= leveldiff) then
  196.         local x,y,z,o = pKilled:GetLocation()
  197.         local FullLootContainer = pKiller:SummonGameObject(ContainerID, x, y, z, 2.5, 0)            --Spawn a Sack of Belongings
  198.         FullLootContainer:RegisterEvent(Remove_FullLootContainer, decaytime*1000, 1)                --Register the Remove/Despawn event to the Sack of Belongings
  199.         guid_linking_table[FullLootContainer:GetGUIDLow()] = pKilled:GetName()
  200.        
  201.         --Get Items
  202.         item_table[FullLootContainer:GetGUIDLow()] = {}
  203.         local items = item_table[FullLootContainer:GetGUIDLow()]
  204.         for i = 0, 38 do
  205.             local checkitem = pKilled:GetItemByPos(255, i)
  206.             if (checkitem) then
  207.                 local entry = checkitem:GetEntry()
  208.                 if (not checkitem:IsBag() and entry ~= 6948) then
  209.                     table.insert(items, {GetItemLink(checkitem), entry, checkitem:GetCount(), pKilled:GetName()})
  210.                     --pKilled:RemoveItem(entry, checkitem:GetCount())
  211.                     if (#items >= maxitems) then
  212.                         break
  213.                     end
  214.                 end
  215.             end
  216.         end
  217.        
  218.         --Kill Announcer
  219.         local kill_message = math.random(1,6)
  220.         if (kill_message==1) then
  221.             SendWorldMessage("[PvP]: |CFF"..killed_color..pKilled:GetName().."|r"..killedguild_name..", got rekt by |CFF"..killer_color..pKiller:GetName().."|r"..killerguild_name.."!")
  222.         elseif (kill_message==2) then
  223.             SendWorldMessage("[PvP]: |CFF"..killed_color..pKilled:GetName().."|r"..killedguild_name..", got knocked in da gabba by |CFF"..killer_color..pKiller:GetName().."|r"..killerguild_name.."!")
  224.         elseif (kill_message==3) then
  225.             SendWorldMessage("[PvP]: |CFF"..killed_color..pKilled:GetName().."|r"..killedguild_name..", had their behind superfluously carved by |CFF"..killer_color..pKiller:GetName().."|r"..killerguild_name.."!")
  226.         elseif (kill_message==4) then
  227.             SendWorldMessage("[PvP]: |CFF"..killed_color..pKilled:GetName().."|r"..killedguild_name..", had their lease on life terminated by |CFF"..killer_color..pKiller:GetName().."|r"..killerguild_name.."!")
  228.         elseif (kill_message==5) then
  229.             SendWorldMessage("[PvP]: |CFF"..killed_color..pKilled:GetName().."|r"..killedguild_name..", died of an iron overdose, courtesy of |CFF"..killer_color..pKiller:GetName().."|r"..killerguild_name..".")
  230.         elseif (kill_message==6) then
  231.             SendWorldMessage("[PvP]: |CFF"..killed_color..pKilled:GetName().."|r"..killedguild_name..", wanted a piece of |CFF"..killer_color..pKiller:GetName().."|r"..killerguild_name..", but bit off a little more than they could chew!")
  232.         end
  233.         CharDBExecute("UPDATE shard_pvp_stats SET honorable_kills="..(killerstats:GetUInt32(0)+1).." WHERE playerguid = "..pKiller:GetGUIDLow())
  234.     else
  235.         CharDBExecute("UPDATE shard_pvp_stats SET dishonorable_kills="..(killerstats:GetUInt32(1)+1).." WHERE playerguid = "..pKiller:GetGUIDLow())
  236.         SendWorldMessage("[PvP]: |cffff0000Everyone give a big round of applause to|r |CFF"..killer_color..pKiller:GetName().."|r |cffff0000"..killerguild_name..", whom is level "..pKiller:GetLevel()..", killed|r |CFF"..killed_color..pKilled:GetName().."|r|cffff0000, a level "..pKilled:GetLevel()..".|r")
  237.     end
  238. end
  239.  
  240. local function CreatureDeath(event, pKiller, pKilled)
  241.     if (not creaturedeath) then
  242.         return
  243.     end
  244.    
  245.     local pKilledGUID = pKilled:GetGUIDLow()
  246.     local x,y,z,o = pKilled:GetLocation()
  247.     local FullLootContainer = pKiller:SummonGameObject(ContainerID, x, y, z, 2.5, 0)            --Spawn a Sack of Belongings
  248.     FullLootContainer:RegisterEvent(Remove_FullLootContainer, decaytime*1000, 1)                --Register the Remove/Despawn event to the Sack of Belongings
  249.     guid_linking_table[FullLootContainer:GetGUIDLow()] = pKilled:GetName()
  250.    
  251.     --Get Items
  252.     item_table[FullLootContainer:GetGUIDLow()] = {}
  253.     local items = item_table[FullLootContainer:GetGUIDLow()]
  254.     for i = 0, 38 do
  255.         local checkitem = pKilled:GetItemByPos(255, i)
  256.         if (checkitem) then
  257.             local entry = checkitem:GetEntry()
  258.             if (not checkitem:IsBag() and entry ~= 6948) then
  259.                 table.insert(items, {GetItemLink(checkitem), entry, checkitem:GetCount(), pKilled:GetName()})
  260.                 --pKilled:RemoveItem(entry, checkitem:GetCount())
  261.                 if (#items >= maxitems) then
  262.                     break
  263.                 end
  264.             end
  265.         end
  266.     end
  267. end
  268.  
  269. local function OnGossipHello(event, player, object)
  270.     local objguid = object:GetGUIDLow()
  271.     local items = item_table[objguid]
  272.     if(not items) then
  273.         return
  274.     end
  275.    
  276.     FullLootFrame:Clear()
  277.     for i = 1, maxitems do
  278.         local button = FullLoot_ButtonTable[i]
  279.         local text = FullLoot_TextTable[i]
  280.         local item = items[i]
  281.         if (item) then
  282.             button:SetVar("lootguid", objguid)
  283.             button:SetVar("lootindex", i)
  284.             button:SetVar("itemlink", item[1])
  285.             button:Show()
  286.             text:SetText(item[1].." x"..item[3])
  287.             text:Show()
  288.         else
  289.             button:Hide()
  290.             text:Hide()
  291.         end
  292.     end
  293.     local killedname = guid_linking_table[objguid]
  294.     if (killedname) then
  295.         FullLootFrame_TitleText:SetText("|cffFFC125"..killedname.."'s Belongings|r")
  296.     else
  297.         FullLootFrame_TitleText:SetText("|cffFFC125Unclaimed Belongings|r")
  298.     end
  299.     FullLootFrame:Send(player)
  300. end
  301.  
  302. local function ShardPvPCommands(event, player, msg)
  303.     if (not player:IsGM()) then
  304.         player:SendBroadcastMessage("You do not have access to this function.")
  305.         return false
  306.     else
  307.         if (msg=="#shard playerdeath on") then
  308.             if (playerdeath) then
  309.                 player:SendBroadcastMessage("Shard PvP already active.")
  310.             else
  311.                 player:SendBroadcastMessage("Shard PvP activated.")
  312.                 playerdeath = true
  313.             end
  314.         elseif (msg=="#shard playerdeath off") then
  315.             if (playerdeath) then
  316.                 player:SendBroadcastMessage("Shard PvP already inactive.")
  317.             else
  318.                 player:SendBroadcastMessage("Shard PvP deactivated.")
  319.                 playerdeath = false
  320.             end
  321.         elseif (msg=="#shard creaturedeath on") then
  322.             if (creaturedeath) then
  323.                 player:SendBroadcastMessage("Shard PvE already active.")
  324.             else
  325.                 player:SendBroadcastMessage("Shard PvE activated.")
  326.                 creaturedeath = true
  327.             end
  328.         elseif (msg=="#shard creaturedeath off") then
  329.             if (creaturedeath) then
  330.                 player:SendBroadcastMessage("Shard PvE already inactive.")
  331.             else
  332.                 player:SendBroadcastMessage("Shard PvE deactivated.")
  333.                 creaturedeath = false
  334.             end
  335.         else
  336.             return true
  337.         end
  338.         return false
  339.     end
  340. end
  341.  
  342. AIO:AddInitMsg(FullLootFrame)
  343. RegisterPlayerEvent(6, EntropyPvP)                                   --Triggered when player dies to player, including killing self
  344. RegisterPlayerEvent(8, CreatureDeath)                                --Triggered when player dies to creature
  345. RegisterGameObjectGossipEvent(818001, 1, OnGossipHello)
  346. RegisterPlayerEvent(18, ShardPvPCommands)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement