Untitled

mail@pastecode.io avatar
unknown
lua
a year ago
1.2 kB
2
Indexable
Never
function onDeath(cid, corpse, deathList)
	math.randomseed(os.time())
	if isMonster(cid) then
		t = {}
		for v, k in pairs(SummConfig) do 
			if v:lower() == getCreatureName(cid):lower() then
				for i = 1, #k.reward do
					table.insert(t, {k.reward[i][1], k.reward[i][2]})
				end
				local pos = getThingPos(cid)
				local newIt = t[math.random(1, #t)]
				addEvent(function() 
					doCleanTile(pos) 
					local rw = doCreateItem(newIt[1], isItemStackable(newIt[1]) and newIt[2] or 1, pos)
					if rw then
						if newIt[1] == 6104 then
							doAddContainerItem(rw, item_id, item_amount)
						end
						if doItemSetAttribute(rw, "aid", 1500) then
							local seconds = k.force ~= nil and k.force or SecondsToLoot
							for i = 1, seconds do
								addEvent(function() 
									doSendAnimatedText(pos, (seconds - i) + 1, COLOR_WHITE)
									if i == seconds then
										local it = getTileItemById(pos, newIt[1])
										if it.uid > 0 then
											doItemSetAttribute(it.uid, "aid", 0)
										end
									end
								end, i * 1000)
							end
						end
					end
				end, 1)
			end
		end
	end
	return true
end