Alppha
Member
LEVEL 1
105 XP
Anybody know any good lua script for auto looting creature after kill?
local CreatureLootTable = { }
local UNIT_FIELD_FLAGS = 59
local UNIT_FLAG_NOT_SELECTABLE = 33554432
function OnLoadLootTables(event)
local t = { }
local query = WorldDBQuery("SELECT Entry, Item, MinCount, MaxCount, Chance FROM creature_loot_template")
if query then
repeat
t =
{
entry = query:GetUInt32(0),
item = query:GetUInt32(1),
minCount = query:GetUInt8(2),
maxCount = query:GetUInt8(3),
chance = query:GetFloat(4)
};
table.insert(CreatureLootTable, t)
until not query:NextRow()
print("Completed Loading Loot Tables for custom_auto_loot_creature.lua")
end
end
function OnKillCreature(event, killer, killed)
local creatureEntry = killed:GetEntry()
killed:SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE) -- Set UnSelectable
for _,v in pairs(CreatureLootTable) do
if v.entry == creatureEntry then
if math.random(0, 100) <= v.chance then
if killer:AddItem(v.item, math.random(v.minCount, v.maxCount)) ~= nil then
killer:SendBroadcastMessage("Looted item!")
else
killer:SendBroadcastMessage("Failed to loot item!")
end
end
end
end
end
RegisterPlayerEvent(7, OnKillCreature)
RegisterServerEvent(14, OnLoadLootTables)
You're welcome! Hope it goes well.Thanks gonna try it!